question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Standalone includes hardcoded external modules meaning executable can't be shared

See original GitHub issue
  • Nuitka version, full Python version and Platform (Windows, OSX, Linux …)
$ python -m nuitka --version
0.6.5
Python: 3.7.4 (v3.7.4:e09359112e, Jul  8 2019, 14:54:52)
Executable: /Users/brendan/.local/share/virtualenvs/test/bin/python
OS: Darwin
Arch: x86_64

$ uname -a
Darwin 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64
  • How did you install Nuitka and Python (pip, anaconda, deb, rpm, from source, what is a virtualenv …), this is very important usually.

  • If possible please supply a Short, Self Contained, Correct, Example that demonstrates the issue i.e a small piece of code which reproduces the issue and can be run with out any other (or as few as possible) external dependencies.

$ cat main.py
import random

$ python -m nuitka --standalone main.py

$ ./main.dist/main

$ sudo mv /Library/Frameworks/Python.framework/Versions/3.7 /Library/Frameworks/Python.framework/Versions/3.6

$ ./main.dist/main
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "/tmp/example/main.dist/./hashlib.py", line 244, in <module>
  File "/tmp/example/main.dist/./hashlib.py", line 113, in __get_builtin_constructor
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
  File "/tmp/example/main.dist/./hashlib.py", line 244, in <module>
  File "/tmp/example/main.dist/./hashlib.py", line 113, in __get_builtin_constructor
ValueError: unsupported hash type sha1
ERROR:root:code for hash sha224 was not found.
Traceback (most recent call last):
  File "/tmp/example/main.dist/./hashlib.py", line 244, in <module>
  File "/tmp/example/main.dist/./hashlib.py", line 113, in __get_builtin_constructor
ValueError: unsupported hash type sha224
ERROR:root:code for hash sha256 was not found.
Traceback (most recent call last):
  File "/tmp/example/main.dist/./hashlib.py", line 244, in <module>
  File "/tmp/example/main.dist/./hashlib.py", line 113, in __get_builtin_constructor
ValueError: unsupported hash type sha256
ERROR:root:code for hash sha384 was not found.
Traceback (most recent call last):
  File "/tmp/example/main.dist/./hashlib.py", line 244, in <module>
  File "/tmp/example/main.dist/./hashlib.py", line 113, in __get_builtin_constructor
ValueError: unsupported hash type sha384
ERROR:root:code for hash sha512 was not found.
Traceback (most recent call last):
  File "/tmp/example/main.dist/./hashlib.py", line 244, in <module>
  File "/tmp/example/main.dist/./hashlib.py", line 113, in __get_builtin_constructor
ValueError: unsupported hash type sha512
Traceback (most recent call last):
  File "/tmp/example/main.dist/./main.py", line 1, in <module>
  File "/tmp/example/main.dist/./random.py", line 46, in <module>
ImportError: cannot import name 'sha512' from 'hashlib' (/tmp/example/main.dist/./hashlib.py)

$ otool -l main.dist/*.so | grep ' name' | sort | uniq
         name /Library/Frameworks/Python.framework/Versions/3.7/lib/libpanelw.5.dylib (offset 24)
         name /Library/Frameworks/Python.framework/Versions/3.7/lib/libssl.1.1.dylib (offset 24)
         name /Library/Frameworks/Python.framework/Versions/3.7/lib/libtcl8.6.dylib (offset 24)
         name /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (offset 24)
         name /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration (offset 24)
         name /usr/lib/libSystem.B.dylib (offset 24)
         name /usr/lib/libbz2.1.0.dylib (offset 24)
         name /usr/lib/libedit.3.dylib (offset 24)
         name /usr/lib/libz.1.dylib (offset 24)
         name @executable_path/libcrypto.1.1.dylib (offset 24)
         name @executable_path/libncursesw.5.dylib (offset 24)
         name @executable_path/libtk8.6.dylib (offset 24)

i have encountered this exact problem when building a standalone executable using Python 3.7.4 and distributing to someone who doesn’t have Python 3.7 installed. Clearly the /Library/Frameworks/Python.framework/Versions/3.7 path makes it non-portable and need replacing with @executable_path/... versions. I don’t know about the other hardcoded paths, are these reliably available on different mac versions?

In my actually application the following path is also in the above list:

         name /usr/lib/libffi.dylib (offset 24)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tiwatsukacommented, Nov 21, 2020

I encountered the same problem.

I’m using Python which is installed from Command Line Tools and the path of it is /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework. When building with standalone option, generated binary has LC_LOAD_DYLIB with @rpath/Python3.framework/Versions/3.8/Python3 but does not have LC_RPATH. Thus, it cannot be executed.

I finally solved this problem by inserting env.Append(LINKFLAGS=["-Wl,-rpath,/Library/Developer/CommandLineTools/Library/Frameworks"]) to nuitka/build/SingleExe.scons ( which is renamed to Backend.scons on develop branch ). Now I can get executable binary by building with standalone option. I don’t know whether this is general solution, the following snippet might help some people who are in trouble.

if "darwin" in sys.platform and "/Python3.framework" in python_prefix:
    rpath = python_prefix[:python_prefix.find("/Python3.framework")]
    env.Append(LINKFLAGS=["-Wl,-rpath,"+rpath])
0reactions
kayhayencommented, Nov 25, 2020

Unfortunately I have no access to macOS. Basically in nuitka.freezer.Standalone there is code specific to macOS that should resolve the rpaths and apparently it may not be general enough. There is no way I can do it right now, and therefore I need your PRs.

I believe @tiwatsuka you are encoutering a problem from using a non-standard Python, or the same issue, I don’t quite understand honestly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I import a module dynamically given the full path?
In this situation utils.py is in src/main/util/ import sys sys.path.append('./') import src.main.util.utils #or from src.main.util.utils import json_converter ...
Read more >
Behavior Quirks — python-build-standalone documentation
When readline and libedit are compiled, there is typically a hard-coded set of search locations for the terminfo database baked into the built...
Read more >
2. Writing the Setup Script — Python 3.11.1 documentation
The setup script is the centre of all activity in building, distributing, and installing modules using the Distutils. The main purpose of the...
Read more >
7. Package Description — Cabal 3.4.0.0 User's Guide
However having both a library and executables in a package does not work very ... In GHC 6.6 and later a program may...
Read more >
Can I call external executables from an Azure Function in an ...
Looking back at that code, it's all pretty straightforward, especially given that the executable can work with pipes, and the module exposes ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found