14

The simplest way to deal with python package installations, so far, to me, has been to check out the source from the source control system and then add a symbolic link in the python dist-packages folder.

Clearly since source control provides the complete control to downgrade, upgrade to any branch, tag, it works very well.

Is there a way using one of the Package installers (easy_install or pip or other), one can achieve the same.

easy_install obtains the tar.gz and install them using the setup.py install which installs in the dist-packages folder in python2.6. Is there a way to configure it, or pip to use the source version control system (SVN/GIT/Hg/Bzr) instead.

4

4 回答 4

26

Using pip this is quite easy. For instance:

pip install -e hg+http://bitbucket.org/andrewgodwin/south/#egg=South

Pip will automatically clone the source repo and run "setup.py develop" for you to install it into your environment (which hopefully is a virtualenv). Git, Subversion, Bazaar and Mercurial are all supported.

You can also then run "pip freeze" and it will output a list of your currently-installed packages with their exact versions (including, for develop-installs, the exact revision from the VCS). You can put this straight into a requirements file and later run

pip install -r requirements.txt

to install that same set of packages at the exact same versions.

于 2009-10-26T16:08:10.317 回答
11

If you download or check out the source distribution of a package — the one that has its "setup.py" inside of it — then if the package is based on the "setuptools" (which also power easy_install), you can move into that directory and say:

$ python setup.py develop

and it will create the right symlinks in dist-packages so that the .py files in the source distribution are the ones that get imported, rather than copies installed separately (which is what "setup.py install" would do — create separate copies that don't change immediately when you edit the source code to try a change).

As the other response indicates, you should try reading the "setuptools" documentation to learn more. "setup.py develop" is a really useful feature! Try using it in combination with a virtualenv, and you can "setup.py develop" painlessly and without messing up your system-wide Python with packages you are only developing on temporarily:

http://pypi.python.org/pypi/virtualenv
于 2009-06-23T17:32:22.663 回答
4

easy_install has support for downloading specific versions. For example:

easy_install python-dateutil==1.4.0

Will install v1.4, while the latest version 1.4.1 would be picked if no version was specified.

There is also support for svn checkouts, but using that doesn't give you much benefits from your manual version. See the manual for more information above.

Being able to switch to specific branches is rarely useful unless you are developing the packages in question, and then it's typically not a good idea to install them in site-packages anyway.

于 2009-06-23T18:35:33.457 回答
0

easy_install accepts a URL for the source tree too. Works at least when the sources are in Subversion.

于 2009-09-18T20:39:07.477 回答