Ubuntu:为Python3安装 pip3, 绑定 pip3到 python3, How to install pip for Python 3.6 on Ubuntu 16.10?

 

首先通过以下命令查看 Python 的版本

python -V

关于切换 Python 默认版本,可以参考文章:转换Python默认版本

安装 pip3,很多时候,你会发现,自己已经安装了,但是系统会提示没有这个命令,例如:

sudo pip3 install virtualenv
sudo: pip3: command not found

sudo apt-get install python3-pip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-pip is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.

但是运行 pip3的时候,依然会有类似下面的报错:

pip3: command not found but python3-pip is already installed

输入命令:

pip3 --version

你会发现pip3对应到了 Python2.7上!

pip 10.0.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

OK,现在给你一个正确安装 pip3 到对应的 python3的方法:

# 不用wget,避免生成文件到硬盘 
curl https://bootstrap.pypa.io/get-pip.py | sudo python3.6

# 绑定 pip3到 python3
(pip -V && pip3 -V && pip3.6 -V) | uniq

#或者使用 python3.6 -m pip ,效果相同
#python3.6 -m pip -V

然后你可以看到输出:

pip 10.0.1 from /usr/local/lib/python3.6/dist-packages (python 3.6)

完成!

 

另外,运行

locate pip3

可以查看 pip3的路径

/<path>/pip3
/<path>/pip3.x

 

参考来源:
https://askubuntu.com/questions/889535/how-to-install-pip-for-python-3-6-on-ubuntu-16-10
https://stackoverflow.com/questions/30993086/pip3-command-not-found-but-python3-pip-is-already-installed/37659137

 

本文:Ubuntu:为Python3安装 pip3, How to install pip for Python 3.6 on Ubuntu 16.10?

Loading

2 Comments

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.