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
Related
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.
I have a Python project that I want to convert into an executable. I have installed Pyinstaller. I only know how to convert one single script into .exe, but I have multiple packages with multiple python scripts.
The command line I used with success is:
pyinstaller --noupx --onefile --add-data="cprofiles.ui;." cprofiles_lmfit.py
pyinstaller manages relatively well the multiple '.py' files that you import, no need to cite them. Under the 'add-data' option, you list the non-py files and in my example, the 'cprofiles_lmfit.py' file is the one containing the main.
But as indicated here need help to compile python with pyinstaller (and in few other posts), I am a beginner with pyinstaller. I was never able to use the 'theano' module and I did not optimize. I still have to test the suggestions in the answer.
Converting the main script into .exe should solve the problem, use -onefile to convert it to one exe and rest of the .py files should be included.
1) Open the command prompt
2) Install pyinstaller
Pip install pyinstaller
3) Test your python script first just to check python script should work with normal
.py extension. Saurabh is the name of python file
python saurabh.py
4) Convert the python into executable file
pyinstaller --onefile Saurabh.py
Notice we have passed “–onefile” as a argument which tell pyinstaller to create only one file
5) Go to directory and navigate to the dist folder.
Prerequisite : Install PyQt5 to avoid error.
pip install PyQt5
I have a pygame application which I would like to convert to .exe format.
Pygame2exe (https://pygame.org/wiki/Pygame2exe) works nicely EXCEPT I am unable to figure out how to do this conversion with a project that has more than one custom module.
For example:
python_project/
main.py
other.py
I need to compile both modules, and merging them is not an option.
I have been working at this problem for a few weeks, and have not found any solutions.
I know it is possible, because I had it working, and then formatted the only hard drive that had a copy of the code without realizing I had not made a backup.
EDIT
Thank you Michael.
I just had to make a small change to the setup.py file you provided to make it font compatible. Here is the full setup.py file
from distutils.core import setup
import py2exe
import os
origIsSystemDLL = py2exe.build_exe.isSystemDLL
def isSystemDLL(pathname):
if os.path.basename(pathname).lower() in ["sdl_ttf.dll"]:
return 0
return origIsSystemDLL(pathname)
py2exe.build_exe.isSystemDLL = isSystemDLL
setup(windows=['main.py'])
(taken from Pygame font not working after py2exe)
Thanks again.
if you are using python 3.3 or 3.4, you can use py2exe.
install through pip, pip install py2exe in cmd
note: if 'pip' is not recognized as an internal or external command, navigate to the directory in which python is installed,/scripts probably: C:\python34\scripts
make a setup script called setup.py,
with just the three lines of code
from distutils.core import setup
import py2exe
setup(windows=['filename.pyw'] #probably pyw in windows, will be name of main file
then open command prompt in the directory where the main file and setup.py are located, and type setup.py py2exe
DO NOT USE or filename.pyw in the setup script, use the name of the main module.
this will make a folder called dist, (you can safely get rid of '__pycache_') containing all the files your exe needs to run!
you will probably want to make an installer, I would recommend Inno Setup (http://www.jrsoftware.org/isinfo.php)
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.
Background: I have had success in the past installing and using Pyinstaller to transform my python projects into one-file executables. I don't think it is an issue with my source code or pyinstaller files.
Problem: I used a free, open-source library/module called easygui imported into my source code to build an application. The application works perfectly run natively or through the Python IDE. I am pretty sure the problem is that Pyinstaller is not finding the EasyGUI module to import (it automatically includes and compiles any libraries you import in the script).
Actions: My python folder is not in the C:\ drive, it is in the E:\ drive. I'm able to access the pyinstaller path in "E:\program files\python" but it is not reading the easygui library, I don't think. I installed pyinstaller and easygui using pip.
Reading a LOT of pyinstaller's documentation i tried to run it to include a paths dir like:
E:\Program Files Hard Disk\Python\Scripts>pyinstaller --paths
DIR "E:\Program Files Hard Disk\Python" --onefile "E:\Program Files\Python"
It does output the single executable in the build file but does not launch correctly. From what I can see in the console window the brief moment it's up, it looks like an easygui issue. Here is the result of attempting to launch the executable from the command-line:
Here is the compiling in the command window:
Please help