I created an application in Python 3.6 with a GUI built in PyQt5. Some modules are only available for Python 3.5 and 3.6.
I managed to pack it on Mac using py2app. I am trying to do the same thing on Windows. I tried to use this guide, but I still have issues.
For what I understand I have 3 options:
py2exe
pyinstaller
cx_Freeze
1) py2exe
According to here py2exe is still not available for python3.6, I need to use python3.5 then.
Using 3.5, I get this error and the compilation stops:
error: [Errno 2] No such file or directory: 'C:\\Users\\carlo\\AppData\\Roaming\\Python\\Python35\\site-packages\\py2exe\\run-py3.5-win32.exe'
2) pyinstaller
Running pyinstaller through Python3.5 as:
pyinstaller --onefile APP.py
I get just a bunch of warnings (lib not found) but the compilation gets to the end. The created EXE, though, opens the command prompt and pops up the following error:
Traceback (most recent call last):
File "site-packages\PyInstaller\loader\rthooks\pyi_rth_qt5plugins.py", line 46, in <module>
File "c:\program files (x86)\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 573, in load_module
module = loader.load_module(fullname)
ImportError: DLL load failed: %1 is not a valid Win32 application.
Failed to execute script pyi_rth_qt5plugins
3) cx_Freeze
Using python3.5, it first give the 'TCL_LIBRARY' error. Following the instructions here the compilation goes smoothly. The created application, however, opens up and closes immediately. It simply doesn't work.
Using python3.6, the compilation seems okay. When I try to open the application, this error pops up. I just managed to take a quick screen-shot:
Does anybody have any suggestion? Any alternative I am not considering?
I managed to solve the problem!
I followed the instructions here.
I first ran (with Python3.5):
pyinstaller CodeName.py
Then I modified the .spec file as indicated in the link and the magic happened!
Related
I want to transform a Python script to an .exe to share it with friends. I've tried with auto-py-to-exe, but here is what I get when I open it:
Traceback (most recent call last):
File "main.py", line 1, in <module>
ModuleNotFoundError: No module named 'pygame'
I saw somewhere that I had to indicate in auto-py-to-exe's interface the module name here:
But I still get the same error.
I have experienced this before where I export .py into .exe with --onedir setup. Here are the solutions that I might suggest (and works for me)
1. Export as --onefile
auto-py-to-exe screenshot
Exporting using --onefile creates only a single .exe file instead of having a folder contain hundreds of other supporting files (is that term exist? IDK). but the drawback is the file will be painstakingly slow to load up.
but if you export it as --onefile but still doesn't work,
2. Ensure the pygame is in the same directory as your .exe file
Apparently your .exe app is looking for the pygame module but failed. Try putting it in the same directory as your source code
There are multiple ways to convert a python file(.py) to an executable(.exe) -:
cx_Freeze
pyinstaller
auto-py-to-exe
Also, as mentioned in the comments by #Nanthakumar JJ and by #Amar Haiqal in his answer, make sure the --onefile option is checked while using auto-py-to-exe for conversion. Further, pygame module has to be present within the directory of the main file that is being compiled, as it will look for pygame and raise a ModuleNotFoundError, if the module is not found, being an .exe it will not look for the module on PYTHONPATH.
I have developed a simple software in python with GUI. I'm actually working on Natural Language Processing and I've just put the whole NLP process in a GUI.
I tried to convert the whole project to a exe file in python using Pyinstaller. I successfully converted it to an exe file but when I run it , it shows an error message something like this
This is the image of my error
I have already solved it but by using another way of converting py to exe which is the cx_Freeze.
I had the same issue earlier today and finally got it to work using the following software versions:
Python 3.6.8, nltk 3.5 and a dev version of pyinstaller:
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
Additionally, I used scikit-learn version 0.21.1.
Few days back, I had the same problem while compressing to EXE. This Problem generally occurs when PyInstaller failes to find Libraries and Modules to import to the directory. But I overcame this problem and the wise solution yet tedious method to do is mentioned below,
Convert Python Scripts to EXE with console = True in the .spec file or to be simple, do not add --noconsole argument while converting using System Argmuents method.(execute GUI with CMD)
After successfully building the file, go to respective directory (dist folder) and open command prompt
Run the Exe file using Command Prompt.
Find the error message and rectify it correspondingly. For example, consider the following Error Message, vcomp140.dll is missing from \\sklearn\\libs directory.
At the end of this Error Message, you'll find Failed to load dynlib/dll , Therefore, find the file or program which is missing. Say, Here we've .libs\\vcomp140.dll
Find vcomp140.dll using window search bar in your C Drive.
Copy the specific file and paste in the directory(under "dist" folder) where the file is missing. Here, the directory is dist\\PyScriptToEXE\\sklearn\\.libs
MatplotlibDeprecationWarning:
The MATPLOTLIBDATA environment variable was deprecated in Matplotlib 3.1 and will be removed in 3.3.
exec(bytecode, module.__dict__)
Traceback (most recent call last):
...
...
...
py3.7.egg\PyInstaller\loader\pyiboot01_bootstrap.py", line 169, in __init__
__main__.PyInstallerImportError: Failed to load dynlib/dll 'C:\\Users\\MOHAMM~1\\AppData\\Local\\Temp\\_MEI38242\\sklearn\\.libs\\vcomp140.dll'. Most probably this dynlib/dll was not found when the application was frozen.
[13968] Failed to execute script try
Follow the steps again using CMD to eliminate each error.
I blocked since some hours and i do not know how can i work around.
-I made a python script using jenkinsapi, this is working correctly.
-I´m trying to make a .exe file with py2exe, so I added jenkinsapi in the "includes" as I do usually, it compile correctly.
But when I run the .exe file, I got this error :
import jenkinsapi
File "jenkinsapi__init__.pyc", line 69, in
KeyError: 'jenkinsapi'
Impossible to find the problem, it seems that py2exe didn´t created the .pyd file of jenkinsapi.
Do someone had the same issue and can help me
I just finished creating a python program in 2.7 and I converted it to a .exe with py2exe.
Everything works fine when I run the converted executable file in the folder I placed it in with all of the images in it. After converting the python program to .exe, I proceeded to creating a setup file for it. I added all of the files associated with my project including tkinter in the setup file. I added pretty much everything that let me run the executable.
Once I finished creating the setup file, I opened it. I went through everything and finished installing it on my system and created a shortcut on my Desktop. When I tried to open it, it would not work. Instead of running the program, it tells me to open a log file in its folder in the Program Files. When I open the log file, I noticed an error. How do I fix this?
Error:
Traceback (most recent call last):
File "gui.py", line 10, in <module>
File "Tkinter.pyc", line 1764, in __init__
_tkinter.TclError: Can't find a usable init.tcl in the following directories:
{C:/Program Files (x86)/lib/tcl8.5} {C:/Program Files (x86)/lib/tcl8.5} C:/lib/tcl8.5 {C:/Program Files (x86)/library} C:/library C:/tcl8.5.15/library C:/tcl8.5.15/library
This probably means that Tcl wasn't installed properly.
I found a bug on the virutalenv site which suggested the following https://github.com/pypa/virtualenv/issues/93
I imagine that you are encountering the same issue just without virtualenv
the following set the correct paths which can then be included in the application please find the right path to TCL and TK for your python version
set "TCL_LIBRARY=C:\Python27\tcl\tcl8.5"
set "TK_LIBRARY=C:\Python27\tcl\tk8.5"
restart your cmd or shell
I believe that the TCL location have changed from there default ones.
I created notepad.ui the file in Qt4 Designer and tried to create the notepadwindow.py file by means of a command
pyuic4.bat notepad.ui -o notepadwindow.py
As a result I got the following error
Traceback (most recent call):
File "C:\Python27\Lib\site-packages\PyQt4\uic\pyuic.py" line 31, in <module>
from PyQt4 import QtCore
Import Error: DLL load failed: %1 then something strange on a different encoding Win32.
This is how I do it:
pyuic4 -x name.ui -o name.py
of course, in cmd go to the directory where your notepad.ui file is. Good luck.
Some installation issue i guess
pyuic4 notepad.ui > notepad.py
this works for me
I experienced with the same error and was able to solve it.
Although I work on a 64-bit Windows, my python shell (2.7.11) and all extension packages are 32-bit and they work well. I faced with many errors because my PyQt4 that i downloaded was 64-bit. When i remove it and install 32-bit PyQt4 the problem is gone and now i am able to convert .ui files to .py
Maybe your problem is the same with me or visa versa, but the versions of both idle and PyQt should match, either 32 or 64-bit.
open cmd and go to the directory where the ui file is being saved and there you write the following command.
pyuic4 -w notepad.ui > notepadwindow.py
I had the same problem with PyQt5 64-bit edition. Removed and replaced with 32-bit edition, then entered at the command prompt: pyuic5 -x "input.ui" -o "output.py"
Ran great.
I think there are at least two possible error conditions
1.ImportError: DLL load failed: The specified module could not be found.
then you have to check your PyQT version is comptible with your python.
In other words, if you use python 3.3, then you can only use PyQT for python3.3
and python 3.3 will not work with PyQT for python3.4
This was the problem I met. I solved it with re-install it
2. Import Error: DLL load failed: %1 then something strange on a different encoding Win32.
then it would be a OS problem. If you use 32bit Python then you have to use 32bit PyQt, so do 64bit
This is what i usually do when converting:
move to .ui file location with : cd /d D:\yourdirectory
YourPyuicLocation -x inputname.ui -o outputname.py
example :
C:\Users\ceppy\AppData\Local\Programs\Python\Python35\Lib\site-packages\PyQt5\pyuic5.bat -x Test.ui -o Test.py
use same version of python and PyQt .It worked out for me in solving error
ImportError: DLL load failed: The specified module could not be found.
For me, it had something to do with the path, maybe it was too long. I copied the .ui file to another folder and ran the command and it worked.