PIP Install Numpy throws an error "ascii codec can't decode byte 0xe2"

67,119

Solution 1

I had this exact problem recently and used

apt-get install python-numpy

This adds numpy to your system python interpreter. I may have had to do the same for matplotlib. To use in a virtualenv, you have to create your environment using the

--system-site-packages

option

http://www.scipy.org/install.html

Solution 2

For me @Charles Duffy comment solved it. Put this in your env:

LC_ALL=C

You can add it to your .bashrc with a line like this:

export LC_ALL=C

But take in care that you'll affect all other programs. So you may want to use it just for the pip run:

$ LC_ALL=C pip install ...

Solution 3

Try updating pip:

pip install -U pip

Solution 4

I had that problem with matplotlib package. I had to execute:

export LC_ALL=C
pip install --upgrade setuptools

Solution 5

For me this was solved by ignoring a (presumably) corrupted cache with

pip install --no-cache-dir ...

as described here: https://github.com/pypa/pip/issues/2674

Share:
67,119
Josh.F
Author by

Josh.F

Updated on June 01, 2020

Comments

  • Josh.F
    Josh.F almost 4 years

    I have a freshly installed Ubuntu on a freshly built computer. I just installed python-pip using apt-get. Now when I try to pip install Numpy and Pandas, it gives the following error.

    I've seen this error mentioned in quite a few places on SO and Google, but I haven't been able to find a solution. Some people mention it's a bug, some threads are just dead... What's going on?

    Traceback (most recent call last):
      File "/usr/bin/pip", line 9, in <module>
        load_entry_point('pip==1.5.4', 'console_scripts', 'pip')()
      File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 185, in main
        return command.main(cmd_args)
      File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 161, in main
        text = '\n'.join(complete_log)
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 72: ordinal not in range(128)
    
  • Josh.F
    Josh.F over 9 years
    Thanks! Also, I found that if python-dev doesn't come stock on the computer, you need that too
  • Jeff M.
    Jeff M. over 9 years
    Yeah. I remember that now.. Good catch.
  • fiatjaf
    fiatjaf over 9 years
    You don't need to recreate your virtualenv, you can modify an existing one with virtualenv VIRTUALENV_DIR --system-site-packages.
  • hello_there_andy
    hello_there_andy over 9 years
    this fixed the same error I had with pip install scipy, thanks
  • tourdownunder
    tourdownunder over 9 years
    Same here. Upgraded VM instance from 1 to a 2 gig RAM temporarily while installing.
  • baltasvejas
    baltasvejas almost 9 years
    Had same issue on Ubuntu server 14.02. sudo apt-get install python2.7-dev solved the issue.
  • Mark
    Mark almost 9 years
    This solves the problem but I think you should at least mention you are making (all) system packages available, so the point of using virtualenv is partially defeated...
  • moi
    moi almost 9 years
    This seems to be the correct answer. Using --system-site-packages was not an option for me.
  • user1158559
    user1158559 about 8 years
    This is only an indirect answer, but it teaches something and does not deserve to be downvoted.
  • Gil Hiram
    Gil Hiram almost 8 years
    a better wording for you answer would be: add "export LC_ALL=C" to your ~/.bashrc
  • msemelman
    msemelman almost 8 years
    @GilHiram Depends on your shell type you may have to set up this env variable in other places. unix.stackexchange.com/questions/50665/…
  • Arjun
    Arjun over 7 years
    The install didn't work for me both within, and outside a virtualenv so using --system-site-packages was not the right answer. I got it to work inside a virtualenv with LC_ALL=C pip install ....
  • kalebo
    kalebo about 7 years
    This worked for me on debian jessie inside of a venv.
  • WestCoastProjects
    WestCoastProjects almost 7 years
    what does export LC_ALL=C mean / do ?
  • radtek
    radtek over 6 years
    @javadba It forces applications to use the default language for output, and forces sorting to be bytewise.
  • Barmaley
    Barmaley over 5 years
    locale-gen en_US.UTF-8 worked for me as well! Or RUN locale-gen en_US.UTF-8 in Dockerfile