227

I'm taking some university classes and have been given an 'instructional account', which is a school account I can ssh into to do work. I want to run my computationally intensive Numpy, matplotlib, scipy code on that machine, but I cannot install these modules because I am not a system administrator.

How can I do the installation?

Michael Petrotta
  • 56,954
  • 26
  • 136
  • 173
Rishi
  • 3,438
  • 4
  • 26
  • 40
  • 14
    You can pass --user or --prefix to setup.py for the package you are installing to install it locally. See [alertnative installation for Python modules](http://docs.python.org/install/index.html#alternate-installation) – arunkumar Sep 19 '11 at 00:47

9 Answers9

309

In most situations the best solution is to rely on the so-called "user site" location (see the PEP for details) by running:

pip install --user package_name

Below is a more "manual" way from my original answer, you do not need to read it if the above solution works for you.


With easy_install you can do:

easy_install --prefix=$HOME/local package_name

which will install into

$HOME/local/lib/pythonX.Y/site-packages

(the 'local' folder is a typical name many people use, but of course you may specify any folder you have permissions to write into).

You will need to manually create

$HOME/local/lib/pythonX.Y/site-packages

and add it to your PYTHONPATH environment variable (otherwise easy_install will complain -- btw run the command above once to find the correct value for X.Y).

If you are not using easy_install, look for a prefix option, most install scripts let you specify one.

With pip you can use:

pip install --install-option="--prefix=$HOME/local" package_name
tiho
  • 5,951
  • 2
  • 25
  • 30
  • 1
    what if python does not have `pip` and `easy_install` available? – Girardi Feb 16 '14 at 16:24
  • Installation went just fine (the pip method), but importing package_name is not working. Do I need to change/add some configurations? also where were the installation copied to (folder wise)? – idoda Sep 03 '14 at 16:04
  • What if you are behind a corporate firewall that blocks internet access, and you can only copy files from a network drive? – rleelr Sep 30 '15 at 10:24
  • 2
    // , @AnotherDayAnotherRob, that sounds like a good _question_. – Nathan Basanese Apr 04 '16 at 04:43
  • What if you have say `google.protobuf` package installed in a directory where you don't have permissions and you want to add a module (say `descriptor_pb2.py`) locally. I've tried placing it in `$HOME/local/lib/pythonX.Y/site-packages/google/protobuf` but it doesn't work (gives import error). – mescarra Apr 20 '16 at 15:54
  • I doubt this will be addressed but, once I do all of these steps and I get say pandas installed, where should I save a python script that then imports pandas? – Garrett Miller Sep 16 '16 at 15:51
  • 2
    It may make sense to update the answer and put `--user` instruction at the top.:) – VasiliNovikov Oct 14 '16 at 11:17
  • this saved my time, installed new pip locally using old pip, then packages locally as well, prepended to my PATH, no need to submit CR :) –  Oct 19 '16 at 04:13
  • 1
    @Girardi In case you have installed python from src to a local dir /my_python/, it would be useful to firstly install pip in this location with: wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py -O - | /my_python/bin/python - then you can install other modules with pip + prefix – teng_wenxuan Aug 12 '17 at 00:55
51

No permissions to access nor install easy_install?

Then, you can create a python virtualenv (https://pypi.python.org/pypi/virtualenv) and install the package from this virtual environment.

Executing 4 commands in the shell will be enough (insert current release like 16.1.0 for X.X.X):

$ curl --location --output virtualenv-X.X.X.tar.gz https://github.com/pypa/virtualenv/tarball/X.X.X
$ tar xvfz virtualenv-X.X.X.tar.gz
$ python pypa-virtualenv-YYYYYY/src/virtualenv.py my_new_env
$ . my_new_env/bin/activate
(my_new_env)$ pip install package_name

Source and more info: https://virtualenv.pypa.io/en/latest/installation/

Niklas
  • 64
  • 2
  • 5
tremendows
  • 4,136
  • 3
  • 30
  • 50
  • 1
    This answer was useful for me on a system with no `pip` installed. – Dan Stowell Sep 02 '13 at 14:16
  • I tried a variant for my local python installation. curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | ~/Python-2.7.8/python – Neerav Aug 11 '14 at 18:34
  • 3
    The source seem to have moved and the above doesn't work out of the box. The similar instructions at `https://virtualenv.pypa.io/en/latest/installation/` work fine though:) – Andras Deak Mar 14 '17 at 00:05
13

You can run easy_install to install python packages in your home directory even without root access. There's a standard way to do this using site.USER_BASE which defaults to something like $HOME/.local or $HOME/Library/Python/2.7/bin and is included by default on the PYTHONPATH

To do this, create a .pydistutils.cfg in your home directory:

cat > $HOME/.pydistutils.cfg <<EOF
[install]
user=1
EOF

Now you can run easy_install without root privileges:

easy_install boto

Alternatively, this also lets you run pip without root access:

pip install boto

This works for me.

Source from Wesley Tanaka's blog : http://wtanaka.com/node/8095

yusong
  • 410
  • 2
  • 7
  • 18
  • 1
    This worked for me to install without root access on linux server. Thank you But I don't have any idea why it worked. Can any body give a hint ? – ChathuraG Aug 10 '16 at 23:19
9

If you have to use a distutils setup.py script, there are some commandline options for forcing an installation destination. See http://docs.python.org/install/index.html#alternate-installation. If this problem repeats, you can setup a distutils configuration file, see http://docs.python.org/install/index.html#inst-config-files.

Setting the PYTHONPATH variable is described in tihos post.

rocksportrocker
  • 6,639
  • 2
  • 28
  • 46
  • 1
    Thanks a lot. I've successfully installed `lxml` library using `python /setup.py install --home=` – Serge S. Apr 16 '12 at 10:15
7

Important question. The server I use (Ubuntu 12.04) had easy_install3 but not pip3. This is how I installed Pip and then other packages to my home folder

  1. Asked admin to install Ubuntu package python3-setuptools

  2. Installed pip

Like this:

 easy_install3 --prefix=$HOME/.local pip
 mkdir -p $HOME/.local/lib/python3.2/site-packages
 easy_install3 --prefix=$HOME/.local pip
  1. Add Pip (and other Python apps to path)

Like this:

PATH="$HOME/.local/bin:$PATH"
echo PATH="$HOME/.local/bin:$PATH" > $HOME/.profile
  1. Install Python package

like this

pip3 install --user httpie

# test httpie package
http httpbin.org
Colonel Panic
  • 119,181
  • 74
  • 363
  • 435
4

I use JuJu which basically allows to have a really tiny linux distribution (containing just the package manager) inside your $HOME/.juju directory.

It allows to have your custom system inside the home directory accessible via proot and, therefore, you can install any packages without root privileges. It will run properly to all the major linux distributions, the only limitation is that JuJu can run on linux kernel with minimum reccomended version 2.6.32.

For instance, after installed JuJu to install pip just type the following:

$>juju -f
(juju)$> pacman -S python-pip
(juju)> pip
user967489
  • 39
  • 2
3

The best and easiest way is this command:

pip install --user package_name

http://www.lleess.com/2013/05/how-to-install-python-modules-without.html#.WQrgubyGOnc

FelixSFD
  • 5,456
  • 10
  • 40
  • 106
1

Install virtualenv locally (source of instructions):

Important: Insert the current release (like 16.1.0) for X.X.X.
Check the name of the extracted file and insert it for YYYYY.

$ curl -L -o virtualenv.tar.gz https://github.com/pypa/virtualenv/tarball/X.X.X
$ tar xfz virtualenv.tar.gz
$ python pypa-virtualenv-YYYYY/src/virtualenv.py env

Before you can use or install any package you need to source your virtual Python environment env:

$ source env/bin/activate

To install new python packages (like numpy), use:

(env)$ pip install <package>
Niklas
  • 64
  • 2
  • 5
  • This is basically an updated version of [tremendows instructions](https://stackoverflow.com/a/13958308/9845608). His instructions are outdated. My edit was rejected. Because of that I posted it as a new instruction. – Niklas May 22 '19 at 11:10
1

Install Python package without Admin rights

import sys

!{sys.executable} -m pip install package_name

Example

import sys

!{sys.executable} -m pip install kivy

Reference: https://docs.python.org/3.4/library/sys.html#sys.executable

Suhas_Pote
  • 1,801
  • 1
  • 13
  • 23