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.
Related
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/
I want to convert a ".py" file to ".exe" file and I have converted that using "auto-py-to-exe"
But the file is not working on the other PC, it shows the error like this
ModuleNotFoundError: No module named 'pygame'.
I used 'pygame' in the .py project and the other PC doesn't have 'pygame' installed.
I'd like to convert ".py" file to ".exe" file and I'd like to run on any PC independent of whether it has Python or the respective libraries installed or not. Is there any way to do that?
Thank You #Starbuck5
As #Starbuck5 mentioned in the comment.
These sorts of problems happen when people mix up python installations on their own computer. What’s happened is that the python installation with pygame is not the same installation as the one with PyInstaller. So when PyInstaller runs, it can’t find a pygame to package. –
Starbuck5
I have created a new virtual environment and installed libraries needed for my project and auto-py-to-exe in that virtual env. Then by using auto-py-to-exe, I converted my python file to .exe file and now it's working properly.
You can use any of these methods "auto-py-to-exe", "py2exe" or "pyinstaller", or any other method possible.
Just the libraries should be accessible by pyinstaller or another method you use.
The best way is to do this in a virtual environment.
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
My requirement is to deploy a python script in a form of exe with digital signature but the python interpreter and dependent python modules should not be embedded into the exe. Rather, python needs to be explicitly installed on the server.
I have tried pyinstaller and cx_freeze but both embeds python and related modules along with the script codebase into the exe. We need to decouple python and script codebase.
You can use py2exe and use Cython to convert your key .py files in .pyc, C compiled files, like .dll in Windows and .so on Linux.
Alternatively, you can use PyInstaller to package Python programs as standalone executables. It works on Windows, Linux, and Mac.
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