我尝试导入请求:

import requests

但我得到一个错误:

ImportError:没有模块命名请求


当前回答

如果您使用anaconda作为python包管理器,请执行以下操作:

conda install -c anaconda requests

通过pip安装请求对我没有帮助。

其他回答

我也有同样的问题,所以我从中复制了名为“requests”的文件夹https://pypi.python.org/pypi/requests#downloadsrequests下载到“/Library/Python/2.7/site包”。现在,当您使用:import请求时,它应该可以正常工作。

Python常见安装问题

如果Homebrew在macOS上破坏了您的路径,这些命令也很有用。

python -m pip install requests

or

python3 -m pip install requests

并行安装多个版本的Python?

在过去几个月里,我有过几次这样的问题。我还没有看到发布的fedora系统的好解决方案,所以这里还有另一个解决方案。我正在使用RHEL7,我发现了以下问题:

如果您通过pip安装了urllib3,并且通过yum安装了请求,那么即使您安装了正确的软件包,也会遇到问题。如果您通过yum安装了urllib3,并且通过pip安装了请求,则同样适用。以下是我解决问题的方法:

sudo pip uninstall requests
sudo pip uninstall urllib3
sudo yum remove python-urllib3
sudo yum remove python-requests

(确认已删除所有这些库)

sudo yum install python-urllib3
sudo yum install python-requests

请注意,这只适用于运行Fedora、Redhat或CentOS的系统。

来源:这个问题(在对这个答案的评论中)。这个github问题。

遵循本教程:

$ 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

酿造用户可以使用以下参考,

安装请求的命令:

python3 -m pip install requests

自制和Python

pip是Python的包安装程序,您需要包请求。