python当中pip使用,如何在Python 3.4中使用pip 3?

My OS is Lubuntu 14.04 and the default Python version is Python 2.7.6, but in

/usr/bin

it says I have Python 3.4 installed (when I run python3 -V it says I have Python 3.4.0). Does Python 3.4 come with a pre-installed pip? Because when I run

pip -V

in a terminal it says that the program is currently not installed. With that said, assume I want to create a Django project which uses Python 3.4.3: do I first download python3-pip and then virtualenv and then do

pip3 install Django==1.8

? or is there a pre-installed pip 3 which comes with Python 3.4 which I already have installed?

解决方案

Instead of installing python3-pip via apt-get or whatever (because the version in the repo is too old), download get-pip.py, switch to the folder where you saved it, and run

sudo python3 get-pip.py

and it will install the latest version of pip for you. It may create a symlink to pip3, it may not, I don't remember.

You can then run

sudo pip install virtualenv

then use it to create your virtualenv, activate it, then use the pip installed inside it to get Django.

NOTE:

You can use the same copy of get-pip.py to install pip for Python 2. If you want to do that, however, I'd advise you to run

sudo python get-pip.py

before you run

sudo python3 get-pip.py

Whichever one you install last will take the pip filename. I don't know if Python 2 installs a command called pip2 (I know upgrading pip via pip does), but after you run the Python 2 install, run

sudo ln -s /usr/local/bin/pip2.7 /usr/local/bin/pip2

to create a pip2 alias. You can then run the Python 3 install, which will overwrite /usr/local/bin/pip, then run

sudo ln -s /usr/local/bin/pip3.4 /usr/local/bin/pip3

to create a pip3 command as well (if you get an error that the file already exists, then you're good to go). Now, instead of running pip when installing to your system site-packages and not knowing exactly which version you're calling, you can just use pip2 and pip3 to explicitly state the version you want.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值