0

I have installed Anaconda, so I'm fairly sure I have installed Pandas.

However, when I run this in Sublime:

import pandas as pd

I get this message:

Traceback (most recent call last):
  File "/Users/user/Documents/Programming/Python/Python for Finance/7_4.py", line 184, in <module>
    import pandas as pd
ImportError: No module named pandas
[Finished in 0.4s with exit code 1]

But when I go to the terminal:

Python 2.7.8 |Anaconda 2.1.0 (x86_64)| (default, Aug 21 2014, 15:21:46) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
>>> import pandas
>>> import pandas as pd
>>> pd.__version__
'0.15.1'

So I know I have pandas, and I've also updated anaconda to the newest version....

Chef-3:~ user$ conda update anaconda Fetching package metadata: ..
# All requested packages already installed.
# packages in environment at /Users/user/anaconda:
# anaconda                  2.1.0                np19py27_0

So what am I missing?

Thanks :)

Chef1075
  • 2,614
  • 9
  • 40
  • 57
  • Is Anaconda the only installed version of Python? What program is Sublime running when you use it to run your file? – BrenBarn Nov 27 '14 at 22:07
  • I don't quite know what you mean. When sublime runs, I set it to Python...thats about it. – Chef1075 Nov 27 '14 at 22:14
  • 2
    There may be more than one Python version on your system. Before `import pandas as pd` in your program, add `import sys` and `print sys.executable` to see which Python interpreter Sublime is using. – DSM Nov 27 '14 at 22:19
  • Ah, I see what could be the problem. I ran the code above and got: /usr/bin/python – Chef1075 Nov 27 '14 at 22:20

3 Answers3

1

I ran into the same problem with PyCharm a few weeks ago. My solution, if all else fails, is to move over to iPython Notebook. Since that runs Anaconda, you know it will detect pandas successfully. For some reason (maybe the reason @DSM mentioned), sometimes installing a package on Anaconda doesn't transfer over to all of your IDEs.

brian
  • 121
  • 2
  • 12
1

Once Anaconda is installed, its Python distribution supercedes the Python distribution that ships with OS X. You've installed Pandas on the former distribution (or rather, it's come pre-installed), while Sublime Text is relying on the latter distribution to build and run.

You'll want to modify Sublime Text to use the Python distribution from Anadonda. You can modify Python.sublime-settings as shown in Sublime Text 2: custom PATH and PYTHONPATH to do this.

(Addendum: To find where python is being executed from Terminal.app, you can run: $ which python.)

Community
  • 1
  • 1
Jacob Budin
  • 9,753
  • 4
  • 32
  • 35
0

Check the version of python that gets run when pandas is found, and the version when it is not found — most likely they are not the same.

Check the pythons you have on your system:

ls -larth `which python`*

For example one of the installed pythons is /usr/bin/python3.6 — you can set it as the default for the current user by adding an alias to /.bashrc:

alias python3='/usr/bin/python3.6'

Another (not recommended) approach would be changing the symlinks in /usr/bin/ or /usr/local/bin to the versions of python you want to use, but this can potentially break things, e.g. ubuntu uses specific versions of python with specific modules to do various system tasks.

And lastly, review your .bashrc, .bash_profile (or the equivalents for the shell you are using if other than bash), and find all the places where $PATH and $PYTHONPATH is (re)defined — if you have changed it manually then it might be time to review it.

ccpizza
  • 28,968
  • 18
  • 162
  • 169