0
import pkg_resources
pkg_resources.require("flask>=1.0.0")


import flask

print flask.__version__

OUTPUT:

$ 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'))

But there are two versions of 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?
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
ealeon
  • 12,074
  • 24
  • 92
  • 173
  • use virtualenv and install packages under it – adrtam Nov 03 '20 at 22:38
  • yeah, @adrtam has the answer. virtualenvs exist pretty much just to solve this problem. With a virtualenv, you only install one version of any package, so there's no ambiguity and no reason to specify the version outside of your `requirements.txt` file. – CryptoFool Nov 03 '20 at 22:55
  • @Steve I understand that but is there a way to specify the version of the module from the python script? – ealeon Nov 04 '20 at 18:00
  • Not that I know of. - If anything, I'd think it might be handled by a command line parameter to the python executable – CryptoFool Nov 04 '20 at 20:30

0 Answers0