我尝试导入请求:
import requests
但我得到一个错误:
ImportError:没有模块命名请求
我尝试导入请求:
import requests
但我得到一个错误:
ImportError:没有模块命名请求
当前回答
唯一对我有用的是:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
pip install requests
其他回答
在Windows Open命令行上
pip3 install requests
如果你使用的是水蟒步骤1:其中python步骤2:以管理员模式打开anaconda提示符步骤3:cd<python路径>步骤4:在此位置安装软件包
遵循本教程:
$ 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 install requests
或
pip3 install requests
或
python -m pip install requests
或
python3 -m pip install requests
或
python -m pip3 install requests
如果所有这些都不起作用,请留下评论!这是如何工作的?根据您当前使用的操作系统,pip命令可能会有所不同,或者在某些操作系统上不起作用。这些是您可以尝试的修复命令。
在OSX上,该命令将取决于您的python安装风格。
Python 2.x-默认
sudo pip install requests
Python 3.x
sudo pip3 install requests