How to use python 2 packages in python 3 project?
I have a Python 3 project, but I need some packages which are written in Python 2.
I do not want to rewrite these python-2 packages, so forking / 2to3 is not an option.
A lot of the previous questions concern using Python 2 modules in Python 3 projects. Here's the most complete explanation. It also works the other way around and suggests the following alternatives:
subprocess
module for requests and getting the response through the CLI. So far the most straightforward way to make cross-references.
python-fire
can quickly add a CLI to a Python 3 library. You'll have a reasonable API to call from the Python 2 project.3to2
. This utility converts Python 3 code to Python 2. It remains unclear how it handles complex Python 3 projects with dependencies and Python 3-only features.six
and __future__
. It seems both of these modules are intended for writing the code compatible with Python 2-3, not for using Python 3 libraries in Python 2 projects.You can't. Any module you import in py3 codebase needs to be py3 compatible. If you can't make the upstream project do it for you, you'll have to do it yourself. As mentioned in the comments, 2to3
utility should help you with that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With