(Open to suggestions for a more descriptive title)
I am trying to package my script using Pyinstaller and get the following when trying to run the exe:
File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
File "apryse_sdk\__init__.py", line 17, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
File "PDFNetPython3\__init__.py", line 17, in <module>
ModuleNotFoundError: No module named 'PDFNetPython'
The import in the main script that solicits this error looks like:
from apryse_sdk import *
where the associated __init__.py
contains the nested import:
...
from PDFNetPython import *
Notice that here PDFNetPython
is imported locally. See the file structure:
Directory: C:\Program Files\Anaconda2022\Lib\site-packages\apryse_sdk
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 9/11/2023 12:56 PM __pycache__
-a---- 9/7/2023 1:13 PM 45508632 PDFNetC.dll
-a---- 9/7/2023 1:13 PM 12 PDFNetPyLibInfo
-a---- 9/7/2023 1:13 PM 658347 PDFNetPython.py
-a---- 9/7/2023 1:13 PM 7536128 _PDFNetPython.pyd
-a---- 9/11/2023 1:33 PM 474 __init__.py
I keep seeing that the syntax for the --hidden-import
param is just --hidden-import=<Module>
but does this apply to local imports? It doesn't seem to me that it does. What is the workaround?
you have to try 2 solutions ....
1- it is updating your python version to the newest version of python ....
2-if it still appears you should take the library and put it next to your program and merge it with it , to be able to import it from the app files
what do i mean by the choice number 2 ?
i mean that you have to take the library for example this is its name the_library
and insert or merge it inside the final application that you have by adding this additional command
--add-data (the path of your library)
this operation will take the library and merge it with the application and make one file normally
also you can add files not only folder using the same command.
and you can auto-py-to-exe
library to make the merging and adding files or folders into your app more easy.
you can install it by this command
pip install auto-py-to-exe
after that turn itt on by calling the name only auto-py-to-exe
and you can choose your python file and the icon
after that you can choose the files or folders or libraries to add like this:
and choose your folder that you want to add by add folder
after that you can see the command below and this helper (auto-py-to-exe) made this operation easier.
Important to mention :
Not All The Time You Have To Add Your Libraries Like This .... We Do This When We Face A Problem In Adding It Using PyInstaller