User68325794
User68325794

Reputation: 21

Nuitka: Integration of PYDs into .py and .exe

I have an app that uses PySimpleGUI, Matplotlib and some others (I will refer to them jointly as the 'Modules').

(1) I would like to use better than everage protection (VMProtect is in the list with some others) for my executable (app.exe). To achieve this I use Nuitka to convert the my app.py code into C++ and mingw64 to compile it into an executable:

python -m nuitka --standalone --nofollow-imports --plugin-enable=tk-inter --plugin-enable=numpy --plugin-enable=pylint-warnings --mingw64 --output-dir=X: app.py

(2) Also, I want to convert the Modules (=Modules.py) into *.pyd files (=Modules.pyd). I also use Nuitka to conver Modules.py into Modules.pyd. For example:

python -m nuitka --module "c:\Program Files\Python\Lib\site-packages\PySimpleGUI\PySimpleGUI.py"

(3) app.exe shall refer to Modules.pyd which will be distributed together.

My problem is that when I am trying to refer to Modules.pyd in app.py code, which is:

import PySimpleGUI.pyd as sg # PySimpleGUI.pyd is located in the same folder as app.py

I receve the following error:

ModuleNotFoundError: No module named 'PySimpleGUI.pyd'; 'PySimpleGUI' is not a package

I was unable to find a solution to this problem.

In practical terms I would like to achieve one of the following:

(i) cause app.py (which also means app.exe) to recognise Modules.pyd (I already have the latter)

(ii) find some other way to receive app.exe (NB: ready for protection) and Modules.pyd through any other conversion / compilation process.

What I do NOT want to have is app.exe and dozens of Modules.py in the same directory.

Any advice on how to achieve either (i) or (ii) will be most appreciated.

P.S.: all software and modules are up-to-date, all PATHS are set.

UPDATE (2021-09-20):

After further reserach I was able to find what seems to be a [partial] solution -- adding the following lines above imports in app.py taught app.exe (after it was converted via Nuitka) to recognise the Modules.pyd:

import sys

sys.path.append("./DLL/") # where ./DLL/ is a sub-folder with Modules.pyd within the folder where app.exe is located.

However: now I cannot conver dateutil.relativedelta into a proper *.pyd because no such file exists.

This is turning to be a question of how to configure Nuitka to create *.pyd files from module.class.

If anyone has any solution to this, please resond.

Upvotes: 2

Views: 1493

Answers (1)

MatCat
MatCat

Reputation: 77

I can help with part, but not all of your questions: In (1), you use both --standalone and --nofollow-imports. These negate each other. You should only use one. If you use --standalone, the modules will be included automatically, you don't need to make them into pyd modules.

Upvotes: 1

Related Questions