Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: If there are multiple egg versions of the same package installed, how do I import specifically the version I need?

Say, for example that FooPackage-1.1 and FooPackage-1.2 are both installed in dist-packages as eggs. How do I import the one I need?

like image 454
Ken Kinder Avatar asked Mar 10 '11 20:03

Ken Kinder


1 Answers

You can use pkg_resources to specify your requirements at import time:

import pkg_resources
pkg_resources.require('FooPackage==1.2')
import FooPackage

For example:

% easy_install simplejson==2.1.3
% easy_install simplejson==2.1.2

pkg_resources.require('simplejson==2.1.2')
import simplejson
assert simplejson.__version__ == '2.1.2'
like image 133
samplebias Avatar answered Sep 19 '22 13:09

samplebias