我尝试导入请求:

import requests

但我得到一个错误:

ImportError:没有模块命名请求


当前回答

可以从安装.whl文件https://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype然后在cmd或任何机器中运行pip install“PATH/To/.whl/file”或类似的文件

其他回答

如果要在windows上请求导入:

pip install request

然后美容组4:

pip3 install beautifulsoup4

如果您使用的是Ubuntu,则需要安装请求

运行以下命令:

pip install requests

如果您面临权限拒绝错误,请在命令之前使用sudo:

sudo pip install requests

遵循本教程:

$ 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

安装python请求库,此错误将得到解决。

在我的案例中,请求已经安装,但需要升级。以下命令成功了

$ sudo pip install requests --upgrade