37
$\begingroup$

I don't want to deal with virtualenv for a local Python installation, I just want to install a few packages locally without dealing with the PYTHONPATH environment variable, how do I do that?

$\endgroup$
2
  • $\begingroup$ You say "deal with" as if virtualenv was a hassle. I've found the exact opposite to be true. (Perhaps you want --system-site-packages?) $\endgroup$ Commented Sep 23, 2012 at 17:09
  • $\begingroup$ it was hypothetically posed :) virtualenv is awesome but it doesn't fit every use case. $\endgroup$ Commented Sep 25, 2012 at 10:17

3 Answers 3

56
$\begingroup$

Python (as of 2.6 and 3.0) now searches in the ~/.local directory for local installs, which do not require administrative privileges to install, so you just need to point your installer to that directory.

If you have already downloaded the package foo and would like to install it manually, type:

cd path/to/foo
python setup.py install --user

If you are using easy_install and would like the package downloaded and installed:

easy_install --prefix=$HOME/.local/ foo

Update by RafiK

pip install --user foo

The following answer is provided for historical purposes: It's a little more work if you are using pip to download and install:

pip install --install-option="--prefix=$HOME/.local" foo
$\endgroup$
1
  • 3
    $\begingroup$ update: pip now supports a --user flag: pip install --user SomePackage (link to manual) Using this, everything should work out of the box even on different OSes $\endgroup$ Commented Mar 11, 2015 at 15:17
5
$\begingroup$

Even though I like Python as a language, distributing Python packages is a mess. I always find people not familiar with Python struggling with it.

Next to the user-local install as outlined by Aron (using --user, or --prefix), another option is EasyBuild (http://hpcugent.github.com/easybuild/). Not only for Python packages, but for any (scientific) software package. Once EasyBuild has support for it, building and installing a software package is basically a single command.

For a list of software packages currently supported, see https://github.com/hpcugent/easybuild/wiki/List-of-supported-software-packages.

Disclaimer: I am a developer of EasyBuild.

$\endgroup$
0
2
$\begingroup$

@Aron: Be sure to add the local site-packages path to the environment variable $PYTHONPATH

$\endgroup$
6
  • $\begingroup$ It's automatically included in the site path as of Python 2.6 and Python 3.0 :) $\endgroup$ Commented Aug 4, 2012 at 10:11
  • $\begingroup$ @AronAhmadia not if you use the --prefix option. $\endgroup$ Commented Jan 21, 2013 at 8:02
  • $\begingroup$ @JensTimmerman - the site path is where Python looks when it starts for modules to import, any time you are running Python. The prefix option specifies where to install a given package when you are installing a Python package. Two completely separate notions. $\endgroup$ Commented Jan 21, 2013 at 13:22
  • $\begingroup$ @AronAhmadia yes, my point is that when you use easy_install --prefix=/tmp you need to add "/tmp/lib/pythonx.x/site-packages" to your PYTHONPATH variable or it will not be picked up by python. $\endgroup$ Commented Jan 22, 2013 at 14:50
  • $\begingroup$ @AronAhmadia pastebin.com/6FCTetCc $\endgroup$ Commented Jan 22, 2013 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.