How do I handle custom modules when creating an exe with PyInstaller? - python-3.x

Using PyInstaller I created a executable from a python script as follows:
pyinstaller --onefile pythonScriptName.py
However, when I run the executable I get an error ImportError: No module named 'MyModule'.
'MyModule' is a placeholder name for a custom module I use in the script. So I'm assuming that PyInstaller didn't package up the custom modules. Is there some way to get it to do that?

I found the --collect-submodules flag to be helpful when getting an import module error.
I just specify the folder name under which all my modules are and pyinstaller collects all the imports automatically.
something like this:
pyinstaller --collect-submodules <folder-name>

Related

ModuleNotFoundError: No module named '__main__.MetricsWindow'; '__main__' is not a package

what is this error please help me iam getting it in python & iam new ? iam using the open source code of simso simulator
ModuleNotFoundError: No module named 'main.MetricsWindow'; 'main' is not a package
This error: ModuleNotFoundError: No module named '__main__.MetricsWindow'; '__main__' is not a package may also occur if you have named the main program file you created as __main__.py and try to run it as python __main__.py or another file has the name __main__.py in the same folder from which you run your program. Python will consider your program file as a module and try to find something in it that is naturally not in it. About where Python is looking for modules, see sys.path.
In this case, rename your program file so that its name does not equal with the name of the imported module.

How to include files while compiling?

I am using pyinstaller to compile a python script to an exe, but before I do that I want to obfuscate it using pyarmor, I fired up pyarmor web ui using pyarmor-webui and created a build that gives out a file named the same one as the file I want to compile but obfuscated and a folder containing two files __init__.py and _pytransform.dll now when I try to compile the obfuscated code into an exe using pyinstaller --onefile myfile.py I get an executable that when I run from a batchfile to look at the output it throws the following error Could not find "C:\Users\0000\AppData\Local\Temp\_MEI72482\pytransform\platforms\windows\x86_64\_pytransform.dll"
myfile.py
import os
import random
for i in range (10):
print (random.randrange(1,100))
Batch file
try_01.exe
pause
How and what do I need to add to pyinstaller command so that it includes the .dll file in the compilation process
The pyinstaller docs say the following:
--add-binary <SRC;DEST or SRC:DEST>
Additional binary files to be added to the executable. See the --add-data option for more details. This option can be used multiple times.
I haven't used pyarmor+pyinstaller before but it should be as simple as:
pyinstaller --onefile myfile.py --add-binary _pytransform.dll
Or, since I looked more into pyarmor's output, it may be:
pyinstaller --onefile myfile.py _pytransform.dll

Error when run exe "ModuleNotFoundError: No module named 'babel.numbers" [duplicate]

I'm trying to install python application on Windows with pyinstaller where I'm using tkcalendar. Application is working but the tkcalendar.Calendar isn't.
When I'm running application without installation everything works but if I do this, Calendar widget does not appear.
I think that pyinstaller sees this module but he has problems with modules that tkcalendar is using.
I tried to run pyinstaller with --path=/.../python/Lib/site-packages but this didnt worked. Also copying module files to application directory didn't help.
The issue does not come from tkcalendar but from the fact that PyInstaller does not detect second level imports. A way to solve this issue is explained in tkcalendar's documentation in the HowTos section:
When bundling an application with PyInstaller, there is an
issue with the
detection of the babel dependency of tkcalendar. This can be fixed by
using the --hidden-import option:
$ pyinstaller --hidden-import babel.numbers myscript.py
or by editing the .spec file:
hiddenimports=["babel.numbers"]
Add following code to your python script, while bundling with pyinstaller
import babel.numbers
If anyone found the same problem.
In tkcalendar 1.5.0 there is problem with import in calendar.py.
Locate the tkcalendar folder (probably /.../python/Lib/site-packages/tkcalendar) and under calendar.py add an additional import for the missing module:
import calendar
from babel.dates import format_date, parse_date, get_day_names, get_month_names
from babel.numbers import * # Additional Import```

Creating .exe file from python package for windows10

I implemented one package with GUI based on Pyside2. This package has the following structure:
Repository
Function
GUI_class
Main_GUI.py
It means Main_GUI.py use some classes and function in GUI and Function folders. Now I want to create the executable version from it for windows 10. I tried Pyinstaller for this aim like the following comments:
(conda env)F:\Repository> Pyinstaller Main_GUI.py
But when I run the *.exe file in dist folder it gives me the following error:
ModuleNotFoundError: No module named 'pkg_resources.py2_warn'
Blockquote[15728] Failed to execute script pyi_rth_pkgre
Would you please help me how can I convert this python package to *.exe? Thank you in advance.
These are my version of my dependencies:
Python 3.6.10,
Pyinstaller 3.6,
Pyside2 5.13.2.

"ModuleNotFoundError: No module named 'zlib'” when I add python3 support with buildroot

When I build the linux image with buildroot, I have enable the python3 and python zlib in the config like below:
BR2_PACKAGE_OPENCV3=y
BR2_PACKAGE_OPENCV3_LIB_PYTHON=y
BR2_PACKAGE_OPENCV3_LIB_IMGCODECS=y
BR2_PACKAGE_OPENCV3_LIB_IMGPROC=y
BR2_PACKAGE_OPENCV3_WITH_JPEG=y
BR2_PACKAGE_PYTHON3_ZLIB=y
Build is ok, and I can enter into python3, but the error "ModuleNotFoundError: No module named 'zlib' always happened when I import some package.
anyone know how to rolve it.
thanks.

Resources