I converted my gui.py to gui.exe with py2exe, but it works only on windows 8 64 bit, when I tried it on win7 32 bit , it won't work
this code that converted .py to .exe
from distutils.core import setup
import py2exe
setup(console=['gui.py'])
any way to convert .py to .exe that works on all windows operating systems ...?
You're building a 64-bit .exe, which won't work on 32-bit Windows. Install a 32-bit copy of Python and use that to make the package - it will be 32-bit then.
You can use something called pyinstaller. Install it using pip install PyInstaller. To use it follow these steps.
In command line do pyinstaller your_file.py
In file explorer go to your your folder where the python file was created. In that folder you will see a folder called dist. In that folder there will be a executable file which is your_file.exe or your_file without extension.
This works for both 64-bit and 32-bit!
Related
My platform is Windows 10 and Python 3.9. There is another computer(Windows server 2008R2) without Python. So I'd like to use pyinstaller in my computer and use .exe on the other computer.
I tried simple script print("hello") and used pyinstaller -F myscript.py
.exe works on my computer, but failed on the other computer.
Error
error loading python dll ~ python39.dll
Should I use Python 3.8? Or what should I do?
The problem is that Pyinstaller does not create fully standalone executables, it creates dependencies (E.g. this python39.dll), so this python39.dll should be on the computer which is running this executable. Because python is already installed on your computer, python39.dll is already there and everything works fine. The problem is that machine that you're running this program on probably won't have it.
To fix this there are several solutions:
Install python 3.9 on targets' machine (But in this case you don't need to create an executable)
Include python39.dll with your program
For second solution just create a folder and move your executable into it as well as this python39.dll library. Windows will find it because it's in the same directory where this executable is. You can get this library from c:\Windows\System32 folder (Or where all DLL's are stored on your system) and then just copy it into folder with your executable. After that ship not just executable but this folder with library included.
#Stepan wrote in comments that you can also include this library right in your executable by adding --add-binary "path\to\python39.dll" to your command when compiling. The final command will look like this:
pyinstaller -F --add-binary "c:\Windows\System32\python39.dll" myscript.py
Check if the Python version is compatible with the windows version you are trying to use. I was having this problem with an exe I did using Python 3.10. Did it again with Python 3.7 and it worked.
In such cases it could be a solution to use something like auto-py-to-exe wrap for pyistaller: it knows better which option to set for py converting :)
Also, from my exp, in some cases you should modify yout already normally working from terminal Py code before pyinstaller: for example replace exit() with sys.exit() and so on.
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 made a python file and converted it to executable file with pyinstaller in Ubuntu, now I want to run the same executable file in windows, how would I do that?
Oups... Programs exists in different formats, normally text (.py for Python), byte code (.pyc) for Python and native executable formats. Text is normally portable across any architecture except for possible charset conversions. Byte code is normally portable, I am sure for Java, less for Python because I have never used it. But native executable formats (true executable in Linux or .exe files on Windows) are dedicated to one single architecture.
So a program generated by pyinstaller on Ubuntu can only be used on a Linux system with same system libraries as yours (read Ubuntu same version, even if it should also run on some other Linux flavours), but definitely not on Windows.
You have to install pyinstaller on windows, and run pyinstaller on windows (From the OS that you want to build your exe file)
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
So far I have used cx_freeze to convert .py file to .exe file, but I get many files. Is there a way to get it all into one executable?
I have seen that PyInstallerGUI is able to that, but it is for Python 2.7. Can it be done with Python 3.4 as well?
PyInstaller works up to Python 3.5. Once you've installed it (type in your terminal pip install pyinstaller), you can do in your terminal:
pyinstaller --onefile script.py
where script.py is the name of script you want to compile into .exe
With the --onefile option it will create only one .exe file.
I haven't tried it but, PyInstaller says here it can do that and it supports Python 2.7 and Python 3.3+.
Quoting from the linked page:
PyInstaller can bundle your script and all its dependencies into a
single executable named myscript (myscript.exe in Windows).
The advantage is that your users get something they understand, a
single executable to launch. A disadvantage is that any related files
such as a README must be distributed separately. Also, the single
executable is a little slower to start up than the one-folder bundle.
Before you attempt to bundle to one file, make sure your app works
correctly when bundled to one folder. It is is much easier to diagnose
problems in one-folder mode.
I found this in the PyInstaller documentation:
pyinstaller --onefile your-python-file.py
To find more: PyInstaller documentation