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
Related
I have created a python application that I build into a Unix executable using Pyinstaller. The application runs fine until I attempt to code sign it. After code signing, I get the following error when attempting to run the executable:
rosetta error: /var/db/oah/526469a4f4887ee6ca553807c3196c9533da7ef706c684764b83169e8658f8e2/ba3f613b849de777b4a89fdb1760c3c2343ac52546e2629e28f83fbf530a8f27/libffi.8.dylib.aot: unable to mmap __TEXT: 1
Is it possible to code sign dylib files such as this?
Steps to reproduce the error:
Create conda environment with python v3.9
Activate environment and conda install numpy and pyinstaller
Create python script that imports numpy. Doesn't matter what the python script does, can just be one line as long as it imports numpy.
Use pyinstaller to build a distribution for the python file, with code signing like so:
pyinstaller -y --clean --codesign-identity='<apple-id>' --osx-entitlements-file='<path-to-entitlements.plist-file>' <name-of-python-script>
Run the Unix executable that is produced inside the dist folder.
I just finished working on a PyCharm project (using python 3.7), which uses libraries downloaded using PyCharm's built in functionality. I just want to send this project to my boss so that he can simply run it by clicking on it, without having to go through downloading PyCharm and downloading the applicable packages. Please tell me that there is a way to do this. Thank you
if you want to convert your python project to a program exucutable in windows you can use the library pyinstaller.
install the library:
pip install pyinstaller
then in the path of the project,open a command console and type the following commands.
if you want the executable in one file(slower start):
pyinstaller.exe --onefile --windowed --icon="your_icon_file".ico "your_python_script".py
if you want the executable in one folder(faster start):
pyinstaller.exe --onedir --windowed --icon="your_icon_file".ico "your_python_script".py
this wil create a folder call "dist" where your .exe will be,
pd: whith the --onedir command you will see all your dependencies in that folder, if you have a simple script you can use the first option.
Link to the pyinstaller documentation:https://pypi.org/project/pyinstaller/
You could solve this issue by converting the .py file to an executable file or .exe file....
Hopefully it helped..thx
A simple way to that would be sharing it on github with a requirements.txt file containing all the dependencies which then can be installed using python -m pip install -r requirements.txt.
Or You can use pyinstaller --onefile <yourfile.py> to create a .exe file which could be run without any requirements on windows.
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
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.
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.