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.

How do I import modules from a SO file generated by nuitka?

See original GitHub issue

I am interested in “Use Case 3”. I am very new to nuitka’s concepts, bare with me.

I am trying to use nuitka to “obfuscate” some django sub packages (“apps”)

My question is, can I reuse the shared object file generated by nuitka in python?

I have the following (basic example):

/api
/api/urls.py

python3 -m nuitka --module api --include-package=api
python3
>>> import api  (works)
>>> from api import urls
ImportError: cannot import name 'urls'

I am also aware of the note in the documentation that says:

The recursion into the package directory needs to be provided manually, otherwise the package is empty.

However this is at odds with the --help command:

--include-package=PACKAGE
                        Include a whole package. Give as a Python namespace,
                        e.g. ``some_package.sub_package`` and Nuitka will then
                        find it and include it and all the modules found below
                        that disk location in the binary or extension module
                        it creates, and make it available for import by the
                        code.

Using --follow-import-to=api appears to make no difference

Perhaps I am going about this all wrong, or can be gently reguided.

Thank you for your work.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kayhayencommented, Feb 23, 2019

@Vigrond This might be a basic Python misunderstanding, but Python does not automatically import submodules.

import module
module.module_variable # works
module.sub_module # will not work

You have to actually trigger the import for this to work. Only an import module.sub_module or with Python3 I think, from module import sub_module will work.

If I am getting something wrong, please try and make the minimal reproducer that illustrates what is working with standard Python and not with compiled code.

0reactions
kayhayencommented, Jul 14, 2019

Lack of feedback.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do you use nuitka shared object files? - Stack Overflow
If you used --module you should probably just do: import some_package. Another approach to use ctypes: import ctypes my_package ...
Read more >
User Manual - Nuitka
No information is available for this page.
Read more >
Intro to Nuitka: A better way to compile and distribute Python
Compile a Python program with Nuitka​​ By default, Nuitka only compiles the module you specify. If your module has imports—whether from elsewhere ...
Read more >
Ubuntu Manpage: nuitka - the Python compiler
This allows you to transfer the created binary to other machines without it using ... Do not create a ".pyi" file for extension...
Read more >
nuitka — Debian unstable
Select what value "__file__" is going to be. With "runtime" (default for standalone binary mode and module mode), the created binaries and modules,...
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