3

I'm having the trouble: "Could not link test program to Python."

I have versions 2.7+ installed in /Library/Frameworks/.

I've tried this solution, but because it was posted more than 6 years ago it doesn't consider SIP (System Integrity Protection), which makes it impossible for many users to change System/Library files. Additionally, in later versions of Python the PYTHONFRAMEWORKDIR to PYTHONFRAMEWORKINSTALLDIR in Python's make file has been fixed (but the problem persists).

I've tried:

  • ./configure PYTHON_LDFLAGS="-l2.7.13_1"
  • ./configure LDFLAGS="-L/usr/local/Cellar/python/2.7.13_1/lib"

…But no combination of LDFLAGS seem to work.

Here's the error:

Could not link test program to Python. Maybe the main Python library has been
  installed in some non-standard library path. If so, pass it to configure,
  via the LDFLAGS environment variable.
  Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
  ============================================================================
   ERROR!
   You probably have to install the development version of the Python package
   for your distribution.  The exact name of this package varies among them.
  ============================================================================ 

And here's the log description:

PKG_CONFIG=''
PYTHON='/Library/Frameworks/Python.framework/Versions/2.7/bin/python'
PYTHON_CPPFLAGS='-I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7'
PYTHON_EXEC_PREFIX='${exec_prefix}'
PYTHON_EXTRA_LDFLAGS='-u _PyMac_Error Python.framework/Versions/2.7/Python'
PYTHON_EXTRA_LIBS='-ldl  -framework CoreFoundation '
PYTHON_LDFLAGS='-L/Library/Frameworks/Python.framework/Versions/2.7/lib -lpython2.7'
PYTHON_PLATFORM='darwin'
PYTHON_PREFIX='${prefix}'
PYTHON_SITE_PKG='/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages'
PYTHON_VERSION='2.7'

How can I just rip Python out of my system? Is that necessary? Or is there a fix to this error?

yeeeeee
  • 163
  • 3
  • 16

2 Answers2

2

Had the same bit of error output on my machine and for me it helped to install python-dev, so

sudo apt-get install python-dev

did it for me.

InsOp
  • 2,425
  • 3
  • 27
  • 42
1

I had a similar issue. The solution on ubuntu 22.04 was to install python-is-python3:

apt install python-is-python3
Farzad A
  • 21
  • 3