Creating an executable from a Pycharm Python Project - python

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

Related

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

Python Application Executable

How we can create an Installable Package of Large Python Project ? Is it advisable to convert the application as .EXE and install on Linux or Windows OS ? For example the .NET C# applications are being packaged as .MSI (Installable). In the same way how the Python Application can be deployed ?
You can create exe first and then create setup file with inno setup.
https://jrsoftware.org/isinfo.php
you can find download links and usage from this site
you can use pyinstaller for exe

Converting .py to .exe with Anaconda

I made a python program using PyGame which is only available for Python 2.7 so that is my python version.
I am using Anaconda because it is easier to install modules and to use python, but the site hasn't py2exe module for 2.7.
Is there another way to convert it? Or some way to install py2exe for 2.7 in Anaconda?
How to create an executable using Anaconda 3 (specifically Anaconda Prompt) for Windows.
1 - Make sure pyinstaller is installed in your anaconda
pip install pyinstaller
2 - Move to the directory of your python script
cd C:\Users....\program.py
3 - Just type the following:
pyinstaller --onefile program.py
If everything goes well, in the folder where you have your script.py you it will be created many folders and your executable is inside folder "dist".
If my explanation is confusing go here: https://medium.com/dreamcatcher-its-blog/making-an-stand-alone-executable-from-a-python-script-using-pyinstaller-d1df9170e263
Instead of using py2exe you could try to build your executable with pyinstaller.
http://www.pyinstaller.org/downloads.html
The PyGame package is also supported with pyinstaller according to this link
https://github.com/pyinstaller/pyinstaller/wiki/Supported-Packages
Another solution is Conda Constructor.
Constructor is a tool which allows constructing an installer for a collection of conda packages. It solves needed packages using user-provided specifications, and bundles those packages. It can currently create 3 kinds of installers, which are best thought of as delivery vehicles for the bundled packages. There are shell installers, MacOS .pkg installers, and Windows .exe installers. Each of these will create an environment on the end user's system that contains the specs you provided, along with any necessary dependencies. These installers are similar to the Anaconda and Miniconda installers, and indeed constructor is used to create those installers.

How can I use setuptools to create an exe launcher

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

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