68

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
  • 3,666
  • 2
  • 27
  • 37
  • 3
    Are there non-ASCII characters in your hostname, home directory, &c.? Does setting `LC_ALL=C` make any difference? – Charles Duffy Oct 20 '14 at 20:15
  • 1
    While this post is aimed at Amazon's EC2, it seems to be the same problem, and I find the answers more helpful: http://stackoverflow.com/questions/19595944/trouble-installing-scipy-in-virtualenv-on-a-amazon-ec2-linux-micro-instance – BenjaminGolder Dec 04 '14 at 12:07
  • I still do have a problem with the installation even though i have gotten numpy. Is there anyone else that have this problem? – eleijonmarck Mar 19 '15 at 21:45
  • As OP, and 3 years later, I can say I have solved this by migrating to Haskell ;) – Josh.F Aug 07 '17 at 22:50

18 Answers18

45

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

Jeff M.
  • 1,037
  • 10
  • 7
37

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

msemelman
  • 2,877
  • 1
  • 21
  • 19
  • 1
    This seems to be the correct answer. Using `--system-site-packages` was not an option for me. – moi Aug 11 '15 at 13:16
  • 4
    a better wording for you answer would be: add "export LC_ALL=C" to your ~/.bashrc – Gil Hiram Jun 28 '16 at 08:43
  • @GilHiram Depends on your shell type you may have to set up this env variable in other places. http://unix.stackexchange.com/questions/50665/what-is-the-difference-between-interactive-shells-login-shells-non-login-shell – msemelman Jun 29 '16 at 13:51
  • 1
    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 ...`. – Arjun Sep 19 '16 at 16:55
  • what does `export LC_ALL=C` *mean* / do ? – WestCoastProjects Jun 27 '17 at 20:40
  • 1
    @javadba It forces applications to use the default language for output, and forces sorting to be bytewise. – radtek Jan 16 '18 at 01:25
12

Try updating pip:

pip install -U pip
Noah
  • 21,451
  • 8
  • 63
  • 71
7

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

export LC_ALL=C
pip install --upgrade setuptools
max
  • 9,708
  • 15
  • 89
  • 144
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

jvd10
  • 1,826
  • 17
  • 17
3

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.

Selah
  • 7,728
  • 9
  • 48
  • 60
3

A combination of

sudo apt-get install python-dev

and

export LC_ALL=C
pip install --upgrade setuptools

solved my problem.

Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
Ali
  • 31
  • 1
3

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)

harshhx17
  • 31
  • 3
3

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

Jan DB
  • 355
  • 2
  • 6
1

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

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

Now you can get the file 'pip.log'

Toby Seo
  • 457
  • 1
  • 4
  • 14
1

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)

Tavleen
  • 11
  • 3
1

@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

Nikhil
  • 1,054
  • 9
  • 9
0

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.

arinarmo
  • 375
  • 1
  • 11
0

Had a similar problem on a Jetson TK1 with Ubuntu.

Works fine with apt-get install python-pandas

rafaelvalle
  • 6,683
  • 3
  • 34
  • 36
0

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.

jlh
  • 4,349
  • 40
  • 45
0

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.

Pete
  • 16,534
  • 9
  • 40
  • 54
0

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.

Eleven
  • 1
  • 1
0

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