我尝试导入请求:
import requests
但我得到一个错误:
ImportError:没有模块命名请求
我尝试导入请求:
import requests
但我得到一个错误:
ImportError:没有模块命名请求
当前回答
尝试sudo apt-get安装python请求。
这对我有用。
其他回答
酿造用户可以使用以下参考,
安装请求的命令:
python3 -m pip install requests
自制和Python
pip是Python的包安装程序,您需要包请求。
遵循本教程:
$ 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
我的答案与@pi-k基本相同。在我的案例中,我的程序在本地运行,但未能在QA服务器上构建。(我怀疑devops的包的旧版本被阻止了,我的版本肯定太过时了)我刚刚决定升级所有的东西
$ pip install pip-review
$ pip-review --local --interactive
尽管我安装了几次“requests”,但还是出现了同样的错误。问题是我在全局Python环境中安装请求,而不是在应用程序虚拟环境中。在虚拟环境中安装请求后,错误消失了。因此,这里有一篇关于如何在应用程序虚拟环境中安装“请求”的好书:虚拟环境和软件包
面对同样的问题,但无法用上述解决方案解决,所以我尝试了这种方法,并成功了:-
卷曲https://bootstrap.pypa.io/pip/2.7/get-pip.py--输出get-pyp.pysudo python2get-pipp.pypython-m pip安装请求