Reputation: 1369
I've a django application where I'm importing a 3rd party app. The app is written for python3, however my application environment is python 2.7 and django 1.11.16 .
The 3rd party app works very well with python2 except for one line in the beginning. One of the file of the 3rd party app contains this:
from urllib.parse import urlencode, quote
. If I change this line to
from urllib import urlencode, quote
in the virtualenv, it works perfectly, however this is a very bad solution.
I don't want to fork the whole application, but is there any other way for the workaround?
Upvotes: 0
Views: 169
Reputation: 991
Disclaimer: Considering that Python2 is not supported anymore you will find less libraries being compatible with your code. I think the best idea is to upgrade your Python version. These 2 tools can help you a lot:
With this being said, there could be another hackish way of making it work. In your application's entrypoint (manage.py in case of Django, could also work in settings.py) you can do this:
import sys
sys.modules['urllib.parse'] = __import__('urllib')
from urllib.parse import urlencode, quote # works now
If this is the only difference it could work but I find the code pretty dangerous.
Upvotes: 1