我尝试导入请求:
import requests
但我得到一个错误:
ImportError:没有模块命名请求
我尝试导入请求:
import requests
但我得到一个错误:
ImportError:没有模块命名请求
当前回答
在终端/命令行中:
pip install requests
然后在Python脚本中使用它:
import requests
或者如果您想使用pycharm IDE安装软件包:
从菜单中的文件转到设置下一步转到Python解释器点击pip搜索请求包并安装它
其他回答
唯一对我有用的是:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
pip install requests
酿造用户可以使用以下参考,
安装请求的命令:
python3 -m pip install requests
自制和Python
pip是Python的包安装程序,您需要包请求。
遵循本教程:
$ pipenv install requests
Installing requests...
Adding requests to Pipfile's [packages]...
Installation Succeeded
Pipfile.lock not found, creating...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
Success!
Updated Pipfile.lock (a290a1)!
Installing dependencies from Pipfile.lock (a290a1)...
▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
$ pipenv shell
Launching subshell in virtual environment...
. /home/[user]/.local/share/virtualenvs/[id]/bin/activate
$ python3
Python 3.10.5 (main, Jul 5 2022, 00:20:23) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> response = requests.get('https://httpbin.org/ip')
>>> print('Your IP is {0}'.format(response.json()['origin']))
Your IP is xx.xxx.xx.xxx
这可能有点太晚了,但即使未设置pip路径,也可以运行此命令。我使用的是在Windows 10上运行的Python 3.7,这是命令
py -m pip install requests
您还可以用任何其他未安装的库替换“requests”
对于windows,只需将路径作为cd和python的“脚本”路径,然后执行命令easy_install.exe请求。然后尝试导入请求。。。