我想在我使用的服务器上安装python包networkx,在我问这个问题之前我会先搜索一下,它说要使用
pip install --user networkx
但它不起作用,linux错误是
Usage: /usr/bin/pip install [OPTIONS] PACKAGE_NAMES...
/usr/bin/pip install: error: no such option: --user
任何人都可以帮忙吗?如何在服务器中安装networkx软件包?
答案 0 :(得分:7)
如果服务器上安装了virtualenv,您可以创建虚拟环境:
virtualenv your_env_name
然后激活它:
source your_env_name/bin/activate
然后通过
安装所有需要的软件包pip install packagename
但是,如果尚未安装virtualenv,您应该查看已经回答相同问题的this thread。
最好为每个项目使用单独的virtualenv,因为这样您就可以使用
轻松导出依赖项了。pip freeze > requirements.txt
您可以将此requirements.txt添加到您的版本控制中,稍后,如果您想在另一台计算机上安装项目,您可以立即安装所有依赖项而不会弄乱版本号等:
pip install -r requirements.txt
答案 1 :(得分:4)
使用virtualenv创建本地python环境,以便您不需要root访问权限。
还有像pyenv这样的virtualenv之上的其他工具,它们更易于使用。
答案 2 :(得分:4)
也许您需要更新版本的pip?我的1.1版按预期工作
$ pip install --version
pip 1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
$ pip install --user networkx
Requirement already satisfied (use --upgrade to upgrade): networkx in /home/aric/.local/lib/python2.7/site-packages
你可以像这样升级点子(这里的说明:http://www.pip-installer.org/en/latest/installing.html)
$ wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ python get-pip.py --user
Downloading/unpacking pip from https://pypi.python.org/packages/source/p/pip/pip-1.4.1.tar.gz#md5=6afbb46aeb48abac658d4df742bff714
Downloading pip-1.4.1.tar.gz (445kB): 445kB downloaded
Running setup.py egg_info for package pip
warning: no files found matching '*.html' under directory 'docs'
warning: no previously-included files matching '*.rst' found under directory 'docs/_build'
no previously-included directories found matching 'docs/_build/_sources'
Installing collected packages: pip
Running setup.py install for pip
warning: no files found matching '*.html' under directory 'docs'
warning: no previously-included files matching '*.rst' found under directory 'docs/_build'
no previously-included directories found matching 'docs/_build/_sources'
Installing pip script to /home/aric/.local/bin
Installing pip-2.7 script to /home/aric/.local/bin
Successfully installed pip
Cleaning up...
$ pip --version
pip 1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
$ ~/.local/bin/pip --version
pip 1.4.1 from /home/aric/.local/lib/python2.7/site-packages (python 2.7)