环境:ubuntu
1. pip install 要不要加 sudo
不加sudo经常会遇到权限问题,如:
$ 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下已经export 了 proxy的,是当前用户的环境变量,sudo的话将找不到,所以 sudo -H pip install xxx
需要另外指定 proxy:
sudo -H pip install xxx --proxy http://ip:port
3. pip install 安装到python2.x还是3.x
同时安装了 python2 和 python3 的电脑,可以使用这种方式来决定 pip 的 package 安装到哪里:
pip2 install xxx
pip3 install xxx
如果不注意,安装到3了,在2里咋都找不到,多烦人呐。
综上
最佳实践:
sudo -H pip2 install -U xxx --proxy http://ip:port