[英]Python Pandas “Error: Could not install packages due to an OSError: No such file or directory:”
System:Win10
IDE: VSCode
Python path: C:\Users\user\AppData\Local\Continuum\miniconda3
while trying to install pandas and geopandas via VSCode terminal to run Jupyter Notebook, I encountered issues, so I created a conda environment and installed pandas and geopandas via Command Prompt and they were successful.在尝试通过 VSCode 终端安装 pandas 和 geopandas 以运行 Jupyter Notebook 时,我遇到了问题,所以我创建了一个 conda 环境并通过命令提示符安装了 pandas 和 geopandas,他们成功了。 Now the Jupyter Notebook worked, by my pythonfiles.py) on VSCode can't find pandas.
现在 Jupyter Notebook 工作了,我的 pythonfiles.py) 在 VSCode 上找不到 pandas。
> PS C:\Users\user\folder> python pythonfile.py
> Traceback (most recent call last): File
> "pythonfile.py", line 1, in <module>
> import pandas as pd ModuleNotFoundError: No module named 'pandas'
>
when I check "pip list" in VSCode, resulted:当我在 VSCode 中检查“pip list”时,结果:
Package Version
--------------- -------------------
asn1crypto 0.23.0
certifi 2017.11.5
cffi 1.11.2
chardet 3.0.4
conda 4.3.31
cryptography 2.1.4
idna 2.6
menuinst 1.4.10
numpy 1.19.5
pip 21.0.1
pycosat 0.6.3
pycparser 2.18
pyOpenSSL 17.5.0
PySocks 1.6.7
python-dateutil 2.8.1
pytz 2021.1
pywin32 221
requests 2.18.4
ruamel-yaml 0.11.14
setuptools 36.5.0.post20170921
six 1.11.0
urllib3 1.22
wheel 0.30.0
win-inet-pton 1.0.1
wincertstore 0.2
when I check pip list in Command Prompt, resulted当我在命令提示符中检查 pip 列表时,结果
(env1) C:\Users\user>pip list
Package Version
---------------- -------------------
attrs 20.3.0
backcall 0.2.0
certifi 2020.12.5
chardet 4.0.0
click 7.1.2
click-plugins 1.1.1
cligj 0.7.1
colorama 0.4.4
cycler 0.10.0
decorator 4.4.2
Fiona 1.8.18
GDAL 3.2.2
geopandas 0.9.0
idna 2.10
ipykernel 5.5.0
ipython 7.18.1
ipython-genutils 0.2.0
jedi 0.17.2
jupyter-client 6.1.7
jupyter-core 4.6.3
kiwisolver 1.3.1
matplotlib 3.3.4
munch 2.5.0
numpy 1.20.1
pandas 1.2.3
parso 0.7.0
pickleshare 0.7.5
Pillow 8.1.2
pip 21.0.1
prompt-toolkit 3.0.8
Pygments 2.7.1
pyparsing 2.4.7
pyproj 3.0.1
python-dateutil 2.8.1
pytz 2021.1
pywin32 227
pyzmq 19.0.2
requests 2.25.1
setuptools 52.0.0.post20210125
Shapely 1.7.1
six 1.15.0
tornado 6.0.4
traitlets 5.0.5
urllib3 1.26.4
wcwidth 0.2.5
wheel 0.36.2
wincertstore 0.2
seems pandas and geopandas are installed in the environment, however, running the pythoncode.py still returned:似乎 pandas 和 geopandas 安装在环境中,但是,运行 pythoncode.py 仍然返回:
> Traceback (most recent call last): File
> "C:\Users\user\folder\pythonfile.py", line 1, in <module>
> import pandas as pd ModuleNotFoundError: No module named 'pandas'
>
when I return to VSCode and try to install pandas again, I get the following error:当我返回 VSCode 并尝试再次安装 pandas 时,出现以下错误:
> PS C:\Users\user\folder> pip install pandas Collecting pandas
> Using cached pandas-1.1.5-cp36-cp36m-win_amd64.whl (8.7 MB)
> Requirement already satisfied: numpy>=1.15.4 in
> c:\users\user\appdata\local\continuum\miniconda3\lib\site-packages
> (from pandas) (1.19.5) Requirement already satisfied: pytz>=2017.2 in
> c:\users\user\appdata\local\continuum\miniconda3\lib\site-packages
> (from pandas) (2021.1) Requirement already satisfied:
> python-dateutil>=2.7.3 in
> c:\users\user\appdata\local\continuum\miniconda3\lib\site-packages
> (from pandas) (2.8.1) Requirement already satisfied: six>=1.5 in
> c:\users\user\appdata\local\continuum\miniconda3\lib\site-packages
> (from python-dateutil>=2.7.3->pandas) (1.11.0) ERROR: Could not
> install packages due to an OSError: [Errno 2] No such file or
> directory:'c:\\users\\user\\appdata\\local\\continuum\\miniconda3\\lib\\site-packages\\pytz-2021.1.dist-info\\METADATA'
how can I make pandas and geopandas work?如何使 pandas 和 geopandas 工作?
The reason is that the python used by the internal terminal of VS Code is different from the python environment you currently select in VS Code (shown in the lower left corner of VS Code).原因是VS Code内部终端使用的python和你目前VS Code中select的python环境不同(见VS Code左下角)。
I noticed that you are using the powershell terminal, which does not automatically activate the conda environment by default in VS Code.我注意到您使用的是 powershell 终端,它在 VS Code 中默认不会自动激活 conda 环境。
Please select conda environment in VS Code, it will be displayed in the lower left corner of VS Code.请在VS Code中select conda环境,会显示在VS Code的左下角。 (
F1
, Python: Select Interpreter
) (
F1
, Python: Select Interpreter
)
Please enter " Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
" in the VS Code terminal, and then reopen the VS Code terminal (Ctrl+Shift+`).请在 VS Code 终端中输入“
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
”,然后重新打开 VS Code 终端(Ctrl+Shift+`)。 When using the command "python --version", the python version it displays is the same as the one displayed in the lower left corner.使用命令“python --version”时,它显示的python版本与左下角显示的版本相同。
If the module is not installed in this environment, please follow it.如果模块没有安装在这个环境中,请按照它。 (
pip install pandas
) (
pip install pandas
)
Update:更新:
In addition, please try to use other terminals, such as the 'cmd' terminal.另外,请尝试使用其他终端,例如“cmd”终端。 Can I use Cmder's shell with the terminal on Windows?
我可以在 Windows 上使用 Cmder 的 shell 和终端吗?
Reference: Python environments in VS Code .参考: VS Code 中的 Python 环境。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.