-1

I want to use python3 code in a python2 program, like this:

py3_code.py:

    def add(a, b):
        return a + b

py2_code.py:

    from py3_code import add
    add(1, 2)

I have tried to import a python3 .so in my python2 program, but I got an: ImportError: undefined symbolL _PyFalseStruct

So how can I do this?

dungarian
  • 171
  • 6
  • Why would you want to do that? any way [this](https://stackoverflow.com/a/44965570/5168011) might work for you but I haven't tried it myself. – Guy Jun 01 '22 at 04:37
  • The code you've shown works the same in 2 and 3, so no problem, you should be able to import it on python 2. Where does the .so file come into play? Do you have an extension module? – tdelaney Jun 01 '22 at 04:38
  • 1
    Your example code works because in *that particular instance* there is no difference between Python 2 and Python 3. But in the general case you can't do that because the two languages are incompatible. And if your import has binary extensions there is no guarantee that you can import across minor version numbers, for example Python 3.5 might fail to import a Python 3.4 module with binary extensions, or crash trying to use it. – BoarGules Jun 01 '22 at 07:32

0 Answers0