I know the obvious answer is to use virtualenv and virtualenvwrapper, but for various reasons I can't/don't want to do that.
So how do I modify the command
pip install package_name
to make pip
install the package somewhere other than the default site-packages
?
To add to the already good advice, as I had an issue installing IPython when I didn't have write permissions to
/usr/local
.pip uses distutils to do its install and this thread discusses how that can cause a problem as it relies on the
sys.prefix
setting.My issue happened when the IPython install tried to write to '/usr/local/share/man/man1' with Permission denied. As the install failed it didn't seem to write the IPython files in the bin directory.
Using "--user" worked and the files were written to ~/.local. Adding ~/.local/bin to the $PATH meant I could use "ipython" from there.
However I'm trying to install this for a number of users and had been given write permission to the
/usr/local/lib/python2.7
directory. I created a "bin" directory under there and set directives for distutils:then (
-I
is used to force the install despite previous failures/.local install):Then I added
/usr/local/lib/python2.7/bin
to$PATH
.I thought I'd include this in case anyone else has similar issues on a machine they don't have sudo access to.
With pip
v1.5.6
on Pythonv2.7.3
(GNU/Linux), option--root
allows to specify a global installation prefix, (apparently) irrespective of specific package's options. Try f.i.,Use:
You might also want to use
--ignore-installed
to force all dependencies to be reinstalled using this new prefix. You can use--install-option
to multiple times to add any of the options you can use withpython setup.py install
(--prefix
is probably what you want, but there are a bunch more options you could use).Installing a Python package often only includes some pure Python files. If the package includes data, scripts and or executables, these are installed in different directories from the pure Python files.
Assuming your package has no data/scripts/executables, and that you want your Python files to go into
/python/packages/package_name
(and not some subdirectory a few levels below/python/packages
as when using--prefix
), you can use the one time command:If you want all (or most) of your packages to go there, you can edit your
~/.pip/pip.conf
to include:That way you can't forget about having to specify it again and again.
Any excecutables/data/scripts included in the package will still go to their default places unless you specify addition install options (
--prefix
/--install-data
/--install-scripts
, etc., for details look at the custom installation options).Newer versions of
pip
(8 or later) can directly use the--prefix
option:where
$PREFIX_PATH
is the installation prefix where lib, bin and other top-level folders are placed.I suggest to follow the documentation and create ~/.pip/pip.conf file. Note in the documentation there are missing specified header directory, which leads to following error:
The full working content of conf file is:
Unfortunatelly I can install, but when try to uninstall pip tells me there is no such package for uninstallation process.... so something is still wrong but the package goes to its predefined location.