当我 pip 安装任何 python 包然后在 pycharm 中运行它时,如下所示:
import requests
from bs4 import beautifulsoup
import pandas
import numpy
它总是显示这个错误:
No module named requests
Unresolved reference 'bs4'
Unresolved reference 'beautifulsoup'
No module named pandas
No module named numpy
这真的很烦人,因为我不能使用任何 python 模块,而且我的电脑上没有多个 python,当我在以下目录中搜索默认安装包的 pip 时,我找到了模块但仍然可以不要使用它们。
C:\Users\sony vaio 2012\AppData\Local\Programs\Python\Python39\Lib\site-packages
我还检查了 python 在 cmd 中使用“where”命令的位置:
C:\Users\sony vaio 2012>where python
C:\Users\sony vaio 2012\AppData\Local\Programs\Python\Python39\python.exe
C:\Users\sony vaio 2012\AppData\Local\Microsoft\WindowsApps\python.exe
这就是 pip 所在的位置:
C:\Users\sony vaio 2012>where python
C:\Users\sony vaio 2012\AppData\Local\Programs\Python\Python39\python.exe
C:\Users\sony vaio 2012\AppData\Local\Microsoft\WindowsApps\python.exe
cmd中的路径:
C:\Users\sony vaio 2012>python
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', 'C:\\Users\\sony vaio 2012\\AppData\\Local\\Programs\\Python\\Python39\\python39.zip', 'C:\\Users\\sony vaio 2012\\AppData\\Local\\Programs\\Python\\Python39\\DLLs', 'C:\\Users\\sony vaio 2012\\AppData\\Local\\Programs\\Python\\Python39\\lib', 'C:\\Users\\sony vaio 2012\\AppData\\Local\\Programs\\Python\\Python39', 'C:\\Users\\sony vaio 2012\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages']
>>>
jupyter笔记本中的路径:
['C:\\Users\\sony vaio 2012',
'c:\\users\\sony vaio 2012\\appdata\\local\\programs\\python\\python39\\python39.zip',
'c:\\users\\sony vaio 2012\\appdata\\local\\programs\\python\\python39\\DLLs',
'c:\\users\\sony vaio 2012\\appdata\\local\\programs\\python\\python39\\lib',
'c:\\users\\sony vaio 2012\\appdata\\local\\programs\\python\\python39',
'',
'c:\\users\\sony vaio 2012\\appdata\\local\\programs\\python\\python39\\lib\\site-packages',
'c:\\users\\sony vaio 2012\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\win32',
'c:\\users\\sony vaio 2012\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\win32\\lib',
'c:\\users\\sony vaio 2012\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\Pythonwin',
'c:\\users\\sony vaio 2012\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\IPython\\extensions',
'C:\\Users\\sony vaio 2012\\.ipython']
点子版本:
C:\Users\sony vaio 2012>pip --version
pip 20.3.3 from c:\users\sony vaio 2012\appdata\local\programs\python\python39\lib\site-packages\pip (python 3.9)
顺便说一句,我是初学者,我在 Windows 10 上使用 python 3.9.1