Python 使用 pip 安装后出现“导入错误:没有名为‘请求’的模块”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30535384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"ImportError: no module named 'requests'" after installing with pip
提问by user3654181
I am getting ImportError : no module named 'requests'
.
我得到ImportError : no module named 'requests'
.
But I have installed the requests
package using the command pip install requests
.
但是我已经requests
使用命令安装了该软件包pip install requests
。
On running the command pip freeze
in the command prompt, the result is
在pip freeze
命令提示符下运行命令,结果是
requests==2.7.0
So why is this sort of error happening while running the python file?
那么为什么在运行 python 文件时会发生这种错误呢?
回答by Isak La Fleur
Run in command prompt.
在命令提示符下运行。
pip list
Check what version you have installed on your system if you have an old version.
如果您有旧版本,请检查您在系统上安装的版本。
Try to uninstall the package...
尝试卸载软件包...
pip uninstall requests
Try after to install it:
安装后尝试:
pip install requests
You can also test if pip does not do the job.
您还可以测试 pip 是否无法完成这项工作。
easy_install requests
回答by Bruce Chou
One possible reason is that you have multiple python executables in your environment, for example 2.6.x, 2.7.x or virtaulenv. You might install the package into one of them and run your script with another.
一种可能的原因是您的环境中有多个 python 可执行文件,例如 2.6.x、2.7.x 或 virtaulenv。您可以将软件包安装到其中一个中并使用另一个运行您的脚本。
Type python in the prompt, and press the tab key to see what versions of Python in your environment.
在提示中键入 python,然后按 Tab 键以查看您的环境中的 Python 版本。
回答by Albert
I had this error before when I was executing a python3 script, after this:
我之前在执行 python3 脚本时遇到过这个错误,在此之后:
sudo pip3 install requests
sudo pip3 install requests
the problem solved, If you are using python3, give a shot.
问题解决了,如果您使用的是python3,请试一试。
回答by dp2050
In Windows it worked for me only after trying the following: 1. Open cmd inside the folder where "requests" is unpacked. (CTRL+SHIFT+right mouse click, choose the appropriate popup menu item) 2. (Here is the path to your pip3.exe)\pip3.exe install requests Done
在 Windows 中,它仅在尝试以下操作后才对我有用: 1. 在解压缩“请求”的文件夹中打开 cmd。(CTRL+SHIFT+鼠标右键,选择合适的弹出菜单项) 2. (这里是你的pip3.exe的路径)\pip3.exe install requests Done
回答by Pascal Louis-Marie
if it works when you do :
如果它在你这样做时有效:
python
>>> import requests
then it might be a mismatch between a previous version of python on your computer and the one you are trying to use
那么它可能是您计算机上以前版本的 python 与您尝试使用的版本不匹配
in that case : check the location of your working python:
在这种情况下:检查您的工作 python 的位置:
which python
And get sure it is matching the first line in your python code
which python
并确保它与您的 python 代码中的第一行匹配
#!<path_from_which_python_command>
回答by Tanzir Rahman
Opening CMD in the location of the already installed request folder and running "pip install requests" worked for me. I am using two different versions of Python.
在已安装的请求文件夹的位置打开 CMD 并运行“pip install requests”对我有用。我正在使用两个不同版本的 Python。
I think this works because requests is now installed outside my virtual environment. Haven't checked but just thought I'd write this in, in case anyone else is going crazy searching on Google.
我认为这是有效的,因为请求现在安装在我的虚拟环境之外。还没有检查,但只是想我会写这个,以防其他人在谷歌上疯狂搜索。