Failed to install pip for pypy on Ubuntu

2019-06-25 10:08发布

问题:

I cannot install pip for pypy 4.0.1 on Ubuntu 15.10.

I downloaded pypy 4.0.1 from http://pypy.org/download.html. Created a symlink for it. And used wget to download get-pip.py from https://bootstrap.pypa.io/get-pip.py.

But when I ran sudo pypy get-pip.py, I got exception:

Collecting pip
Exception:
Traceback (most recent call last):
    File "/tmp/tmps2kjCI/pip.zip/pip/basecommand.py", line 211, in main
      status = self.run(options, args)
    File "/tmp/tmps2kjCI/pip.zip/pip/commands/install.py", line 294, in run
      requirement_set.prepare_files(finder)
    File "/tmp/tmps2kjCI/pip.zip/pip/req/req_set.py", line 334, in prepare_files
      functools.partial(self._prepare_file, finder))
    File "/tmp/tmps2kjCI/pip.zip/pip/req/req_set.py", line 321, in _walk_req_to_install
      more_reqs = handler(req_to_install)
    File "/opt/pypy-4.0.1-linux64/lib_pypy/_functools.py", line 42, in __call__
      return self._func(*(self._args + fargs), **fkeywords)
    File "/tmp/tmps2kjCI/pip.zip/pip/req/req_set.py", line 491, in _prepare_file
      session=self.session)
    File "/tmp/tmps2kjCI/pip.zip/pip/download.py", line 825, in unpack_url
      session,
    File "/tmp/tmps2kjCI/pip.zip/pip/download.py", line 673, in unpack_http_url
      from_path, content_type = _download_http_url(link, session, temp_dir)
    File "/tmp/tmps2kjCI/pip.zip/pip/download.py", line 885, in _download_http_url
      with open(file_path, 'wb') as content_file:
    TypeError: expected string, got NoneType object

I could run sudo python get-pip.py without problem but failed with pypy. I also tried Ubuntu 12.04 and 14.04 but no luck.

I have Python 2.7.10 installed and I'm using a Linode machine. But changed to a DigitalOcean one didn't help.

回答1:

How about installing PyPy from the Ubuntu archives sudo apt install pypy. Or if you want the latest version, from the PyPy PPA

Then if you create a virtualenv, it will have pip inside it:

$ sudo apt-get install virtualenv
$ virtualenv -p pypy ve
$ . ve/bin/activate
$ pip install ...


回答2:

I had the same issue, and the solution is easy, yo have to run this command:

export LC_ALL=C.UTF-8

And then run the pip installation.

You should add this line to your .bashrc or .bash_profile in the server, even you can add it to /etc/environment to have it in a global way. (If someone has a better solution, please tell me)

Edit (2016-10):

Above is the global and lazy solution for any other distribution. If you're in ubuntu, you need to reconfigure the locales and you can do it with:

sudo locale-gen "en_US.UTF-8"
sudo dpkg-reconfigure locales