I have been working on a python GUI based project using PyQt5. I am done with that and it runs perfectly on my PC but I want to make an executable out of it. So, i'm using cx_freeze to convert my python file to an executable. I have python version 3.5 and PyQt5.
When I build the script the build folder is made and when I run the executable it get the missing modules error as shown in the image attached.
Kindly, help me out i am stuck on this for ages now.
Copy all the modules in the same directory as the file you are converting to exe, then try it again.
Related
I want to create a single executable from my Python project which uses tkinter. A user should be able to download and run it without needing Python installed. What can I use to build a self-contained executable from a Python project?
my question is somewhat similar to this one but I didn't find what I was looking for there.
I have a folder which looks like this:
-project/
-script.py
-res/
-image1.jpg
-image2.jpg
-image3.jpg
In my script.py I am using the images from the res folder in my tkinter UI and I want to create an executable out of this script. what would be the best way to tackle this problem?
You can try using PyInstaller
PyInstaller - How to convert to .exe
1. Installation
The pyinstaller module makes you able to create a standalone exe file for pc from a python script, so that you can use it on other computers than do not have python or your python version.
To install pyinstaller: pip install
2. Create an exe
After you installed pyinstaller, go in the folder where your python script to be transformed in exe is and type in the command line (go in the address bar on top of the window and type cmd). Then type :
pyinstaller yourscript.py
where your script is the name of your file.
You will find a folder called “dist” where there is a folder called yourscript (if the name of your script was this) where there are many files and the exe file that will allow you to run the script also on other computer. You just have to copy the whole folder.
3. What to do if there are images
If you use images, that are in the same folder, for example, you can copy manually into the folder made by pyinstaller or you can run this command to make it do it for you:
pyinstaller –add-data “*.png;.” yourscript.py
This way you will see that in the folder where your exe is there are also the png files (all of them, if you want just one do not put the asterisc, but the whole name of the file.
External links - PyInstaller
Use a bundler like Pyinstaller.
Pyinstaller website
Include images in Pyinstaller
Note: If you are having issues with tkinter and pyinstaller take a look at this: Problems with Pyinstaller with tkinter app on python 3.5
I'm trying to run pyinstaller in python exe file in order to someone without python can use pyinstaller but no idea how to do it.
I tried import PyInstaller with other needed modules and convert this script to exe but I got error "The 'PyInstaller' distribution was not found and is required by the application". I also tried to pack PyInstaller exe file but didn't worked too. Python 3.6.5
Any ideas how to do it?
Unfortunately, what you're describing is not possible with PyInstaller. I submitted an issue on GitHub, and this is what one of the developers said:
Nope, this won't work.
PyInstaller internally uses a lot of sub-processes where it is assumed that sys.executable points to a python interpreter (e.g., here); this is not true in a frozen application, where it points to the frozen executable, which ends up in effectively endless recursion.
Even if this was not a problem, the frozen application includes only a subset of python environment, so it cannot be used to freeze an arbitrary script (not to mention the issue of 3rd party packages).
So whatever use case you have for this, it cannot be supported by PyInstaller.
check the requirements for the Pyinstaller from this link initially
https://pythonhosted.org/PyInstaller/requirements.html
Then install Pyinstaller by,
pip install pyinstaller
To create .exe file use this command for basically,
pyinstaller your_script.py
To run the created .exe
METHOD 1
Do double click the .exe file in your directory.
METHOD 2
In your cmd prompt load in to your current directory or project directory then do
: .\dist\your_script.exe
because the create .exe files are saved in dist folder inside to the project folder with the name of your script file names only.
How do I convert the following files into one executable?
A main.py file that imports five other python scripts
Five python scripts that each have their own GUI
A background image is used in the main.py file
I am using Python 3.5.2. I have tried py2exe, cx_Freeze and pyinstaller but none seem to work, or I am doing something very wrong. Please could you help with clear steps.
It seems I have to downgrade to Python 3.4 in order to convert successfully but I don't really want to downgrade.
I am using tkinter for GUI and the Python math module for rounding-off numbers.
I've had some success with pyinstaller and a program using enaml (Qt backend) for the GUI.
For pyinstaller it helps to use the --debug option or make a .spec file and set debug=True. Also, pyinstaller has the option to make a single folder with an exe in the folder instead of a single exe, this might be easier to debug. You can distribute your single-folder programme by making a single-exe installer with software like InnoSetup.
is there any surefire way to convert a Python (3.5.2) File into an exe? I have seen Pyinstaller, py2exe and cx_Freeze. cx_Freeze does not have a Python 3.5 version, only 3.4 so it isnt compatible. Py2exe works only for Python 2 and while I had some success with Pyinstaller, it returned an error relating to 9130 WARNING: hidden import "pygame._view" not found! (the only one as I can see).
The exe. file was created but malfunctioned and stopped working.
Any advice?
I used py2exe to convert python 3 files to exe files. I haven't tested with version 3.5 but this website says that this version of py2exe works with any python 3 versions.
Download and install py2exe
Navigate to your python folder.
Create new text file called setup.
Insert these commands:
from distutils.core import setup
import py2exe
setup(console=['nameofyourpyfile.py'])
Close the text file and open cmd.
Navigate to your python folder using command cd.
Enter this command: python setup.txt py2exe
Press enter and your done navigate to folder called dist and find your exe file.
If it doesn't work install program called pywin32 and try again. If pywin32 doesn't help then let me know I will help you for sure :D
I am trying to run a python file that I create as an executable or .exe in windows. I want to run this code in another computer that does not have nor need python, or pyserial or PIL or any other software, My code creates a Gui that do stuff
I am using a method to do this but it is not working
first I create a new python file, called setup.py, inside I put this code
from distutils.core import setup
import py2exe
setup(console=['mycode.py'])
and mycode.py is where my code creates a GUI that do stuff
of course I have downloaded the py2exe application by typing in the command prompt
pip install py2exe
then in the command prompt I change the directory where my setup.py and mycode.py are and run this line
python setup.py py2exe
and effectively it do creates 2 folders, one with pycache (with one archive mycode.cpython-34.pyc) and another one with a lot of archives and mycode.exe
then I take these to folders from my computer to another computer where python, pyserial, PIL are not installed, and I try to run mycode.exe and it's not working. Could someone explain why?
I have found the problem, there is no problem with py2exe but with mycode
in mycode I use some images from my computer so when I create the .exe it takes those images from the directory in my computer and runs
but when I take the .exe from my computer to another computer to run it, I do not take those images and therefore the .exe does not run
now the problem is how to call these images, which is another question