import pkg_resources
pkg_resources.require("flask>=1.0.0")
import flask
print flask.__version__
输出:
$ python2.7 test_import_flask.py
Traceback (most recent call last):
File "test_import_flask.py", line 2, in <module>
pkg_resources.require("flask>=1.0.0")
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 733, in require
return needed
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 635, in resolve
pkg_resources.VersionConflict: (Flask 0.10.1 (/misc/toolchain-builds/a87ab33ee169dddc3c9eafd7586153de2017d6fb.x86_64/lib/py/Flask-0.10.1-py2.7.egg), Requirement.parse('flask>=1.0.0'))
但是Flask有两个版本
Flask-0.10.1-py2.7.egg -> /misc/toolchain-builds/a87ab33ee169dddc3c9eafd7586153de2017d6fb.x86_64/lib/py/Flask-0.10.1-py2.7.egg
Flask-1.1.2-py2.7.egg -> /misc/toolchain-builds/a87ab33ee169dddc3c9eafd7586153de2017d6fb.x86_64/lib/py/Flask-1.1.2-py2.7.egg```
how do i make sure the script uses Flask-1.1.2-py2.7.egg and not 0.10.1?