您的位置:首页 > 编程语言 > Python开发

虚拟环境virtualenv问题PIP Install Numpy throws an error “ascii codec can't decode byte 0xe2”

2018-01-17 18:48 417 查看
转换虚拟环境:
virtualenv VIRTUALENV_DIR
--system-site-packages


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

Ask
Question

up vote63down
votefavorite
9

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?

来源: https://stackoverflow.com/questions/26473681/pip-install-numpy-throws-an-error-ascii-codec-cant-decode-byte-0xe2

 

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 numpy pandas pip

shareimprove
this question
asked Oct 20 '14 at 19:46



Josh.F
1,18411021

 
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: stackoverflow.com/questions/19595944/… – BenjaminGolder Dec
4 '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
7 at 22:50
add
a comment


14 Answers

activeoldestvotes

up vote43down
voteaccepted
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

shareimprove
this answer
answered Oct 20 '14 at 20:11



Jeff M.
79977

 
1 
Thanks! Also, I found that if python-dev doesn't come stock on the computer, you need that too – Josh.F Oct
20 '14 at 20:16
 
Yeah. I remember that now.. Good catch. – Jeff
M. Oct
20 '14 at 20:17
3 
You don't need to recreate your 
virtualenv
,
you can modify an existing one with 
virtualenv
VIRTUALENV_DIR --system-site-packages
. – fiatjaf Dec
6 '14 at 3:09
3 
Had same issue on Ubuntu server 14.02. 
sudo
apt-get install python2.7-dev
 solved the issue. – baltasvejas May
25 '15 at 16:31
1 
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... – Mark Aug
2 '15 at 13:53
show 1 more
comment
up vote32down
vote
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 ...


shareimprove
this answer
edited Jun
5 at 13:02

answered Jul 22 '15 at 20:16



msemelman
1,8511419

 
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 8:43
 
@GilHiram Depends on your shell type you may have to set up this env variable in other places. unix.stackexchange.com/questions/50665/… – 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 ? – javadba Jun
27 at 20:40
add
a comment
up vote8down
vote
Try updating pip:

 

pip install -U pip


shareimprove
this answer
answered Jul 23 '16 at 17:40



Noah
6,76833952

 
 
This worked for me on debian jessie inside of a venv. – kalebo May
4 at 15:47 
add
a comment
up vote7down
vote
I had that problem with matplotlib package. I had to execute:

 

export LC_ALL=C


pip install --upgrade setuptools


shareimprove
this answer
answered Aug 12 '15 at 19:14



max
3,20443868

 add
a comment
up vote4down
vote
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

shareimprove
this answer
answered Mar 1 '16 at 19:18



jvd10
701612

 add
a comment
up vote3down
vote
A combination of

 

sudo apt-get install python-dev


and

 

export LC_ALL=C


pip install --upgrade setuptools


solved my problem.

shareimprove
this answer
edited Oct
21 '15 at 7:00



wudzik
16.8k125478

answered Oct 21 '15 at 6:36



Ali
311

 add
a comment
up vote3down
vote
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.

shareimprove
this answer
edited Mar
22 at 19:19

answered Dec 15 '14 at 22:03



Selah
2,69531933

 
1 
Same here. Upgraded VM instance from 1 to a 2 gig RAM temporarily while installing. – darwindave Jan
15 '15 at 3:05
add
a comment
up vote1down
vote
In 'site-packages' directory, make 'sitecustomize.py' like this

 

import sys


sys.setdefaultencoding("utf-8")


Now you can get the file 'pip.log'

shareimprove
this answer
answered Nov 20 '14 at 8:46



Toby Seo
808

 
 
This is only an indirect answer, but it teaches something and does not deserve to be downvoted. – user1158559 Mar
3 '16 at 17:05
add
a comment
up vote1down
vote
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)

shareimprove
this answer
answered Sep 16 '15 at 8:09



Tavleen
112

 add
a comment
up vote0down
vote
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.

shareimprove
this answer
answered Dec 4 '15 at 1:21



arinarmo
335

 add
a comment
up vote0down
vote
Had a similar problem on a Jetson TK1 with Ubuntu.
Works fine with 
apt-get
install python-pandas


shareimprove
this answer
answered Mar 5 '16 at 0:11



rafaelvalle
2,0561324

 add
a comment
up vote0down
vote
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.

shareimprove
this answer
answered Aug 7 at 21:24



jlh
578824

 add
a comment
up vote0down
vote
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.

shareimprove
this answer
answered Aug 11 at 20:55



Pete
6,85672743

 add
a comment
up vote0down
vote
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.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐