Executable made with pyinstaller doesn't work - python-3.x

I've tried to create an executable of my python script with pyinstaller, but it's not working.
If I run the exe file from terminal, I get these errors:
Traceback (most recent call last):
File "main.py", line 127, in <module>
File "main.py", line 9, in main
File "c:\users\danie\onedrive - universitat de valencia\escritorio\professors banda\profs\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "docx2pdf\__init__.py", line 13, in <module>
File "importlib\metadata.py", line 531, in version
File "importlib\metadata.py", line 504, in distribution
File "importlib\metadata.py", line 177, in from_name
importlib.metadata.PackageNotFoundError: docx2pdf
[13776] Failed to execute script main
I installed pyinstaller using pip inside the virtual environment of the project.
I would appreciate any help.
Thank you in advance.

Seems you have missing modules, that weren't found by PyInstaller analysis hooks.
Try to rebuild your application with --hidden-import=docx2pdf option.

Related

ImportError during executing exe file generated with pyinstaller on another pcs

So, basically I've created .exe file from py code by using pyInstaller, and it works perfectly fine on my machine.
But when I try to execute it at another pc, it raises ImportError like that
Traceback (most recent call last):
File "opty.py", line 10, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "paramiko\__init__.py", line 22, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "paramiko\transport.py", line 129, in <module>
File "paramiko\transport.py", line 190, in Transport
File "paramiko\kex_curve25519.py", line 30, in is_available
File "cryptography\hazmat\primitives\asymmetric\x25519.py", line 39, in generate
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "cryptography\hazmat\backends\openssl\__init__.py", line 6, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "cryptography\hazmat\backends\openssl\backend.py", line 113, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "cryptography\hazmat\bindings\openssl\binding.py", line 14, in <module>
ImportError: DLL load failed while importing _openssl: The specified module could not be
found.
So, basically the way how I converted py file into exe file is
pyinstaller.exe --onefile --windowed --icon="required\icons.ico" opty.py --upx-
dir="D:\rabbani\app\upx-3.96-win64"
I've tried different variations like using onedirectory, auto-py-to-exe, manually adding _ssl.ddl to the generated dist folder.
p.s. I have windows 10, python 3.9, PyInstaller 5.1.

ModuleNotFoundError: No module named 'winreg' on Mac? (But winreg is a windows thing)

I am receiving the following error when I try to run a django shell. I am on a Mac though and everything that I can find says that this is associated with Windows and that winreg should be installed by default. Suggestions as to what I should be looking at?
Traceback (most recent call last):
File "/Users/j/code/myproject/core/manage.py", line 22, in <module>
main()
File "/Users/j/code/myproject/core/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 460, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/shell.py", line 127, in handle
exec(sys.stdin.read(), globals())
File "<string>", line 5, in <module>
ModuleNotFoundError: No module named 'winreg'
Between when I had a working env and the env producing the error I made a lot of changes to a script that I was working on including installing packages and adding modules.
When I tried to run the script I received the error above.
In the comments, Iain asked for the command I was running and then the contents of the script. Out of all the things I was looking at -- I ignored this, because was certain it was something I installed, not the file I was working on.
At the top of the file, I found this line in the imports:
from winreg import FlushKey
^^ My best guess is that this was accidentally added while I was quickly moving across the keyboard too quickly and I didn't noticed and pressed some sort of key combo that added it.
This is a first. 🫣

Spacy_DLL load failed while importing nn_parser

I am trying to download the french module for Spacy with the command python -m spacy download fr_core_news_md , but it get error:
Traceback (most recent call last):
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 184, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 143, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 110, in _get_module_details
__import__(pkg_name)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\spacy\__init__.py", line 12, in <module>
from . import pipeline
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\spacy\pipeline\__init__.py", line 4, in <module>
from .pipes import Tagger, DependencyParser, EntityRecognizer, EntityLinker
File "pipes.pyx", line 1, in init spacy.pipeline.pipes
ImportError: DLL load failed while importing nn_parser: The specified module could not be found.
How to fix it?
Python 3.8.2 (64 bit) on Windows 10*64
Thank you!
I managed to fix this error by installing Visual C++ redist on my Windows machine.
https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
I also managed to fix this by installing the MS VC redist package. If you use, chocolately: https://chocolatey.org/packages/vcredist140
choco install vcredist140

failing to build python script to .exe with correct conda environment

I've tried using pyinstaller, py2exe and auto-py-to-exe but keep having similar problems. First, py2exe seems to be abandoned, but pyinstaller and auto-py-to-exe correctly build an exe that can run, and run the beginning of my code, however when I try to load a pickled model using joblib dump/load I get the following error. This is the same error I get when I run the python script in the wrong environment.
How can I build from the correct conda environment?
**Traceback (most recent call last):
File "test.py", line 43, in <module>
File "test.py", line 24, in main
File "site-packages\joblib\numpy_pickle.py", line 598, in load
File "site-packages\joblib\numpy_pickle.py", line 526, in _unpickle
File "pickle.py", line 1088, in load
File "pickle.py", line 1376, in load_global
File "pickle.py", line 1426, in find_class
ModuleNotFoundError: No module named 'sklearn.mixture._gaussian_mixture'
[12708] Failed to execute script test**

cx_freeze doesn't work in my script

I freeze a script using cx_freeze (4.3.1) in python 3.4.
The script works perfectly running in IDLE. It uses tkinter, re, and reportlab to create a pdf form.
Then the following error occurrs when I run the exe.
PS C:\Python34\build\exe.win32-3.4> .\CREEPING_cx_freeze.exe
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "CREEPING_cx_freeze.py", line 6, in <module>
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2214, in _find_and_load
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2203, in _find_and_load_unlocked
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
AttributeError: 'module' object has no attribute '_fix_up_module'
It looks like everything is working. Everything is created in the build folder, but the compiled executable does not work.
I tried searching for a solution but did not find any. Could somebody help me with this?
I´m using win 8 64 bits
Wrong version installed.
pip installs 64 bits but it doesn,t work.
running the 32bits version...works

Resources