Do not expect pip
or easy_install
change your PATH
, their task is to install the package in the current environment.
On Linux, if you use the global Python environment, you will most likely need root privileges, so you usually do:
$ sudo pip install <package>
However, this method is not recommended because it spoils the system-wide Python environment (imagine that two applications have slightly different requirements for the same package version and you may have a problem).
The recommended method is to use some kind of virtualenv, which allows you to install the python package in a separate python environment, which is also easily removed and recreated.
How do I install python based scripts on a system
It looks like you have a custom python based script that you want to use on your system.
For this scenario, I use the following method (assuming the virtualenv
tool is installed in system-wide python):
$ mkdir ~/apps $ mkdir ~/apps/myutil $ cd ~/apps/myutil $ virtualenv .env $ source .env/bin/activate (.env)$ pip install <package-or-more>
Now you have all the script installed by pip
installed in the ~/apps/myutil/.env/bin
, let's call it myscript
(there can be more of them).
The rest of the step is to create a symbolic link from some directory that is already on PATH
, for example. in /usr/local/bin
:
$ cd /usr/local/bin $ sudo ln -s ~/apps/myutil/.env/bin/myscript
From now on, you can invoke the myscript
command even without activating virtualenv.
Script update
If you need to install a later version of the script:
$ cd ~/apps/myutil $ source .env/bin/activate (.env)$ pip install --upgrade <package-or-more>
Since you have a related script, it will be automatically available in the latest version.
Naming with virtualenvwrapper
virtualenvwrapper
allows you to create multiple named virtual servers and provide easy activation and deactivation. In this case, I do the following:
$ mkvirtualenv bin-myscript (bin-myscript)$ pip install <package-or-more> (bin-myscript)$ which `myscript` ~/.Evns/bin-myscript/bin/myscript (bin-myscript)$ cd /usr/local/bin (bin-myscript)$ sudo ln -s ~/.Evns/bin-myscript/bin/myscript
Updating is even easier:
$ workon bin-myscript (bin-myscript)$ pip install --upgrade <package-or-two>
and you are done
alternative to toxin
tox
is a great tool for automatically creating virtual virtual machines and testing. I use it to create virtualenvs in directories that I like. See my other SO answer for more information.