简体   繁体   中英

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?

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM