我尝试导入请求:

import requests

但我得到一个错误:

ImportError:没有模块命名请求


当前回答

遵循本教程:

$ 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

其他回答

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

您必须确保请求模块未安装在较新版本的python中。

使用python 3.7时,运行python文件,如下所示:

python3 myfile.py

或使用以下命令进入python交互模式:

python3

是的,这对我有用。像这样运行文件:python3 file.py

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

安装请求的命令:

python3 -m pip install requests

自制和Python

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

在命令提示符(Windows)或终端(Linux/macOS)中键入此命令:

pip install requests

在OSX上,该命令将取决于您的python安装风格。

Python 2.x-默认

sudo pip install requests

Python 3.x

sudo pip3 install requests