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) 
4
  • 3
    Are there non-ASCII characters in your hostname, home directory, &c.? Does setting LC_ALL=C make any difference? Commented Oct 20, 2014 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: stackoverflow.com/questions/19595944/… Commented Dec 4, 2014 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? Commented Mar 19, 2015 at 21:45
  • As OP, and 3 years later, I can say I have solved this by migrating to Haskell ;) Commented Aug 7, 2017 at 22:50

19 Answers 19

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

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks! Also, I found that if python-dev doesn't come stock on the computer, you need that too
Yeah. I remember that now.. Good catch.
You don't need to recreate your virtualenv, you can modify an existing one with virtualenv VIRTUALENV_DIR --system-site-packages.
Had same issue on Ubuntu server 14.02. sudo apt-get install python2.7-dev solved the issue.
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...
|
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 ...

6 Comments

This seems to be the correct answer. Using --system-site-packages was not an option for me.
a better wording for you answer would be: add "export LC_ALL=C" to your ~/.bashrc
@GilHiram Depends on your shell type you may have to set up this env variable in other places. unix.stackexchange.com/questions/50665/…
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 ....
@javadba It forces applications to use the default language for output, and forces sorting to be bytewise.
|
13

Try updating pip:

pip install -U pip 

1 Comment

This worked for me on debian jessie inside of a venv.
7

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

export LC_ALL=C pip install --upgrade setuptools 

Comments

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

Comments

3

A combination of

sudo apt-get install python-dev 

and

export LC_ALL=C pip install --upgrade setuptools 

solved my problem.

Comments

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.

1 Comment

Same here. Upgraded VM instance from 1 to a 2 gig RAM temporarily while installing.
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)

Comments

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

1 Comment

locale-gen en_US.UTF-8 worked for me as well! Or RUN locale-gen en_US.UTF-8 in Dockerfile
1

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

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

Now you can get the file 'pip.log'

1 Comment

This is only an indirect answer, but it teaches something and does not deserve to be downvoted.
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)

Comments

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

Comments

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.

Comments

0

Had a similar problem on a Jetson TK1 with Ubuntu.

Works fine with apt-get install python-pandas

Comments

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.

Comments

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.

Comments

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.

Comments

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

Comments

-1

I got the same error:

ascii codec can't decode byte 0xe2

because I entered the .env file variable like:

OPENAI_KEY = `` 

I used backticks instead of double-quotes:

OPENAI_KEY = "" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.