2

I have installed the 'script' package and launch atom editor in terminal.

I imported 'numpy' and 'pandas' like this,

import numpy as np
import pandas as pd

the autocompleting works.

When I ran it by CMD+I ,'numpy' was successfully imported but 'pandas' failed:

Traceback (most recent call last):
  File "/Users/Dmj/Desktop/pythontest/movie_datas.py", line 2, in <module>
    import pandas as pd
ImportError: No module named pandas

I can run this scrip in python3.5 shell.So I've surely installed 'pandas'.

When I import other libs it shows the same error.

How can I fix it?

OS X 10.11

Richard Slater
  • 6,313
  • 4
  • 53
  • 81
Domon Ji
  • 21
  • 1
  • 1
  • 2

2 Answers2

1

please make sure that the module pandas does exist in the search path sys.path.

python -c "import sys; print(sys.path);"
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/pymodules/python2.7']
ROY
  • 8,800
  • 1
  • 17
  • 13
  • `python3 -c "import sys;print(sys.path);"` `['','/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages']` and the module pandas does exist in the site-packages folder – Domon Ji Apr 04 '16 at 06:01
  • Does it mean the module is in the path? Thanks a lot. – Domon Ji Apr 04 '16 at 06:11
  • @DomonJi Please read it. [6.1.2. The Module Search Path](https://docs.python.org/3/tutorial/modules.html#the-module-search-path) – ROY Apr 04 '16 at 07:03
  • @DomonJi try to install `pandas` with `$ pip install pandas` – ROY Apr 04 '16 at 07:08
1

just found an alternative solution for the cited problem, see [How to fix Python Numpy/Pandas installation?

User sjs wrote:

If you're like me and you don't like the idea of deleting things that were part of the standard system installation (which others have suggested) then you might like the solution I ended up using:

Get Homebrew - it's a one-line shell script to install!

Edit your .profile, or whatever is appropriate, and put /usr/local/bin at the start of your PATH so that Homebrew binaries are found before system binaries

brew install python - this installs a newer version of python in /usr/local

pip install pandas

This worked for me in OS X 10.8.2, and I can't see any reason it shouldn't work in 10.6.8.

I had the problem that atom-runner within atom editor did not recognize pandas after installing it via pip. This is obviously a consequence of using Homebrew in combination with bash and python.

For my case, I edited .bash_profile and changed PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}" to PATH="/usr/local/bin/python3:${PATH}", and exported this path.

After, I reinstalled pandas using pip install pandas, and rerun the .py script that contained import pandas as pd without any problems in atom.

Community
  • 1
  • 1
P. Baumann
  • 11
  • 2