160

I am trying to write code in Python to fetch Twitter data, and I am not getting an error for twython. But I am getting an error for Pandas.

I have installed Pandas using pip install pandas. But I still get the following error. How can I fix it?

F:\> pip install pandas
Collecting pandas
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py
:90: InsecurePlatformWarning: A true SSLContext object is not available. This pr
events urllib3 from configuring SSL appropriately and may cause certain SSL conn
ections to fail. For more information, see https://urllib3.readthedocs.org/en/la
test/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Using cached pandas-0.17.0-cp27-none-win32.whl
Requirement already satisfied (use --upgrade to upgrade): pytz>=2011k in c:\pyth
on27\lib\site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in c:\
python27\lib\site-packages (from pandas)
Collecting numpy>=1.7.0 (from pandas)
  Downloading numpy-1.10.1.tar.gz (4.0MB)
    100% |################################| 4.1MB 26kB/s
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in c:\python2
7\lib\site-packages (from python-dateutil->pandas)
Building wheels for collected packages: numpy
  Running setup.py bdist_wheel for numpy
  Complete output from command c:\python27\python.exe -c "import setuptools;__fi
le__='c:\\users\\sangram\\appdata\\local\\temp\\pip-build-m6knxg\\numpy\\setup.p
y';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))"
 bdist_wheel -d c:\users\sangram\appdata\local\temp\tmppmwkw4pip-wheel-:
  Running from numpy source directory.
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help

  error: invalid command 'bdist_wheel'

  ----------------------------------------
  Failed building wheel for numpy
Failed to build numpy
Installing collected packages: numpy, pandas
  Running setup.py install for numpy
    Complete output from command c:\python27\python.exe -c "import setuptools, t
okenize;__file__='c:\\users\\sangram\\appdata\\local\\temp\\pip-build-m6knxg\\nu
mpy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().rep
lace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\sangram\appdat
a\local\temp\pip-ll4zaf-record\install-record.txt --single-version-externally-ma
naged --compile:
    blas_opt_info:
    blas_mkl_info:
      libraries mkl,vml,guide not found in ['c:\\python27\\lib', 'C:\\', 'c:\\py
thon27\\libs']
      NOT AVAILABLE

    openblas_info:
      libraries openblas not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python2
7\\libs']
      NOT AVAILABLE

    atlas_3_10_blas_threads_info:
    Setting PTATLAS=ATLAS
      libraries tatlas not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python27\
\libs']
      NOT AVAILABLE

    atlas_3_10_blas_info:
      libraries satlas not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python27\
\libs']
      NOT AVAILABLE

    atlas_blas_threads_info:
    Setting PTATLAS=ATLAS
      libraries ptf77blas,ptcblas,atlas not found in ['c:\\python27\\lib', 'C:\\
', 'c:\\python27\\libs']
      NOT AVAILABLE

    atlas_blas_info:
      libraries f77blas,cblas,atlas not found in ['c:\\python27\\lib', 'C:\\', '
c:\\python27\\libs']
      NOT AVAILABLE

    blas_info:
      libraries blas not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python27\\l
ibs']
      NOT AVAILABLE

    blas_src_info:
      NOT AVAILABLE

      NOT AVAILABLE

    non-existing path in 'numpy\\distutils': 'site.cfg'
    F2PY Version 2
    lapack_opt_info:
    openblas_lapack_info:
      libraries openblas not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python2
7\\libs']
      NOT AVAILABLE

    lapack_mkl_info:
    mkl_info:
      libraries mkl,vml,guide not found in ['c:\\python27\\lib', 'C:\\', 'c:\\py
thon27\\libs']
      NOT AVAILABLE

      NOT AVAILABLE

    atlas_3_10_threads_info:
    Setting PTATLAS=ATLAS
      libraries tatlas,tatlas not found in c:\python27\lib
      libraries lapack_atlas not found in c:\python27\lib
      libraries tatlas,tatlas not found in C:\
      libraries lapack_atlas not found in C:\
      libraries tatlas,tatlas not found in c:\python27\libs
      libraries lapack_atlas not found in c:\python27\libs
    <class 'numpy.distutils.system_info.atlas_3_10_threads_info'>
      NOT AVAILABLE

    atlas_3_10_info:
      libraries satlas,satlas not found in c:\python27\lib
      libraries lapack_atlas not found in c:\python27\lib
      libraries satlas,satlas not found in C:\
      libraries lapack_atlas not found in C:\
      libraries satlas,satlas not found in c:\python27\libs
      libraries lapack_atlas not found in c:\python27\libs
    <class 'numpy.distutils.system_info.atlas_3_10_info'>
      NOT AVAILABLE

    atlas_threads_info:
    Setting PTATLAS=ATLAS
      libraries ptf77blas,ptcblas,atlas not found in c:\python27\lib
      libraries lapack_atlas not found in c:\python27\lib
      libraries ptf77blas,ptcblas,atlas not found in C:\
      libraries lapack_atlas not found in C:\
      libraries ptf77blas,ptcblas,atlas not found in c:\python27\libs
      libraries lapack_atlas not found in c:\python27\libs
    <class 'numpy.distutils.system_info.atlas_threads_info'>
      NOT AVAILABLE

    atlas_info:
      libraries f77blas,cblas,atlas not found in c:\python27\lib
      libraries lapack_atlas not found in c:\python27\lib
      libraries f77blas,cblas,atlas not found in C:\
      libraries lapack_atlas not found in C:\
      libraries f77blas,cblas,atlas not found in c:\python27\libs
      libraries lapack_atlas not found in c:\python27\libs
    <class 'numpy.distutils.system_info.atlas_info'>
      NOT AVAILABLE

    lapack_info:
      libraries lapack not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python27\
\libs']
      NOT AVAILABLE

    lapack_src_info:
      NOT AVAILABLE

      NOT AVAILABLE

    running install
    running build
    running config_cc
    unifing config_cc, config, build_clib, build_ext, build commands --compiler
options
    running config_fc
    unifing config_fc, config, build_clib, build_ext, build commands --fcompiler
 options
    running build_src
    build_src
    building py_modules sources
    creating build
    creating build\src.win32-2.7
    creating build\src.win32-2.7\numpy
    creating build\src.win32-2.7\numpy\distutils
    building library "npymath" sources
    Running from numpy source directory.
    c:\users\sangram\appdata\local\temp\pip-build-m6knxg\numpy\numpy\distutils\s
ystem_info.py:1651: UserWarning:
        Atlas (http://math-atlas.sourceforge.net/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [atlas]) or by setting
        the ATLAS environment variable.
      warnings.warn(AtlasNotFoundError.__doc__)
    c:\users\sangram\appdata\local\temp\pip-build-m6knxg\numpy\numpy\distutils\s
ystem_info.py:1660: UserWarning:
        Blas (http://www.netlib.org/blas/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [blas]) or by setting
        the BLAS environment variable.
      warnings.warn(BlasNotFoundError.__doc__)
    c:\users\sangram\appdata\local\temp\pip-build-m6knxg\numpy\numpy\distutils\s
ystem_info.py:1663: UserWarning:
        Blas (http://www.netlib.org/blas/) sources not found.
        Directories to search for the sources can be specified in the
        numpy/distutils/site.cfg file (section [blas_src]) or by setting
        the BLAS_SRC environment variable.
      warnings.warn(BlasSrcNotFoundError.__doc__)
    c:\users\sangram\appdata\local\temp\pip-build-m6knxg\numpy\numpy\distutils\s
ystem_info.py:1552: UserWarning:
        Atlas (http://math-atlas.sourceforge.net/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [atlas]) or by setting
        the ATLAS environment variable.
      warnings.warn(AtlasNotFoundError.__doc__)
    c:\users\sangram\appdata\local\temp\pip-build-m6knxg\numpy\numpy\distutils\s
ystem_info.py:1563: UserWarning:
        Lapack (http://www.netlib.org/lapack/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [lapack]) or by setting
        the LAPACK environment variable.
      warnings.warn(LapackNotFoundError.__doc__)
    c:\users\sangram\appdata\local\temp\pip-build-m6knxg\numpy\numpy\distutils\s
ystem_info.py:1566: UserWarning:
        Lapack (http://www.netlib.org/lapack/) sources not found.
        Directories to search for the sources can be specified in the
        numpy/distutils/site.cfg file (section [lapack_src]) or by setting
        the LAPACK_SRC environment variable.
      warnings.warn(LapackSrcNotFoundError.__doc__)
    c:\python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution opt
ion: 'define_macros'
      warnings.warn(msg)
    error: Unable to find vcvarsall.bat

    ----------------------------------------
Command "c:\python27\python.exe -c "import setuptools, tokenize;__file__='c:\\us
ers\\sangram\\appdata\\local\\temp\\pip-build-m6knxg\\numpy\\setup.py';exec(comp
ile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __fi
le__, 'exec'))" install --record c:\users\sangram\appdata\local\temp\pip-ll4zaf-
record\install-record.txt --single-version-externally-managed --compile" failed
with error code 1 in c:\users\sangram\appdata\local\temp\pip-build-m6knxg\numpy

F:\>python tweet_fetcher.py
Traceback (most recent call last):
  File "tweet_fetcher.py", line 1, in <module>
    import pandas
ImportError: No module named pandas
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sangram Barge
  • 1,611
  • 2
  • 13
  • 8
  • 1
    Your pandas installation failed. Rather than installing it manually on your own (it has a lot of dependencies which require native extensions for Python to be compiled) I would recommend you use teh Anaconda Python distribution https://www.continuum.io/downloads – Bernhard Nov 02 '15 at 16:14
  • As a side note, I get strange errors when installing pandas using the ps terminal in Visual Studio Code. In cmd seems to work. – Gabriel P. Mar 25 '18 at 07:36

13 Answers13

194

You're missing a few (not terribly clear) steps. Pandas is distributed through pip as a wheel, which means you need to do:

pip install wheel
pip install pandas

You're probably going to run into other issues after this - it looks like you're installing on Windows which isn't the most friendly of targets for NumPy, SciPy, and Pandas. Alternatively, you could pickup a binary installer from here.

You also had an error installing NumPy. Like before, I recommend grabbing a binary installer for this, as it's not a simple process. However, you can resolve your current error by installing this package from Microsoft.

While it's completely possible to get a perfect environment setup on Windows, I have found the quality-of-life for a Python developer is vastly improved by setting up a Debian VM. Especially with the scientific packages, you will run into many cases like this.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
TkTech
  • 4,729
  • 1
  • 24
  • 32
47

I fixed the same problem with the below commands...

Type python on your terminal. If you see python version 2.x, then run these two commands to install Pandas:

sudo python -m pip install wheel

and

sudo python -m pip install pandas

Else if you see python version 3.x, then run these two commands to install Pandas:

sudo python3 -m pip install wheel

and

sudo python3 -m pip install pandas

Good Luck!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • If you're working on a raspberry pi take a look at https://stackoverflow.com/a/47875615/7773582 – Jochen Haßfurter Sep 17 '20 at 11:52
  • 2
    As for anyone using windows use: `py -m pip install pandas` – Jarrett Dec 20 '20 at 06:32
  • And for true beginners like me, you have to type `py -m pip install pandas` in the powershell terminal in VS code. Also make sure your global interpreter is set correctly (I chose Global) and you don't have a another virtual environment `venv` messing things up. Once I deleted my local `venv` folders that I was using pre-Global interpreter, then everything worked fine. – Sidders Oct 10 '22 at 02:00
  • >>> sudo python3 -m pip install wheel File "", line 1 sudo python3 -m pip install wheel ^^^^^^^ SyntaxError: invalid syntax – Ehsan May 11 '23 at 09:09
41

I just had the problem and I kept installing and uninstalling. It turns out the problem happens when you're installing Pandas to a version of python and trying to run the program using another python version.

So to start off, run:

which python
python --version
which pip

make sure both are aligned, most probably, python is 2.7 and pip is working on 3.x or pip is coming from anaconda's python version which is highly likely to be 3.x as well

In case of python redirects to 2.7, and pip redirects to pip3, install pandas using pip install pandas and use python3 file_name.py to run the program.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ramy M. Mousa
  • 5,727
  • 3
  • 34
  • 45
15

Try this:

python -m pip install pandas
S.B
  • 13,077
  • 10
  • 22
  • 49
  • 1
    This is the only answer that worked for me! Any explanation why? – bmilovanovic Jun 21 '22 at 22:22
  • 1
    When using `pip install pandas`, you install the module in the default location but the Python runtime you are using might not be loading modules from the default. By using `python -m pip install pandas`, you will install the module in the right directory that the `python` runtime is using. – harnamc Oct 03 '22 at 16:44
13

If you are on Ubuntu and use the builtin Python 3, you can just install it from the Ubuntu repos like so in a terminal:

sudo apt install python3-pandas

the above works on Ubuntu 20.04 LTS and be slightly different depending on your version. Note that if you use the built-in python, it's best to use apt to install modules, not pip because you may get conflicts in the installed modules.

Vincent Gerris
  • 7,228
  • 1
  • 24
  • 22
8

When I try to build the docker image zeppelin-highcharts, I find that the base image openjdk:8 also does not have pandas installed. I solved it with this steps.

curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | python
pip install pandas

I referred to What is the official “preferred” way to install pip and virtualenv systemwide?.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rockie Yang
  • 4,725
  • 31
  • 34
6

If you are running Python version 3.9, Pandas won't work as of now. So install Python version 3.7 or below to mitigate this issue.

Or else if you want to stick with Python 3.9, try install Pandas by compiling the library.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sheshan Gamage
  • 574
  • 11
  • 19
3

As of Dec 2020, I had the same issue when installing python v 3.8.6 via pyenv. So, I started by:

  1. Installing pyenv via Homebrew, brew install pyenv
  2. Install xz compiling package via brew install xz
  3. pyenv install 3.8.6. Pick the required version
  4. pyenv global 3.8.6. Make this version as global
  5. python -m pip install -U pip to upgrade pip
  6. pip install virtualenv

After that, I initialized my new env, installed Pandas via the pip command, and everything worked again. The Pandas version installed is 1.1.5 within my working project directory.

Note: If you have installed Python before xz, make sure to uninstall it first, otherwise the error might persist.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Salma Elshahawy
  • 1,112
  • 2
  • 11
  • 21
3
  1. curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
  2. python3 get-pip.py
  3. sudo python3 -m pip install pandas
Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94
1

For me how it worked was, I had two executable versions of Python so on pip install it was installing in one version, but my executable path version was different so it failed.

Then I changed the path in sys's environment variable and installed in the executable version of Python and it was able to identify the package from site-packages.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Daniel
  • 35
  • 1
  • 6
1

This is for those who tired the above answers but still have issues. You should do the following:

  1. figure out which python version you're using by running this

python --version

  1. Based on the version of Python you are using run one of the following:

pip3.10 install pandas

or

pip3.9 install pandas

or

pip3.8 install pandas

etc.

Desert Eagle
  • 191
  • 14
0

For me this happened in pycharm when I opened another project folder up. Seem like since I installed pandas in a folder that was not accessible to the new project folder my computer could not find the pandas.

Python uses a scripts folder to store this in I believe.

I know when I use pip install it pulls from the python script folder, so what I did was make a folder called "everything python", the name doesn't matter, and put my script folder here. Then took the other folders for other projects and put them in there and use the "everything python" as the project I want to work on in pycharm.

This solved it for me.

Dharman
  • 30,962
  • 25
  • 85
  • 135
JQTs
  • 142
  • 2
  • 11
0

If using python 3, using pip3 instead of pip

python 3: pip3 install pandas

Mani S
  • 23
  • 7