Force python to use an older version of module (than what I have installed now)

南笙酒味 提交于 2019-11-27 19:08:10
SingleNegationElimination

A better version of option B. would be to replace

import twisted

by

import pkg_resources
pkg_resources.require("Twisted==8.2.0")
import twisted

which will arrange for the correct version of twisted to be imported, so long as it's installed, and raises an exception otherwise. This is a more portable solution.

This won't work, though (nor would any other variaton of option B), if twisted gets imported before the pkg_resources.require gets called; twisted will already be in sys.modules

OP Edit: Minor syntax correction, per pkg_resources docs

I can't tell you what is best in your situation, but you might be able to consider:

Option D: run it in a virtual machine (eg. with Windows 7)

Option E: install old version of python/twisted on another machine

If SingleNegationElimination's solution doesn't work, be aware that you don't need to replace all 33 instances of the import; you only need to modify sys.path at the entry points; e.g. you could target just your module's __init__.py files.

There you would insert e.g.

import sys
sys.path.insert(0, DIR)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!