How to install python modules without root access?

匿名 (未验证) 提交于 2019-12-03 02:11:02

问题:

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?

回答1:

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 


回答2:

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 3 commands in the shell will be enough:

$ curl -O https://raw.github.com/pypa/virtualenv/master/virtualenv.py $ python 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/



回答3:

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



回答4:

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.



回答5:

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 


回答6:

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 


回答7:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!