Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install python package without root access [duplicate]

Tags:

python

pip

I want to install python package networkx in the server I use, and I do search before I ask this question, it says to use

pip install --user networkx

but it doesn't work and the linux error is

Usage: /usr/bin/pip install [OPTIONS] PACKAGE_NAMES...

/usr/bin/pip install: error: no such option: --user

anyone can help? How can I install networkx package in the server?

like image 687
ilovecp3 Avatar asked Dec 14 '13 15:12

ilovecp3


2 Answers

If virtualenv is installed on the server, you can create a virtual environment:

virtualenv your_env_name

Then activate it:

source your_env_name/bin/activate

Then install all your desired packages via

pip install packagename

However, if virtualenv is not installed yet, you should take a look at this thread where the same question has been answered already.

It is still better to use a separate virtualenv for each of your projects, because then you can easily export your dependencies using

pip freeze > requirements.txt

You could add this requirements.txt to your version control, and later, if you want to install your project on another machine, you can install all dependencies at once without messing with version numbers etc:

pip install -r requirements.txt
like image 130
schreon Avatar answered Oct 07 '22 02:10

schreon


Maybe you need a newer version of pip? My version 1.1 works as expected

$ 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

You can upgrade pip like this (instructions here too: 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)
like image 39
Aric Avatar answered Oct 07 '22 01:10

Aric