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

Question:

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)
Asked By: Josh.F

||

Answers:

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

Answered By: Jeff M.

In ‘site-packages’ directory, make ‘sitecustomize.py’ like this

import sys
sys.setdefaultencoding("utf-8")

Now you can get the file ‘pip.log’

Answered By: Toby Seo

I had a similar error when running pip install pandas and it was due to a memory shortage. I increased the memory in my virtual machine to 4G and that fixed things.

Answered By: Selah

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 ...

Answered By: msemelman

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

export LC_ALL=C
pip install --upgrade setuptools
Answered By: max

try sudo apt-get install python-numpy .
It worked out for me and same can be used for scipy,pandas etc by replacing them in place of numpy. (Y)

Answered By: Tavleen

A combination of

sudo apt-get install python-dev

and

export LC_ALL=C
pip install --upgrade setuptools

solved my problem.

Answered By: Ali

If you want the pip version of numpy, you can build the dependencies for the package and then install it using pip

sudo apt-get build-dep python-numpy
pip install numpy

This should install everything needed at system level to install the package.

Answered By: arinarmo

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

Answered By: jvd10

Had a similar problem on a Jetson TK1 with Ubuntu.

Works fine with apt-get install python-pandas

Answered By: rafaelvalle

Try updating pip:

pip install -U pip
Answered By: Noah

So many answers and none worked for me even though some clearly worked for other people. But I then figured out what my problem was, so I’ll just add it to the collection:

dpkg-reconfigure locales
# enable the "en-US.UTF-8" locale
# when asked for a default, no need to define one

The thing is, I was working inside a Debian Stretch linux container that happened to not have any UTF-8 locales installed, probably because I downloaded a minimal stock image. With this UTF-8 locale now installed, pip properly installed numpy and other packages.

Answered By: jlh

In my case I had just installed Python from source (on a remote machine where I am not sudo). For whatever reason, pip was on some really old version. So after:

python -m pip install --upgrade pip

I was able to install numpy and everything I wanted without trouble.

Answered By: Pete

I met the similar problem. I tried:

export LC_ALL=C
pip install --upgrade setuptools

But it did not solve the problem, but another error came up:

AttributeError: ‘str’ object has no attribute ‘rollback’

Then I tried:

pip install -U pip

Then the problem was solved.

Answered By: Eleven

@OSX Users: Add the following lines to your ~/.profile or ~/.bashrc

LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"

Execute the scripts using
source ~/.profile or source ~/.bashrc

Answered By: Nikhil

Resetting my regional settings in my machine to the expected one solved my problem. For me the problem started when I switched my language settings to English(India). I had to switch it back to English(Great Britain).

Answered By: Amitabh Ghuwalewala

Recently, I stumbled upon the same problem
This solved it for me:

              echo 'export LANG=en_US.UTF-8' >> ~/.bashrc
              echo 'export LANGUAGE=en_US:en' >> ~/.bashrc
              echo 'export LC_ALL=en_US.UTF-8' >> ~/.bashrc
              sudo apt-get install language-pack-en

Note,

I already had python-numpy and python-dev installed. Even this may be causing a problem on your system.
You can also export LC_ALL=C instead of en_US.UTF-8(or any other language)

Answered By: harshhx17

When running in a docker container, this fixed it for me (on the project django-postgrespool, but this should also work here).

# Set the locale
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && 
    locale-gen
ENV LANG en_US.UTF-8  
ENV LANGUAGE en_US:en  
ENV LC_ALL en_US.UTF-8   

see https://stackoverflow.com/a/28406007/1876203

Answered By: Jan DB
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.