views:

97

answers:

2

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?

EDIT TO ADD

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

+6  A: 

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.

eruciform
It almost worked, see the question for the problems I ran into.
stsquad
@stsquad: i think it matters what python you use when setting up the virtualenv and then when using the virtualenv-installed things. it appears above what you may have used 2 different versions. also, set up your `PYTHONPATH` to point to the new stuff and not the old stuff, and reload your shell. i'm guessing that it might be conflicting with the previous installation...
eruciform
virtualenv installs setuptools (or distribute, which is a newer replacement for it) inside the virtualenv; you don't need to install setuptools explicitly as a second step. If you did, that may be what causes those UserWarnings you see.
Marius Gedminas
A: 

The best way to develop python apps with dependencies is to : 1) Download desired version of the python interpreter 2) Install and use buildout (http://www.buildout.org/)

Buildout is something like Maven for java ( will fetch all needed packag automatically )

This way your python interpreter will not be polluted by third party packages ( this is important if you will be running developed application on other machines). Aditionally you can integrate buildout with virtualenv package ( this allows you to create virtual python interpreters for each project).

Piotr Duda