「PyPY」- 安装pip命令

问题描述

该笔记将记录:在 PyPy 中,安装 pip 命令。

为什么是「在PyPy中,安装pip命令」?

在PyPy中,它有自己的site-packages路径,因此需要为PyPy单独安装模块。

它不能与Python共享同一个site-packages路径。因此我们需要为PyPy单独安装pip命令。

安装方法

操作系统:Kali GNU/Linux Rolling

# 推荐方法

正常情况下,可以使用pypy -m ensurepip命令进行pip安装,这是推荐的一种方法:

#!/bin/sh

################################################################################
# 使用ensurepip模块
################################################################################
pypy -m ensurepip

################################################################################
# 或者执行如下命令
################################################################################
# pypy
Python 2.7.13 (7.1.1+dfsg-1, Aug 08 2019, 23:50:46)
[PyPy 7.1.1 with GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>> import ensurepip
>>>> ensurepip.bootstrap(upgrade=True)

使用该方法要求在安装PyPy时,要安装ensurepip模块。

# 手动安装

有时候上面的方法不可能。比如,在Debian/Ubuntu中会出现如下提示:

ensurepip is disabled in Debian/Ubuntu for the system python.

Python modules For the system python are usually handled by dpkg and apt-get.

    apt-get install pypy-<module name>

Install the python-pip package to use pip itself.  Using pip together
with the system python might have unexpected results for any system installed
module, so use it on your own risk, or make sure to only use it in virtual
environments.

又或者,在安装PyPY时没有安装ensurepip模块。

对于这两种情况都可以使用“手动安装”的方法:

#!/bin/sh

wget https://bootstrap.pypa.io/get-pip.py
/usr/lib/pypy/bin/pypy-c get-pip.py

使用方法

安装pip模块之后,就可以使用它了。由于没有生成pip命令,所以要使用如下方法:

#!/bin/sh

pypy -m pip install validators

!!!注意,你肯能需要安装pypy-dev包,即头文件。因为在某些扩展的安装过程中,需要编译,因此需要安装pypy-dev包,并且可能开需要特定类库的头文件。

参考文献

Install pip on pypy
PyPy: “ImportError: No module named xlrd”