libimobiledevice / libplist

A library to handle Apple Property List format in binary or XML
https://libimobiledevice.org
GNU Lesser General Public License v2.1
535 stars 304 forks source link

PyThreadState_Get: no current thread and other issues with different Python installations on macOS #155

Closed dnicolson closed 2 years ago

dnicolson commented 4 years ago

When using the package manager pyenv, I have been unable to build the plist module linked to the correct version of Python. It is possible to build the module with Homebrew or the system Python installation but not without some changes.

Python 2.7.16 has been used below for all methods (Python 3 has other issues).

pyenv

Many combinations of LDFLAGS and other variables were tried unsuccessfully, the "Could not link test program to Python" error was not shown and the correct Python directories were found.

Build script ```bash #!/bin/bash PYTHON_VERSION=2.7.16 # Install Python brew install pyenv eval "$(pyenv init -)" pyenv install $PYTHON_VERSION pyenv global $PYTHON_VERSION # Install Cython pip install cython # Compile libplist git clone git@github.com:libimobiledevice/libplist.git && cd libplist ./autogen.sh make && make install # Test python -c 'import plist; print(dir(plist))' otool -L /usr/local/lib/python${PYTHON_VERSION%.*}/site-packages/plist.so # Cleanup # pip uninstall -y cython brew uninstall pyenv rm /usr/local/lib/python${PYTHON_VERSION%.*}/site-packages/plist* rm -rf ../libplist ```

Python error otool -L output:

Fatal Python error: PyThreadState_Get: no current thread
./python-pyenv.sh: line 29: 10120 Abort trap: 6           python -c 'import plist; print(dir(plist))'
/usr/local/lib/python2.7/site-packages/plist.so:
  /usr/local/lib/libplist.3.dylib (compatibility version 6.0.0, current version 6.0.0)
  /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)

Homebrew

This is the most straightforward process, although the unsupported python@2 formula must be used.

Build script ```bash #!/bin/bash PYTHON_VERSION=2.7.16_1 # Install Python brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/0fc3f51093fe10c570eb777b04c93d86640f9e80/Formula/python@2.rb # Install Cython pip install cython # Compile libplist git clone git@github.com:libimobiledevice/libplist.git && cd libplist ./autogen.sh make && make install # Test python -c 'import plist; print dir(plist)' otool -L /usr/local/lib/python${PYTHON_VERSION%.*}/site-packages/plist.so # Cleanup pip uninstall -y cython brew uninstall python@2.rb rm /usr/local/lib/python${PYTHON_VERSION%.*}/site-packages/plist* rm -rf ../libplist ```

otool -L output:

/usr/local/lib/python2.7/site-packages/plist.so:
  /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0)
  /usr/local/lib/libplist.3.dylib (compatibility version 6.0.0, current version 6.0.0)
  /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)

macOS Python

Unlike the Homebrew steps, the PYTHONPATH environment variable must be set.

Build script ```bash #!/bin/bash PYTHON_VERSION=2.7.16 if ! [ -x "$(command -v pip)" ]; then sudo easy_install pip fi # Install Cython pip install cython export PATH=$PATH:$HOME/Library/Python/${PYTHON_VERSION%.*}/bin # Compile libplist export PYTHONPATH=/usr/local/lib/python${PYTHON_VERSION%.*}/site-packages git clone git@github.com:libimobiledevice/libplist.git && cd libplist ./autogen.sh make && make install # Test python -c 'import plist; print dir(plist)' otool -L /usr/local/lib/python${PYTHON_VERSION%.*}/site-packages/plist.so # Cleanup pip uninstall -y cython rm /usr/local/lib/python${PYTHON_VERSION%.*}/site-packages/plist* rm -rf ../libplist ```

otool -L output:

/usr/local/lib/python2.7/site-packages/plist.so:
  /System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.16)
  /usr/local/lib/libplist.3.dylib (compatibility version 6.0.0, current version 6.0.0)
  /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)
dnicolson commented 2 years ago

Closing due to macOS no longer including Python and Homebrew no longer supporting Python 2.