Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python: after installing anaconda, how to import pandas

I have installed anaconda. Now when i am trying to run

import pandas as pd

I am getting the following error

Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pandasFile
ImportError: No module named pandasFile

It is my first day to python. I cannot figure out how to fix it. I am hoping that I have to change some path somewhere. I know it can be a silly question to post here.

like image 843
Kanika Singhal Avatar asked Sep 14 '15 12:09

Kanika Singhal


People also ask

How do I import pandas in Python?

Enter the command “pip install pandas” on the terminal. This should launch the pip installer. The required files will be downloaded, and Pandas will be ready to run on your computer. After the installation is complete, you will be able to use Pandas in your Python programs.

Is pandas automatically installed with Anaconda?

10 |Anaconda 2.3. 0 (x86_64)| (default, May 28 2015, 17:04:42) . Pandas should be automatically installed by Anaconda.

Can we use pandas in Anaconda?

The easiest way to install pandas is to install it as part of the Anaconda distribution, a cross platform distribution for data analysis and scientific computing.


4 Answers

I'm using python 3.4 and Anaconda3 4.2.

I had the same problem, but it worked (the import pandas works now anyway) for me to install pandas with pip by writing:

python -m pip install pandas

Good luck!

like image 88
Lasse Hamborg Avatar answered Oct 18 '22 02:10

Lasse Hamborg


The cool thing about anaconda is, that you can manage virtual environments for several projects. Those also have the benefit of keeping several python installations apart. This could be a problem when several installations of a module or package are interfering with each other.

Try the following:

  1. Create a new anaconda environment with user@machine:~$ conda create -n pandas_env python=2.7
  2. Activate the environment with user@machine:~$ source activate pandas_env on Linux/OSX or $ activate pandas_env on Windows. On Linux the active environment is shown in parenthesis in front of the user name in the shell. (I am not sure how windows handles this, but you can see it by typing $ conda info -e. The one with the * next to it is the active one)
  3. Type (pandas_env)user@machine:~$ conda list to show a list of all installed modules.
  4. If pandas is missing from this list, install it (while still inside the pandas_env environment) with (pandas_env)user@machine:~$ conda install pandas, as @Fiabetto suggested.
  5. Open python (pandas_env)user@machine:~$ python and try to load pandas again.

Note that now you are working in a python environment, that only knows the modules installed inside the pandas_env environment. Every time you want to use it you have to activate the environment. This might feel a little bit clunky at first, but really shines once you have to manage different versions of python (like 2.7 or 3.4) or you need a specific version of a module (like numpy 1.7).

Edit:

If this still does not work you have several options:

  1. Check if the right pandas module is found:

    `(pandas_env)user@machine:~$ python`
    Python 2.7.10 |Continuum Analytics, Inc.| (default, Sep 15 2015, 14:50:01)
    >>> import imp
    >>> imp.find_module("pandas")
    (None, '/path/to/miniconda3/envs/foo/lib/python2.7/site-packages/pandas', ('', '', 5))
    
    # See what this returns on your system.
    
  2. Reinstall pandas in your environment with $ conda install -f pandas. This might help if you files have been corrupted somehow.

  3. Install pandas from a different source (using pip). To do this, create a new environment like above (make sure to pick a different name to avoid clashes here) but replace point 4 by (pandas_env)user@machine:~$ pip install pandas.
  4. Reinstall anaconda (make sure you pick the right version 32bit / 64bit depending on your OS, this can sometimes lead to problems). It could be possible, that your 'normal' and your anaconda python are clashing. As a last resort you could try to uninstall your 'normal' python before you reinstall anaconda.
like image 23
m00am Avatar answered Oct 18 '22 02:10

m00am


If you are facing same problem as mine. Here is the solution which works for me.

  1. Uninstall every python and anaconda.
  2. Download anaconda from here "http://continuum.io/downloads" and only install it (no other python is needed).
  3. Open spyder and import.
  4. If you get any error, type in command prompt

    pip install module_name

I hope it will work for you too

like image 6
Kanika Singhal Avatar answered Oct 18 '22 02:10

Kanika Singhal


You should first create a new environment in conda. From the terminal, type:

$ conda create --name my_env pandas ipython

Python will be installed automatically as part of this installation. After selecting [y] to confirm, you now need to activate this environment:

$ source activate my_env

On Windows I believe it is just:

$ activate my_env

Now, confirm installed packages:

$ conda list

Finally, start python and run your session.

$ ipython
like image 2
Alexander Avatar answered Oct 18 '22 02:10

Alexander