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.

Package programs have relative import fails when compiled

See original GitHub issue

When I run create an executable with nuitka --standalone, the resulting executable gives errors about relative imports.

  • Nuitka version:
> python -m nuitka --version
0.6.18.4
Commercial: None
Python: 3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)]
Flavor: Unknown
Executable: C:\Users\Jonathan\AppData\Local\Programs\Python\Python39\python.exe
OS: Windows
Arch: x86_64
>nuitka --standalone MyApp
Nuitka-Options:INFO: Used command line options: --standalone MyApp
Nuitka:INFO: Starting Python compilation with Nuitka '0.6.18.4' on Python '3.9' commercial None.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'tkinter' added '_tkinter'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'socket' added '_socket'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'ctypes' added '_ctypes'.
Nuitka:INFO: Completed Python level compilation and optimization.
Nuitka:INFO: Generating source code for C backend compiler.
Nuitka:INFO: Running data composer tool for optimal constant value handling.
Nuitka:INFO: Running C compilation via Scons.
Nuitka-Scons:INFO: Backend C compiler: cl (cl).
Nuitka-Scons:INFO: Compiled 10 C files using clcache with 0 cache hits and 10 cache misses.
Nuitka-Plugins:INFO: data-files: Included data file 'lib2to3\Grammar3.9.9.final.0.pickle' due to package data for 'lib2to3.pgen2'.
Nuitka-Plugins:INFO: data-files: Included data file 'lib2to3\PatternGrammar3.9.9.final.0.pickle' due to package data for 'lib2to3.pgen2'.
Nuitka:INFO: Keeping build directory 'MyApp.build'.
Nuitka:INFO: Successfully created 'MyApp.dist\\MyApp.exe'.
  • Output of running the script via python -m MyApp (expected):
>python -m MyApp
testing modules
running module
running util.tools.Tool from within module
init Tool
testing util
init Tool
  • Output of running executable (unexpected):
>MyApp.dist\MyApp.exe
Traceback (most recent call last):
  File "Z:\2021-12-20\MyApp.dist\__main__.py", line 3, in <module>
ImportError: attempted relative import with no known parent package

This issue may be related to #493 or #869. I’m probably just doing something wrong, but @kayhayen suggested in Nuitka-chat/community that I submit an issue about this.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:22 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
kayhayencommented, Dec 21, 2021

I pushed to factory a change that makes this work. The only horror I have is how to explain this to people.

0reactions
kayhayencommented, Jan 9, 2022

I included it in 0.6.19 still, taking the risk of breakage.

Read more comments on GitHub >

github_iconTop Results From Across the Web

beyond top level package error in relative import
The relative import is relative to where the import happens - that's why the error message is as OP describes. The top-level package...
Read more >
attempted relative import with no known parent package - IQ-Inc
How to fix ImportError: attempted relative import with no known parent package. Learn why it happens and Python import best-practices.
Read more >
Python beyond top level package error in relative import
We're trying to import “printer” into our “app.program” file. This is an issue because “printer” itself is not in a package. Relative imports ......
Read more >
Absolute vs Relative Imports in Python
Relative imports make use of dot notation to specify location. A single dot means that the module or package referenced is in the...
Read more >
Why does Python 3 not allow relative imports? - Quora
Relative imports rely on the current package or module's location in the file system to determine the path of the imported module, which...
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