Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to install python packages locally for development

Being new to the python games I seem to have missed out on some knowledge on how you can develop on a program but also keep it in your live environment.

Programs like gpodder can be run directly from the source checkout which is really handy however others want to be "installed" to run.

A lot of programs are distributed with a setup.py with instructions to run "python ./setup.py install" as root which will put stuff somewhere in your file-system. There are even install commands like "develop" which seem to hold the promise of what I want. So I tried:

export PYTHONPATH=/home/alex/python
python ./setup.py develop --install-dir=/home/alex/python

Which downloaded a bunch of stuff locally and seems magically ensure the application I'm hacking on is still being run out of the src tree. So I guess my roundabout question is is this the correct way of developing python code? How do things like easy_install and pip factor into this?

So I tried the following:

 python /usr/share/pyshared/virtualenv.py /home/alex/src/goobook
 cd /home/alex/src/goobook/googbook.git
 /home/alex/src/goobook/bin/python ./setup.py develop

And finally linked the program in question to my ~/bin

 cd /home/alex/src/goobook
 linkbin.pl bin/goobook

However invocation throws up a load of extra chatter which seems to imply it's wrong:


17:17 alex@socrates/i686 [goobook] >goobook --help
/home/alex/bin/goobook:5: UserWarning: Module pkg_resources was already imported from        /home/alex/src/goobook/lib/python2.5/site-packages/setuptools-0.6c8-py2.5.egg/pkg_resources.py, but /home/alex/src/goobook/lib/python2.5/site-packages/distribute-0.6.10-py2.5.egg is being added to sys.path
  from pkg_resources import load_entry_point
/home/alex/bin/goobook:5: UserWarning: Module site was already imported from /home/alex/src/goobook/lib/python2.5/site.pyc, but /home/alex/src/goobook/lib/python2.5/site-packages/distribute-0.6.10-py2.5.egg is being added to sys.path
  from pkg_resources import load_entry_point

like image 829
stsquad Avatar asked Jul 19 '10 13:07

stsquad


People also ask

How do I install a Python package locally?

To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.

Can I install Python packages offline?

Download the main packages on the online computer. Transfer the package files from the online computer to the offline computer. On the offline computer, decompress the transferred files. Install the required RPMs on the offline computer.

Where should Python libraries be installed?

Usually the Python library is located in the site-packages folder within the Python install directory, however, if it is not located in the site-packages folder and you are uncertain where it is installed, here is a Python sample to locate Python modules installed on your computer.


2 Answers

Install:

http://pypi.python.org/pypi/virtualenv

to set up a localized virtual environment for your libraries, and:

http://pypi.python.org/pypi/setuptools

i.e. "easy_install" to install new things.

like image 57
eruciform Avatar answered Sep 25 '22 21:09

eruciform


Virtualenv allows you to work in completely independent and isolated Python environments. It will let you easily create multiple environments which have different Python packages installed or different versions of a same package. Virtualenv also lets you easily switch between your different environments.

As of 2012, the de facto preferred tool for package management in Python is pip rather than setuptools. Pip is able to handle dependencies and to install/uninstall globally or inside a virtual environment. Pip even comes out-of-the-box with virtualenv.

Python 3

Also worth mentioning is the fact that virtual environments are becoming a part of Python itself in release 3.3, with the implementation of PEP 405.

like image 26
Rodrigue Avatar answered Sep 23 '22 21:09

Rodrigue