python import requests报错
我在Mac终端里输入pip install requests后显示成功下载,但在python的idle里输入尝试导入requests时>>> import requests
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
怎么办? 我检查过了,电脑上只有1个python
你安装成功的英文有 Successfully 吗? 没有就不是安装成功
应该有的,况且我重新输入pip install requests时会显示Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: requests in ./Library/Python/2.7/lib/python/site-packages (2.24.0)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./Library/Python/2.7/lib/python/site-packages (from requests) (1.25.10)
Requirement already satisfied: certifi>=2017.4.17 in ./Library/Python/2.7/lib/python/site-packages (from requests) (2020.6.20)
Requirement already satisfied: chardet<4,>=3.0.2 in ./Library/Python/2.7/lib/python/site-packages (from requests) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in ./Library/Python/2.7/lib/python/site-packages (from requests) (2.10)
Requirement already satisfied就是要下载的东西已经存在的意思吧? 是不是你的文件名也起成requests了
试试这样在mac的终端python -m pip intall requests 卸载模块 pip uninstall requests
安装python -m pip install requests
查看已安装的模块 python -m pip list 我在python -m pip list里发现了requests
但是还是无法导入
在IDLE里输入
>>> for i in sys.path:
if not os.path.isdir(i):
continue
if 'request.py' in os.listdir(i):
print('找到啦')
break
else:
print('没找到')
Ta打印了‘没找到’
不明白 上面的代码是我打错了,应该是‘requests’ 不是‘request’,但‘requests’也没找到 有可能IDLE和你下载好的模块不在一个文件夹里 革命年 发表于 2020-8-19 09:23
有可能IDLE和你下载好的模块不在一个文件夹里
什么意思? 我PYTHON的path有
>>> for path in sys.path:
print(path)
/Users/apple/Documents
/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
我之前install的easygui,pygame,pyautogui都在/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages里(都是用pip install xxx) 谢谢各位大佬的帮助,我已经找到解决方案了
sys.path.append('/Users/apple/Library/Python/2.7/lib/python/site-packages')
这样就好了 kcal 发表于 2020-8-19 10:28
什么意思?
不在一个文件夹里就找不到
页:
[1]