Nuitka: Nuitka doesn't handle using Python from compiled source checkout and cannot tell the location of Python.h

Hello,

I am working on porting an application to macOS and for some reasons I had to build my own Python version (from a release tag of the official CPython Git repository). When I tried to compile my app, I had the following error:

Nuitka:INFO: Running C compilation via Scons.
Nuitka-Scons:INFO: Backend C compiler: clang (clang 15.0.0).
FATAL: Error, no 'Python.h' development headers can be found at '['/usr/local/include/python3.11', '/usr/local/develop/headers/python3.11']', dependency not satisfied!

I was able to fix my issue and to successfully build my app by editing the nuitka/build/Backends.scons file to add the path of the Include/ folder of my compiled CPython.

  • Is it possible/worthwhile to add a way to tel Nuitka where the Python.h file is located?
  • What is the best way to achieve this? (CLI option? dedicated env var? parsing “common” env vars like CPATH/CCPATH/CFLAGS/…?)

I can work on a PR to implement whatever solution you think is the best to achieve this (if you think this feature is valuable for Nuitka).

Nuitka / OS version

1.9.4
Commercial: None
Python: 3.11.7 (tags/v3.11.7:fa7a6f2303, Dec 14 2023, 15:44:57) [Clang 15.0.0 (clang-1500.1.0.2.5)]
Flavor: Unknown
Executable: /Users/fabien/myproject/build/__env__/bin/python
OS: Darwin
Arch: arm64
Version C compiler: /usr/bin/clang (clang 15.0.0).

Steps to reproduce

I first installed XCode, HomeBrew and the following packages with brew:

brew install pkg-config openssl@3.0 xz gdbm tcl-tk

Then I built Python:

PATH="/opt/homebrew/bin/:$PATH"

cd ~/myproject/
mkdir -p build/

git clone https://github.com/python/cpython.git build/cpython.git
cd build/cpython.git
git checkout v3.11.7

GDBM_CFLAGS="-I$(brew --prefix gdbm)/include"
GDBM_LIBS="-L$(brew --prefix gdbm)/lib -lgdbm"
./configure \
    --with-openssl="$(brew --prefix openssl@3.0)"
make -j4

cd -

Then I made a virtualenv and installed Nuitka (and dependencies for my app):

build/cpython.git/python.exe -m venv build/__env__/
source build/__env__/bin/activate
pip install nuitka==1.9.4
pip install -e .

And finally I built my app:

export CPPFLAGS="-I$PWD/build/cpython.git/Include -I$PWD/build/cpython.git"
export LDFLAGS="-L$PWD/build/cpython.git"
python -m nuitka \
    --follow-imports \
    --include-package=PIL \
    --include-package-data=myapp \
    --enable-plugin=tk-inter \
    --tcl-library-dir="$(brew --prefix tcl-tk)" \
    --tk-library-dir="$(brew --prefix tcl-tk)" \
    --standalone \
    --onefile \
    --macos-create-app-bundle \
    --macos-signed-app-name=fr.foo.bar.myapp \
    --macos-app-name=MyAPP \
    --macos-app-version="$(python setup.py --version)" \
    --jobs=4 \
    --disable-cache=all \
    macbuild/myapp-darwin.py

EDIT: I edited the Nuitka/OS version… I ran the command from the wrong venv the first time ^^’

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Comments: 18 (18 by maintainers)

Most upvoted comments

This is part of the stable release 2.0 that I just made.

It seems I am not going to Windows yet, at least not until I need it, so I consider this done now.

Thanks a lot for working on this, very helpful indeed.