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.
Another alternative is to use Pycharm IDE. For each project, you can set the Project Interpreter in Settings.
For example, if anaconda is installed in /home/user/anaconda2/bin/python, you can select the Project Interpreter and set to this folder.
Since the whole project is set to Anaconda's path, you can import any module which is packaged within Anaconda.
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
pip install module_name will work or If you are using a file that you were previously working on than just do shift+enter to reload and will do the job
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!
You can only import a library which has been installed in your environment.
If you have created a new environment, e.g. to run an older version of Python, maybe you lack 'pandas' package, which is in the 'base' environment of Anaconda by default.
Fix through GUI
To add it to your environment, from the GUI, select your environment, select "All" in the dropdown list, type pandas in the text field, select the pandas package and Apply.
Afterwards, select 'Installed' to verify that the package has been correctly installed.
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:
user@machine:~$ conda create -n pandas_env python=2.7
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)(pandas_env)user@machine:~$ conda list
to show a list of all installed modules.(pandas_env)user@machine:~$ conda install pandas
, as @Fiabetto suggested.(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).
If this still does not work you have several options:
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.
Reinstall pandas in your environment with $ conda install -f pandas
. This might help if you files have been corrupted somehow.
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
.even after installing anaconda i got the same error and entering python3 showed this:
$ python3
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
enter this command: source ~/.bashrc
(it is kind of restarting the terminal) after running the command enter python3
again:
$ python3
Python 3.7.4 (default, Aug 13 2019, 20:35:49)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
this means anaconda is added. now import pandas
will work.
i had pandas installed ('conda list|grep pandas') and python could find it ('python; import imp; imp.find_module("pandas");'
However still was getting this error inside spyder. I had accidentally been using 'spyder3' instead of 'spyder' command, the former using a different python (3.5) rather than one conda is using (3.8). Running spyder and things worked as expected.
I've had the same exact problem in that I installed Anaconda because a python script I want to use relies on pandas, and that after so doing, python still returned the same comment that "pandas module is missing" or something to that effect.
When I typed "python" to see which python was being called, I found it was still accessing the older version of python 2.7, even though when I installed Anaconda the installer asked (and I agreed) that it would make its python the default python on my machine (PC running Windows 7).
I tried to find if there is a CONFIG.SYS file on the PC, but gave up after searching in various places (If anyone knows, please tell me). I got around the problem by writing a one-line batch script named python2.bat that called the Anaconda2 version of python, which then worked. However, it would clearly be better to change the CONFIG.SYS or whatever the PC uses to decide which version of python to call.
What worked for me, on my Mac at least, was that I opened PyCharm system preferences, then chose my project on the left side. I clicked on Program Interpreter and looked in the list to see that pandas was not installed. I simply chose it from the list on the right (using the search at the top). I clicked the install package and this resolved the issue.
I know there are a lot of answers to this already but I would like to put in my two cents. When creating a virtual environment in anaconda launcher you still need to install the packages you need. This is deceiving because I assumed since I was using anaconda that packages such as pandas, numpy etc would be include. This is not the case. It gives you a fresh environment with none of those packages installed, at least mine did. All my packages installed into the environment with no problem and work correctly.
For OSX:
I had installed this via Anaconda, and had a hell of a time getting it to work. What helped was adding the Anaconda bin AND pkgs folder to my PATH.
Since I use fishshell, I did it in my ~/.config/fish/config.fish
file like this:
set -g -x PATH $PATH /Users/cbrevik/anaconda/bin /Users/cbrevik/anaconda/pkgs
If you use fishshell like me, this answer will probably save you some trouble later using pandas as well.
Source: Stackoverflow.com