0

I've got a package with swig wrapping C for Python that I'm trying to upgrade to Python 3. I'm building it under Linux (CentOS) (provided in a Docker environment).

My problem is that the compile and link options assume I'm using Python 2.7. That is, the compile includes

-I/usr/include/python2.7

and the link includes

-lpython2.7

I got the compilation to work by including a compile option to find the Python 3 include directory:

CC="gcc -I/usr/include/python3.6m" python setup.py build_ext

but the link is failing due to not finding the python2.7 library:

/usr/bin/ld: cannot find -lpython2.7 collect2: error: ld returned 1 exit status

How do I tell distutils I'm a Python 3 shop now? "python" already gives "python3".

4
  • 1
    swig -python -py3 ? Commented Apr 27, 2021 at 23:41
  • 1
    This is the command line to tell swig that you use python3. I will recommend that you simply use the distutils from Python3, e.g. in virtual environment. Check also the setup.py script if there is anything pointing to python 2.7 Commented Apr 28, 2021 at 12:24
  • Thanks, phd. I'll try to figure out how to get -py3 to the swig command (I don't give it explicitly; distutils figures it out from a source being ".i"). Commented Apr 28, 2021 at 14:59
  • Thank you, Jens. I thought I was running setup.py with Python 3, because I have an alias of "python" -> "python3", but that wasn't respected by the calling (Python 3) script. Explicitly asking for python3 in the calling script fixed everything. Commented Apr 28, 2021 at 15:08

1 Answer 1

1

As Jens pointed out, though I thought I was calling setup.py with Python 3, I was actually using Python 2. Fixing that to Python 3 solved my problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.