Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python setup.py develop to override installed version

I have a package I am developing. This package is already installed as an egg file parked in the site-packages directory, egg path added to easy-install.pth.

I now realized I have a bug in the package, so I invoked python setup.py develop to hook up the development dir. The path of the source dir is correctly added to easy-install.pth, but it's added latest, meaning that the already installed egg will be chosen and imported first with I issue import mypackage.

How can I have the development hook override the already installed package ?

Eventually, if I am doing it wrong, please explain what's the proper strategy to solve this use case.

like image 701
Stefano Borini Avatar asked Jun 01 '11 12:06

Stefano Borini


2 Answers

If you are using pip,

sudo pip uninstall packagename

will prompt for all packages that are in the easy-install.pth and delete all of them, upon confirmation.

You can then do a setup.py develop so that only the development branch is in the python path.

If you need multiple versions of the same library, the best option is to use virtualenv (and virtualenvwrapper as the bash helper).

Also worth mentioning, if you want the simplest solution without any network traffic (I can't imagine why), you might as well, just symlink from the site-packages, like:

sudo ln -fs ~/django_registration/registration /usr/lib/python2.6/dist-packages/django_registration

If you are using pip for package installation (why wouldn't you?) you can also get the developing version into the easy-install.pth by something like:

pip install -e hg+http://bitbucket.org/ubernostrum/django-registration/#egg=django_registration

Update, based on the comment:

If you want to use the new package only in the current module, you can manually modify the sys.path, like

sys.path.insert(1,'/path/to/package')

So, the import picks up from the right location.

like image 180
lprsd Avatar answered Oct 02 '22 20:10

lprsd


You can ask pip to override the current installed packages with --upgrade and pip can install from a local dir so:

easy_install pip # if you don't have pip installed
pip install /your/package --upgrade
like image 34
e-satis Avatar answered Oct 02 '22 20:10

e-satis