Reputation: 507
I'm getting the error in the title when running a .py
script. I have pandas
installed (version 0.24.2) as you can see in the screenshot. The Python
version is 3.7.3. When I run the command import pandas as pd
in a Jupyter notebook it works. However, when I have the same command in a .py
file ("MyFile.py") and try to run that file using Anaconda command prompt
I get this error. Same happens when using the Windows command prompt. Can someone please advise on how to solve this?
The 2nd screenshot above shows that I can't find a folder for pandas in site-packages but anaconda seems to think it's installed.
Upvotes: 0
Views: 2139
Reputation: 4275
Anaconda uses its own python installation, which by default, and as per this documentation, should be under C:\Users\<your-username>\Anaconda3\
.
By installing pandas via Anaconda, and then specifically running the script with a different python installation, you're running a script using a library within environment that does not have that library installed.
You can try installing pandas to this separate python installation (I saw your pip install didn't work, you could again specify this python installation and use pip as a module):
'C:\python27\python.exe' -m pip install pandas
Or run the script with the Anaconda python installation by specifying that python installation:
{path_to_anaconda_python} MyFile.py
Where path_to_anaconda_python is path to Anaconda python installation (by default, within C:\Users\<your-username>\Anaconda3\
)
Upvotes: 1
Reputation: 36
Probably you have installed Python and afterwards Anaconda.
Upvotes: 1
Reputation: 36
have you tried python3.7 MyFile.py
?
If not, I would try it. Then if it doesn't work I'd create a new environment with python 3.7, and then install pandas and run your code:
conda create -n test_env python=3.7
conda activate test_env
pip install pandas
python MyFile.py
Upvotes: 1