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. Now the Jupyter Notebook worked, by my pythonfiles.py) on VSCode can't find 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:
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
(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:
> 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:
> 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 ?
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).
I noticed that you are using the powershell terminal, which does not automatically activate the conda environment by default in VS Code.
Please select conda environment in VS Code, it will be displayed in the lower left corner of VS Code. (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+`). When using the command "python --version", the python version it displays is the same as the one displayed in the lower left corner.
If the module is not installed in this environment, please follow it. (pip install pandas
)
Update:
In addition, please try to use other terminals, such as the 'cmd' terminal. Can I use Cmder's shell with the terminal on Windows?
Reference: Python environments in VS Code.