简体   繁体   English

在 Python 中收到“ImportError: No module named requests”错误

[英]Receiving a 'ImportError: No module named requests' error in Python

When I run import requests I receive an error: ImportError: No module named requests .当我运行import requests时,我收到一个错误: ImportError: No module named requests I have looked at other responses to similar questions and tried nearly everything and nothing is working.我查看了对类似问题的其他回复,并尝试了几乎所有方法,但没有任何效果。 I'm using MacOS and my project is on my desktop in a folder with a single file with the one line of code I wrote above.我正在使用 MacOS,我的项目在我的桌面上的一个文件夹中,该文件夹中有一个文件,上面有我写的一行代码。 When I run pip3 list, the request package is installed.当我运行 pip3 list 时,安装了请求 package。

I understand you, python can be a mess.我了解您,python 可能会一团糟。 Macos has a default installation of python version 2.XX when you type 'python' in terminal it executes the preinstalled python v2 Macos 默认安装 python 版本 2.XX,当您在终端中键入“python”时,它会执行预安装的 python v2

Now since you are using pip3 I assume you've installed latest python 3.XX and pip3 will install modules for python 3 only not for the default python 2现在,由于您使用的是 pip3,我假设您已经安装了最新的 python 3.XX,并且 pip3 将为 python 3 安装模块,而不是默认的 python 2

So when you are running your script.py, insted of python script.py try python3 script.py因此,当您运行 script.py 时, python script.py尝试python3 script.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM