環(huán)境:ubuntu
1. pip install 要不要加 sudo
不加sudo經(jīng)常會(huì)遇到權(quán)限問(wèn)題瞳腌,如:
$ pip install robotframeworklexer
Collecting robotframeworklexer
Using cached robotframeworklexer-1.0.tar.gz
Installing collected packages: robotframeworklexer
Running setup.py install for robotframeworklexer ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-bdb9pw3q/robotframeworklexer/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-nh6zqdwr-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build/lib
copying robotframeworklexer.py -> build/lib
running install_lib
copying build/lib/robotframeworklexer.py -> /usr/local/lib/python3.4/dist-packages
error: could not create '/usr/local/lib/python3.4/dist-packages/robotframeworklexer.py': Permission denied
遇到這種需要向 /usr/local/pythonx.x/ 下拷貝東西的,要么加sudo -H
,要么chmod/chown。
2. proxy
terminal下已經(jīng)export 了 proxy的匀油,是當(dāng)前用戶的環(huán)境變量磕瓷,sudo的話將找不到,所以 sudo -H pip install xxx
需要另外指定 proxy:
sudo -H pip install xxx --proxy http://ip:port
3. pip install 安裝到python2.x還是3.x
同時(shí)安裝了 python2 和 python3 的電腦成福,可以使用這種方式來(lái)決定 pip 的 package 安裝到哪里:
pip2 install xxx
pip3 install xxx
如果不注意,安裝到3了荆残,在2里咋都找不到奴艾,多煩人吶。
綜上
最佳實(shí)踐:
sudo -H pip2 install -U xxx --proxy http://ip:port