3

I have a python script which is running successfully when i run it from spyder. But the same script gives "ImportError: No module named pandas" when run from windows command prompt.

Nitin
  • 2,572
  • 5
  • 21
  • 28

2 Answers2

2

This Q&A mentioned similar problem https://stackoverflow.com/a/10741803/5088142

Can you please check which folders are mentioned in Spyder Tools/PYTHONPATH manager?

Also you can execute the following two lines in Spyder, and identify the location of pandas library:

import pandas 
print pandas.__file__

The output should be the path to pandas module Please add this path to Windows path (reference https://docs.python.org/2/using/windows.html)

Python:

import sys
sys.path.append('_location_of_python_lib_')

Windows CMD:

set PYTHONPATH=%PYTHONPATH%;C:\_location_of_python_lib_

Windows:

Simply add this path to your PYTHONPATH environment variable. To do this, go to Control Panel / System / Advanced / Environment variable, and in the "User variables" sections, check if you already have PYTHONPATH. If yes, select it and click "Edit", if not, click "New" to add it. Paths in PYTHONPATH should be separated with ";".

The following link show you how to set environment variable in Windows 7 permanently http://www.nextofwindows.com/how-to-addedit-environment-variables-in-windows-7

Community
  • 1
  • 1
Yaron
  • 10,166
  • 9
  • 45
  • 65
  • I added the path, but now i get a different error : ImportError : C extension : DLL load failed.....If u want to import pandas from source directory, you may need to run python setup.py build_ext.... – Nitin May 05 '16 at 12:57
  • How did you originally installed pandas? this link http://stackoverflow.com/q/30945272/5088142 mentioned similar problem in windows " There is a bug in older versions (of conda) where if you had updated pandas WHILE it was being used it didn't update correctly. Try closing all python processes, then conda remove pandas; conda install pandas" – Yaron May 05 '16 at 13:02
  • Initially it was installed with Anaconda by default and it is working fine with spyder. Do u still suggest to reinstall pandas ? – Nitin May 05 '16 at 13:06
  • Which path did you add? – Yaron May 05 '16 at 13:14
  • I have set PYTHONPATH to Appdata\local\Continuum\Anaconda3\lib\site-packages\ – Nitin May 05 '16 at 13:19
  • which version of python (2? 3?) - are you running in spyder? in Windows? – Yaron May 05 '16 at 13:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/111136/discussion-between-nitin-and-yaron). – Nitin May 05 '16 at 13:27
-3

You should then install pandas using the windows interpreter.

Open Windows command prompt and type:

pip install pandas

or

easy_install pandas

depending on which package manager you use.

estemendoza
  • 3,023
  • 5
  • 31
  • 51
  • 1
    Can't i somehow use the same libraries that are being used by spyder. spyder is able to find all the packages. – Nitin May 05 '16 at 12:31
  • I think he is asking about a problem he encountered while running a python script from command line – Selvaram G Dec 19 '18 at 15:12