Itay
Itay

Reputation: 313

import pandas ImportError: No module named pandas

When I try to run the following source (I installed anaconda, there is no problem with other anaconda libraries ):

#!/usr/bin/python 

import pandas

def add_full_name(path_to_csv, path_to_new_csv):
    f = pandas.read_csv(path_to_csv)
    print f['nameFirst'], f['nameLast']
    f['nameFull'] = f['nameFirst'] + ' ' + f['nameLast']
    f.to_csv(path_to_new_csv)

add_full_name("./AllstarFull.csv", "./AllstarFullNew.csv")

I get

"import pandas
 ImportError: No module named pandas"

But when I used the command line and did import panda there where no problem

$ python
Python 2.7.8 |Anaconda 2.0.0 (x86_64)| (default, Jul  2 2014, 15:36:00) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import pandas
>>>

But I still can't use any command of pandas I like to

Upvotes: 1

Views: 19938

Answers (3)

Yinhui
Yinhui

Reputation: 1

I met this same issue when setting up the anaconda along with ST3, and got it fixed by: file->preference->browse packages. Then go to user and open Python3.sublime-build, edit the cmd with the python from anaconda. Restart and enjoy.

{
 "cmd": ["/Users/*USERNAME*/anaconda/bin/python", "-u", "$file"],
 "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
 "selector": "source.python" 
}

Upvotes: 0

Oleg Gryb
Oleg Gryb

Reputation: 5259

If you want to have the same result for running it from interpreter and through "./prog.py", make sure that you have the following in your Python module instead of #!/usr/bin/python:

#!<path-to-your-anacaonda-python>

The 'which' command that I was writing about will provide the path

Upvotes: 2

holdenweb
holdenweb

Reputation: 37143

Your program specifically asks to run the system Python with the shebang line #!/usr/bin/python, so whether you have installed anaconda or not this program won't run using anaconda's Python. Try running the command

python program.py

(or whatever your program is called). That should ensure that you get the version of Python with Pandas installed in it.

Upvotes: 0

Related Questions