可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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)
回答1:
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
回答2:
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 ...
回答3:
Try updating pip:
pip install -U pip
回答4:
I had that problem with matplotlib package.
I had to execute:
export LC_ALL=C
pip install --upgrade setuptools
回答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
回答6:
A combination of
sudo apt-get install python-dev
and
export LC_ALL=C
pip install --upgrade setuptools
solved my problem.
回答7:
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.
回答8:
In 'site-packages' directory, make 'sitecustomize.py' like this
import sys
sys.setdefaultencoding("utf-8")
Now you can get the file 'pip.log'
回答9:
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)
回答10:
@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
回答11:
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.
回答12:
Had a similar problem on a Jetson TK1 with Ubuntu.
Works fine with apt-get install python-pandas
回答13:
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.
回答14:
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.
回答15:
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.
回答16:
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).
回答17:
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)
回答18:
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