12

I am trying to learn pandas and I haven't been able to import it into my code.

I have looked at other answers on this site and none of them have worked.

I just installed anaconda and installed everything through conda.

Here is a sample script that I am trying to run.

import pandas as pd

writer = pd.ExcelWriter('farm_data.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1')

workbook = writer.book
worksheet = writer.sheets['Sheet1']

chart = workbook.add_chart({'type': 'column'})

And the error it kicks back.

Traceback (most recent call last):

File "C:\Users\thiet01\Documents\Python Scripts\new 1.py", line 1, in

import pandas

ImportError: No module named 'pandas'

If you need any more information, please let me know and I can provide it.

Thanks in advance for any help.

Warren Sergent
  • 2,542
  • 4
  • 36
  • 42
Tthieme
  • 121
  • 1
  • 1
  • 4
  • 2
    1) have you installed pandas: "conda install pandas". 2) is anaconda your default python, i.e. when you run "python" on the terminal, does it say the version indicating anaconda distribution – Vince W. Jun 27 '16 at 19:09
  • 1
    You might have multiple Python installations in which case pandas is installed for one and not the other. – mechanical_meat Jun 27 '16 at 19:09
  • @VinceWest 1) Yes 2) I don't believe so. I installed anaconda, did some troubleshooting and tried restarting as I saw this reply (might have been you) in another thread. When I open a python shell, it doesnt say anything about continuum. Should I be looking elsewhere or how should I correct this? – Tthieme Jun 27 '16 at 19:17
  • @bernie How would I check this to see if I have multiple instances and where they are? – Tthieme Jun 27 '16 at 19:17
  • From your previous comment it sounds like you do have multiple installations. You can go to the Control Panel to Add/Remove Programs and uninstall the non-Anaconda Python. – mechanical_meat Jun 27 '16 at 19:19
  • start python. >>>import sys >>>sys.executable. This will print the path to your running python executable. If you know where you installed your anaconda python distribution, you can start it by running /path/to/python/python.exe . – Vince W. Jun 27 '16 at 19:20
  • Alright so I did have multiple installs of python, I uninstalled 2 of them and just have the Anaconda version. When I open a python shell, it now says anaconda as well. Now I seem to have run into a new issue, I used to be able to open the script, press f5 and it would run it. Now it just says that Windows can't open that file. Solved one problem I guess. – Tthieme Jun 27 '16 at 19:38
  • where are you running the script from? Spyder? – Vince W. Jun 27 '16 at 19:43
  • @VinceWest initially I was just running it through IDLE, looks like that is gone now and I am trying to run it through Spyder. Is there something else I should be using instead? Thanks for all of the help by the way. – Tthieme Jun 27 '16 at 19:46
  • at this point, I think you should consider uninstalling anaconda, and re-installing using the Windows executable. Be sure to check all of the boxes indicating to make Anaconda the default python executable. There are a lot of environment variables in Windows that tell the OS to execute python scripts with a default interpreter which the installer should do with all the proper options checked. – Vince W. Jun 27 '16 at 19:48
  • Alternatively, you can try and rescue the situation by changing your environment variables, and adding your anaconda/python.exe directory to your System Path (google windows system path if you don't know how to do this). Once your preferred python.exe is in the system path, typing python myscript.py out to work, where you are in the directory of myscript.py – Vince W. Jun 27 '16 at 19:49
  • That is what I ended up doing. I uninstalled anaconda and reinstalled it. It is the default now but looks like I have to run through Spyder as my interpreter if I am using the terminology correctly. – Tthieme Jun 27 '16 at 20:34

7 Answers7

10

below solved my issue:

apt-get install python3-pandas or apt-get install python2-pandas

Font: https://ask.fedoraproject.org/en/question/36529/installing-python-pandas/

Marcos
  • 844
  • 3
  • 10
  • 25
7

I had the same problem for a long time. Today I tried a whole day and it finally worked. Below is the steps how I did it. I don't have theory for why the problem exist and how it is solved. I just know the following steps helped me get pandas going.

A. download first and install miniconda using the following code:

bash Miniconda2-latest-MacOSX-x86_64.sh

B. create an env for your project using following code:

conda create --name trypandas numpy pandas jupyter

C. going to your env and try jupyter notebook with pandas using:

source activate trypandas
jupyter notebook

Note: my own experience indicates:

  1. when I missed conda install jupyter, pandas only work in pure python environment, not in ipython nor in jupyter notebook;

  2. after conda install jupyter, pandas works in jupyter notebook now.

  3. the step B above installing jupyter together with numpy and pandas, there should not be a problem.

My trypandas in installed in ~/miniconda2/envs.

James Risner
  • 5,451
  • 11
  • 25
  • 47
Daniel
  • 1,428
  • 3
  • 16
  • 35
4

Here is the basic documentation on how to instal python packages.

For OS X and Linux users, the following command ought to work:

pip install pandas
David C
  • 203
  • 3
  • 7
1

Even I had same issue but this solved my problem-

sudo apt-get install python-pandas

To check if pandas is installed or not:

Open up a Python prompt by running the following:

python

At the prompt, type the following:

import pandas

print pandas.\__version__

This will print the installed version of pandas in the system

MatejMecka
  • 1,448
  • 2
  • 24
  • 37
sujay
  • 11
  • 1
0

I wanted to add this as a comment but Im not special enough yet in the eyes of stackoverflow.

Some modules need to be separately installed into your libraries folder of your python directory.Using pip (https://pip.pypa.io/en/stable/) is helpful for this. Otherwise manually add the module to your library folder by installing the module at:

https://pypi.python.org/pypi/pandas/0.18.1/

running the setup through the command line ((pandas location)>setup.py install), and finally adding it to your python directory.

Hope this helps!

mattyb
  • 11
  • 1
  • 8
0

What worked for me was to make sure that I run the command sudo apt-get so you run as root to make sure I download python3 like below

sudo apt-get install python3

The reason you need to use sudo it's because environments such as Ubuntu lock the root automatically according to Wikihow

Then I used

sudo apt-get update
sudo apt-get upgrade

And then I used the pip install pandas

That worked for me. I hope that's helpful

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
0

For installing pandas you can also use following method in python3.

python3 -m pip install pandas

or

pip3 install pandas

Also if this still fails because of a build error

ERROR: Could not build wheels for scipy which use PEP 517 and cannot be installed directly

or takes a long time to install pandas, then try upgrading pip.

pip3 install --upgrade pip
v1shva
  • 1,261
  • 3
  • 13
  • 28