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


Python Problem Overview

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)

Python Solutions

Solution 1 - Python

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




Solution 2 - Python

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


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

Try updating pip:

pip install -U pip

Solution 4 - Python

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

export LC_ALL=C
pip install --upgrade setuptools

Solution 5 - Python

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

Solution 6 - Python

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.

Solution 7 - Python

A combination of

sudo apt-get install python-dev


export LC_ALL=C
pip install --upgrade setuptools

solved my problem.

Solution 8 - Python

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


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)

Solution 9 - Python

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 && \

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

Solution 10 - Python

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

import sys

Now you can get the file 'pip.log'

Solution 11 - Python

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)

Solution 12 - Python

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


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

Solution 13 - Python

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.

Solution 14 - Python

Had a similar problem on a Jetson TK1 with Ubuntu.

Works fine with apt-get install python-pandas

Solution 15 - Python

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.

Solution 16 - Python

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.

Solution 17 - Python

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.

Solution 18 - Python

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


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJosh.FView Question on Stackoverflow
Solution 1 - PythonJeff M.View Answer on Stackoverflow
Solution 2 - PythonmsemelmanView Answer on Stackoverflow
Solution 3 - PythonNoahView Answer on Stackoverflow
Solution 4 - PythonmaxView Answer on Stackoverflow
Solution 5 - Pythonjvd10View Answer on Stackoverflow
Solution 6 - PythonSelahView Answer on Stackoverflow
Solution 7 - PythonAliView Answer on Stackoverflow
Solution 8 - Pythonharshhx17View Answer on Stackoverflow
Solution 9 - PythonJan DBView Answer on Stackoverflow
Solution 10 - PythonToby SeoView Answer on Stackoverflow
Solution 11 - PythonTavleenView Answer on Stackoverflow
Solution 12 - PythonNikhilView Answer on Stackoverflow
Solution 13 - PythonarinarmoView Answer on Stackoverflow
Solution 14 - PythonrafaelvalleView Answer on Stackoverflow
Solution 15 - PythonjlhView Answer on Stackoverflow
Solution 16 - PythonPeteView Answer on Stackoverflow
Solution 17 - PythonElevenView Answer on Stackoverflow
Solution 18 - PythonAmitabh GhuwalewalaView Answer on Stackoverflow