kcal 发表于 2020-8-18 00:03:47

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'
怎么办?

kcal 发表于 2020-8-18 00:05:58

我检查过了,电脑上只有1个python

Twilight6 发表于 2020-8-18 00:21:10



你安装成功的英文有 Successfully 吗? 没有就不是安装成功

kcal 发表于 2020-8-18 01:01:57

应该有的,况且我重新输入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就是要下载的东西已经存在的意思吧?

西门吃蒜 发表于 2020-8-18 08:00:25

是不是你的文件名也起成requests了

烦!!! 发表于 2020-8-18 11:38:47

试试这样在mac的终端python -m pip intall requests

烦!!! 发表于 2020-8-18 11:47:31

卸载模块 pip uninstall requests
安装python -m pip install requests
查看已安装的模块 python -m pip list

kcal 发表于 2020-8-18 21:10:16

我在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打印了‘没找到’
不明白

kcal 发表于 2020-8-18 21:38:07

上面的代码是我打错了,应该是‘requests’ 不是‘request’,但‘requests’也没找到

革命年 发表于 2020-8-19 09:23:40

有可能IDLE和你下载好的模块不在一个文件夹里

kcal 发表于 2020-8-19 10:28:10

革命年 发表于 2020-8-19 09:23
有可能IDLE和你下载好的模块不在一个文件夹里

什么意思?

kcal 发表于 2020-8-19 10:38:22

我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)

kcal 发表于 2020-8-19 11:08:55

谢谢各位大佬的帮助,我已经找到解决方案了
sys.path.append('/Users/apple/Library/Python/2.7/lib/python/site-packages')
这样就好了

革命年 发表于 2020-8-20 12:42:22

kcal 发表于 2020-8-19 10:28
什么意思?

不在一个文件夹里就找不到
页: [1]
查看完整版本: python import requests报错