简体   繁体   中英

ImportError when trying to import pandas in Atom using script

I've installed pandas using pip3 . I'm able to import pandas in the MacOS terminal without issue, but whenever I try to import it in Atom, using the script package, I get an error. This error is:

ImportError: No module named pandas

I don't get this error when trying to import numpy in Atom.

I assume you are using Script package to run python scripts in Atom. Following approach worked for me.

Lets first check which python version Atom is using. Try this in Atom.

import sys
print('Python: {}'.format(sys.version))

If you see output as python version 2.x then

  1. Point Atom to use python 3 by updating Atom ->Preferences -> Open Config Folder ->Packages -> Script->lib->grammars->python.coffee. Change command: 'python' to command: 'python3' .
  2. Save and Close Atom.
  3. Run your code again to check python version. Now it should say 3.x
  4. pip install pandas

You can run following python code in atom to check versions of commonly used python libraries for ML.


# Check the versions of libraries

# Python version
import sys
print('Python: {}'.format(sys.version))
# scipy
import scipy
print('scipy: {}'.format(scipy.__version__))
# numpy
import numpy
print('numpy: {}'.format(numpy.__version__))
# matplotlib
import matplotlib
print('matplotlib: {}'.format(matplotlib.__version__))
# pandas
import pandas
print('pandas: {}'.format(pandas.__version__))
# scikit-learn
import sklearn
print('sklearn: {}'.format(sklearn.__version__)) 

i had this in some new files I created to test Pandas, but on closer inspection I found I was missing this line in my new files, as I was adding the library:

#!/usr/local/bin/python3

On adding this definition it worked perfectly via Python3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM