python2和python3并存时库的安装方法

Python014

python2和python3并存时库的安装方法,第1张

python2和python3并存时库的安装方法

在安装了python2和python3的电脑上,使用命令

py -2 -m pip install xxx

py -3 -m pip install xxx

可以分别为python2和python3安装所需的库。

当系统环境或虚拟环境中安装了python2和python3时,使用pip安装模块时可能会安装在python2的包目录下,于是就会出现在python3下调包出现报错。

除了使用pip2或pip3来指定,也可以使用python命令来指定,譬如:

python3 -m pip install some_module 。

参考:

How to override the pip command to Python3.x instead of Python2.7?