I'm trying to generate an executable from Linux for Windows using pyinstaller.
pyinstaller --onefile --windowed montecarlo.py
I run this command and get a single executable that works on Linux just fine, but if I try on Windows, it's just a simple file. Why?
I was trying to do this same thing today and ran across this answer. It pointed to the FAQ, which says cross-compiling is not supported. It recommends using Wine.
Related
I programmed a small application and compiled it using pyinstaller. However I can't run my compiled .exe. It shows this error:
Does anyone know how to fix it and create a working .exe?
pyinstaller --noconfirm --onedir --windowed --icon " "
I had the exact same problem. For me it turned out to be a bug related to pyinstaller 4.7 and python 3.9.8. I uninstalled python 3.9.8 and installed 3.9.5 instead and it worked perfectly with pyinstaller -w, my exe file runs without a console window now, and without any errors.
This happens because of --windowed argument in Windows. Without it it compiles and works ok, but you need to keep the Command Prompt window open too. Still trying to find a work-around.
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 developing a GUI app in Python, the code works fine in PyCharm IDE. Now I want to convert into an exe for distribution.
My code works fine until I generate a single file exe with PyInstaller with -w option enable (command: pyinstaller -F -w ). If I omit -w option, the code works fine but the final exe shows unwanted console as well.
To find a solution, I searched and found this to be a suitable workaround:
Python Subprocess Popen with Pyinstaller
Therefore, I tried Recipe sub-process as described here:
https://github.com/pyinstaller/pyinstaller/wiki/Recipe-subprocess
However, this is not working for me and I still get the error where subprocess command fails.
Anybody been in this situation, please help.
I am using Python 3.5, PyInstaller version 3.2.1.
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
I have a Python script (that manipulates files on a shared drive). I would like to turn that script into a file (maybe .exe?) that perhaps can be double-clicked and run on a machine that doesn't have Python installed. Is that possible/easy to do?
You can try py2exe.
Tutorials can be found at http://www.py2exe.org/index.cgi/Tutorial
I use and recommend pyinstaller. If you need only one executable file, you need to install pyinstaller and call executable passing these arguments:
pyinstaller.exe your_script.py --onefile --windowed
This options can be used when you generate the executable file: https://pythonhosted.org/PyInstaller/usage.html#options
To install: http://www.pyinstaller.org/
Documentation: https://pythonhosted.org/PyInstaller/