我尝试导入请求:

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

其他回答

如果你使用的是水蟒步骤1:其中python步骤2:以管理员模式打开anaconda提示符步骤3:cd<python路径>步骤4:在此位置安装软件包

唯一对我有用的是:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
pip install requests

我发现我的问题是VSCode从错误的Python解释器读取。这个youtube教程帮我解决了这个问题。

要在Debian/Uubuntu for Python2上安装请求模块,请执行以下操作:

$sudo apt-get安装python请求

对于Python3,命令是:

$sudo apt-get安装python3请求

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

conda install -c anaconda requests

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