Chipmunk_da
Chipmunk_da

Reputation: 507

No module named pandas in command prompt

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?enter image description here

enter image description here

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

Answers (3)

dm2
dm2

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

Ricardo Fantinelli
Ricardo Fantinelli

Reputation: 36

Probably you have installed Python and afterwards Anaconda.

  • AnaConda has its own python exe and Libs that are automatically installed. They're probably located in (Windows path): C:\ProgramData\AnacondaX\
  • So, if you go to C:\ProgramData\AnacondaX\Lib\site-packages\ you will see a folder "pandas". It means that Pandas lib is installed for Anaconda exclusively.
  • On the other hand, you have installed Python in c:\Python27. I'd advise you firstly add to %PATH% environment variable to get access to Python from any folder you're in and after please check the libs you have installed in your Python (not Anaconda) with (pandas is not listed there): c:>pip freeze
  • Next step is to install pandas for your Python installation. Just do it: c:>pip install pandas

Upvotes: 1

Marcelo Ventura
Marcelo Ventura

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

Related Questions