python: after installing anaconda, how to import pandas

前端 未结 13 2149
眼角桃花
眼角桃花 2021-01-31 18:00

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

import pandas as pd

I am getting the following error

Traceback (most re         


        
相关标签:
13条回答
  • 2021-01-31 18:40

    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.

    0 讨论(0)
  • 2021-01-31 18:41

    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
    
    0 讨论(0)
  • 2021-01-31 18:41
    1. Another alternative is to use Pycharm IDE. For each project, you can set the Project Interpreter in Settings.

    2. For example, if anaconda is installed in /home/user/anaconda2/bin/python, you can select the Project Interpreter and set to this folder.

    3. Since the whole project is set to Anaconda's path, you can import any module which is packaged within Anaconda.

    0 讨论(0)
  • 2021-01-31 18:41

    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.

    0 讨论(0)
  • 2021-01-31 18:42

    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.

    0 讨论(0)
  • 2021-01-31 18:44

    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

    0 讨论(0)
提交回复
热议问题