gpt4 book ai didi

Python Pandas "Error: Could not install packages due to an OSError: No such file or directory:"

转载 作者:行者123 更新时间:2023-12-04 07:52:26 27 4
gpt4 key购买 nike

System:Win10
IDE: VSCode
Python path: C:\Users\user\AppData\Local\Continuum\miniconda3
在尝试通过 VSCode 终端安装 pandas 和 geopandas 以运行 Jupyter Notebook 时,我遇到了问题,所以我创建了一个 conda 环境并通过命令提示符安装了 pandas 和 geopandas,它们成功了。现在 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'
>
当我在 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
当我在命令提示符中检查 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
似乎环境中安装了 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'
>
当我返回 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'
如何让 pandas 和 geopandas 工作?

最佳答案

原因是VS Code内部终端使用的python和你当前在VS Code中选择的python环境不同(在VS Code左下角)。
我注意到您使用的是 powershell 终端,它在 VS Code 中默认不会自动激活 conda 环境。

  • 请在 VS Code 中选择 conda 环境,它将显示在 VS Code 的左下角。 ( F1 , Python: Select Interpreter )
  • 请在 VS Code 终端中输入“Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process”,然后重新打开 VS Code 终端(Ctrl+Shift+`)。使用命令“python --version”时,它显示的python版本与左下角显示的相同。
    enter image description here
  • 如果模块没有安装在这个环境中,请按照它。 (pip install pandas)

  • 更新:
    另外,请尝试使用其他终端,例如“cmd”终端。 Can I use Cmder's shell with the terminal on Windows?
    引用: Python environments in VS Code .

    关于Python Pandas "Error: Could not install packages due to an OSError: No such file or directory:",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66891582/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com