Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch ctypes find_library function search path #2339

Closed
5 of 11 tasks
RemiDesgrange opened this issue Apr 25, 2022 · 4 comments
Closed
5 of 11 tasks

Patch ctypes find_library function search path #2339

RemiDesgrange opened this issue Apr 25, 2022 · 4 comments

Comments

@RemiDesgrange
Copy link

RemiDesgrange commented Apr 25, 2022

Too many issues will kill our team's development velocity, drastically.
Make sure you have checked all steps below.

Prerequisite

  • Make sure your problem is not listed in the common build problems.
  • Make sure no duplicated issue has already been reported in the pyenv issues. You should look for closed issues, too.
  • Make sure you are not asking us to help solving your specific issue.
    • GitHub issues is opened mainly for development purposes. If you want to ask someone to help solving your problem, go to some community site like Gitter, StackOverflow, etc.
  • Make sure your problem is not derived from packaging (e.g. Homebrew).
    • Please refer to the package documentation for the installation issues, etc.
  • Make sure your problem is not derived from plugins.
    • This repository is maintaining pyenv and the default python-build plugin only. Please refrain from reporting issues of other plugins here.

Description

  • Platform information (e.g. Ubuntu Linux 16.04): mac os 12.3.1
  • OS architecture (e.g. amd64): arm64 (m1)
  • pyenv version: 2.2.5
  • Python version: python 3.10.3
  • C Compiler information (e.g. gcc 7.3): clang 13.1.6
  • Please attach the debug trace of the failing command as a gist:
    • Run env PYENV_DEBUG=1 <faulty command> 2>&1 | tee trace.log and attach trace.log. E.g. if you have a problem with installing Python, run env PYENV_DEBUG=1 pyenv install -v <version> 2>&1 | tee trace.log (note the -v option to pyenv install).

On a mac m1, using homebrew to install C extension puts them in /opt/homebrew/lib. The source code of python is quite clear:
https://github.com/python/cpython/blob/main/Lib/ctypes/macholib/dyld.py#L29-L33 it searches trough a list of hardcoded path. Macport patches this file: https://github.com/macports/macports-ports/blob/master/lang/python310/files/patch-Lib-ctypes-macholib-dyld.py.diff in order for him to work.
normally we can set the DYLD_LIBRARY_PATH to override the path but SIP limit this possibility, example: FOO=BAR python -c "import os; print(os.environ['FOO'])" work as expected, while DYLD_LIBRARY_PATH=~/lol python -c "import os; os.environ['DYLD_LIBRARY_PATH']" raise an exception.

As a solution a configurable path when building python would have been nice, but I cannot found any (not an expert in python build though). Otherwise a patch like here: https://github.com/pyenv/pyenv/blob/master/plugins/python-build/share/python-build/patches/3.7.13/Python-3.7.13/0001-Port-ctypes-and-system-libffi-patches-for-arm64-macO.patch

@native-api
Copy link
Member

native-api commented Apr 25, 2022

On a mac m1, using homebrew to install C extension puts them in /opt/homebrew/lib

This is correct, as Homebrew installs extensions for the Homebrew-provided Python installation.

Pyenv makes its own, independent Python installations. You need to switch to that installation and use Pip to install extension modules.

I'm not sure when the code that you showed would fire, but it looks like something that would only be used in a Framework build of Python (with PYTHON_CONFIGURE_OPTS=--enable-framework) -- in which case, the build creates its own Library/Frameworks subtree.

@RemiDesgrange
Copy link
Author

Pyenv makes its own, independent Python installations. You need to switch to that installation and use Pip to install extension modules.

In this case I have no idea how to make this happen.

Step to reproduce:

brew install pango
pip install weasyprint
python -c "import weasyprint"

@github-actions
Copy link

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@jvpwfb
Copy link

jvpwfb commented Jan 8, 2023

Thanks for the detailed explanation. For anyone who finds their way here via a google search, one easy workaround that worked for me was to simply create a symbolic link from one of the unused locations in the ctypes search path to the homebrew library path. For example, /usr/local was empty on my machine so I simply did the following:
sudo ln -s /opt/homebrew/lib /usr/local/lib
The following also worked:
ln -s /opt/homebrew/lib ~/lib
Now ctypes can find the GDAL library that was tripping me up on using pyenv with django on my mac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants