How can I use setuptools to create an exe launcher - python

I can install a python script as an exe file into "scripts" folder on windows.
How can I just create an exe launcher for a script without installing it?
Using 64-bit python, can I create an exe that will work with 32-bit python?

Instead of using setuptools, you can use py2exe to create your executable files.
Just read the tutorial page to understand how to create them.
Install it by typing in your terminal:
pip install py2exe
Create your .exe script (hello.py)
print "hello world!"
Create your setup config script (setup.py)
from distutils.core import setup
import py2exe
setup(console=['hello.py'])
Run your setup script by typing in your terminal
python setup.py py2exe
After that, 2 folders will be created inside the scripts folder.
They'll be called 'dist' and 'build' folder.
Inside the 'dist' folder you'll find an executable of your script.
In our example, we compiled the hello.py file, correct? So, inside the dist folder we should find a hello.exe file.
Q: Also, using 64-bit python, can I create an exe that will work with
32-bit python?
A: No! You'll have to install a 32-bit python and compile using the
32-bit version.
Hint: create a virtual machine to compile your 32-bit programs.
Also you can take a look at:
YT Tutorial
PythonCentral Tutorial
PythonTips Tutorial
StackOverflow Question

Related

How to create exe of project who has .cxx .py file and many dlls

I have a code who is depended on Qt, PyQt, VTK, ITK, libs.
using CMAKE to build
Environment : Windows
I want to distribute EXE who has cxx, py files and related dlls
I have tried to compile and got executable but my python files are remaining necked.
I don't want to share python files as a script.
how we can make those python files as a dlls
python is often a hard language to turn to exe but the best way to do so is using the pyinstaller package. Installed by pip install pyinstaller and can turn a .py file to a .exe by pyinstaller --onefile FILENAME.py in CMD. After that your exe file should be stored in a folder called disk. The other files can just be included in the same file as the exe.
docs: https://pyinstaller.org/en/stable/

Including External Python Packages with Python Executable

I have made my own Executable from a python script which I want to run on a computer that does not have Python installed on it. My only problem is there are packages I have included which are not default python packages (e.g. pynput). Otherwise, the Executable would run fine without Python installed. Is there a way to include Python packages with my executable? Can I put the packages in the same folder as the script and import them from there? If so, would I then be able to transport them along with my Executable? I have already googled a solution but I cannot find anything on it.
use following method :
pip install pyinstaller
pyinstaller is a package for generating executable files for python and can be ran from command line or terminal
in the same directory of your pyhton file run following command
pyinstaller --onefile nameofyourfile.py
after its done if you check your folder there should be a dist folder
inside that you can find an executable to your python file which has no dependencies to other packages

Creating an executable from a Pycharm Python Project

How can I take all scripts and files in my Python project directory and create a single executable. I have tried using this: How do I create an executable file out of a PyCharm project using PyInstaller? but it does not work. I have developed the project in PyCharm and I am using Python 3.4.
You can use cx_Freeze it's the same way that py2exe and py2app. It supports python 2.7 or highter or you can use Pyinstaller that binds in an executable all the stuff.
You can download it using the following command:
pip install pyinstaller
Or you can download it from the website

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.

Do I need Python installed if I have PYC files?

I want to add Python as a scripting language to my game. If instead of distributing PY script, I distribute the PYC compiled files with my game, will the user still need Python installed, or will the DLL be sufficient?
Not only would they still need the Python interpreter, but the compiled python byte-code files are not guaranteed to work across different platforms.
You do need an executable to actually load the files into the VM. Fortunately it doesn't need to be very complex.
pyinstaller can be used to convert the .py file into an executable file
to install the pyinstaller
pip install pyinstaller
and to convert the .py file let's say file.py
pyinstaller file.py
this will make two new folders in the same directory
build and dist. dist folder contains all the required dll and file.exe to run the python code without python installed.

Categories