Question about Python script compiled to .exe [duplicate] - python

This question already has answers here:
How can I make a Python script standalone executable to run without ANY dependency? [duplicate]
(19 answers)
Closed 3 years ago.
I have a Question about compiling a python script to Executable. So If I compile a C/C++ static executable I know that it will work on other systems without the need of installing some frameworks or stuff. I am really not sure if Python scripts compiled to executable work on other systems without Python installed. So, Is it good and safe to compile python scripts to executable? If I convert a python script to executable and run it on systems without python installed an Error pops up saying Failed to execute script emailmanager

Yes when you compile python using pyinstaller it creates a directory with the compiled executable and all the libraries it needs to run. Therefore you can distribute said directory and it should work on any system - even when python or used libraries are not installed

Related

How to compress python .exe file size [duplicate]

This question already has answers here:
Reducing size of pyinstaller exe
(5 answers)
Closed 11 months ago.
I have converted python file to exe using this
But the size of .exe is 800mb, is there any way I can reduce its size?
Using Pyinstaller
The --onefile flag with pyinstaller (e.g., pyinstaller myprogram.py --onefile or pyinstaller myprogram.py -F puts everything in just a single executable, including all the code of all your installed dependencies, even if you're using just one function from them. That's a lot!
The --onedir or -D flag instead puts the those dependencies in a directory that's packaged alongside your compiled code. It tends to reduce the size of the .exe file considerably.
But still, I wouldn't recommend using Pyinstaller. Having experimented with it extensively, I've found that execution time is incredibly slow on machines that don't already have a Python-friendly environment. (Most of the slow execution time comes from loading those dependencies.)
Using cx_Freeze
For the executables that I build for my department, I use cx_Freeze to build an installer or a disk image.
To do so, all you have to do is write a setup script and then call py setup.py bdist_msi (Windows) or py setup.py dbist_dmg (Linux).
The resulting installer will be relatively small and, once it's installed, it will execute much faster than any of the Pyinstaller options I've seen.

Running python script anywhere [duplicate]

This question already has answers here:
How can I distribute python programs?
(8 answers)
Closed 2 years ago.
I have developed some scripts which I need to share with colleagues who does not have python nor have underlying distributions to run it. How to automatically configure environment and more importantly run the script without even python installed?
I saw some solutions on SO like py2exe. Not sure that it’s the best option. Docker is also not possible since in my case I need something what can work simply by running python3 path/to/program
You can use online coding platforms like repl.it to run scripts from the browser so u don't want to install python locally.
Convert it into a exe file using pyinstaller
Following are the steps:
1. Open cmd on the folder in which you stored your py file
2.type it on the cmd
pyinstaller -- onefile filename.py
If you don't have pyinstaller module then install it using
pip install pyinstaller
It depends on the complexity of the script.
If it is doing complex things that it needs to be run on your computer for, like file input & output, then PyInstaller is probably the way:
pip isntall
pyinstaller -- onefile script.py
If it is just a short script, then Repl.It is a great way to save and share scripts that can be viewed and run right in the browser. It supports installing pip packages and environments. It even has a feature where you can host a terminal app as a website: repl.run
I am using PyInstaller to create a complete standalone executables, that does not depend on a machine having python interpreter. Here is a complete guide: https://datatofish.com/executable-pyinstaller/

Running a python script in another PC [duplicate]

This question already has answers here:
How can I make a Python script standalone executable to run without ANY dependency? [duplicate]
(19 answers)
Closed 3 years ago.
I have to check versions of different software and their proper patches and I have written a python script that works (developed in my office laptop).
Now I have to run the scripts in my labs and the lab PCs do not have python and I am not allowed to install python on them.
Is there a way to run my python script in the labs?
Options I have seen
Convert my python to an EXE and run it.
If I choose this option, I do not prefer the use of the scheduler to run the EXE in a fixed time as the labs may be used for testing.
How do I create API for my code so I can call the API and run it as needed?
or is there a better way than I have missed?
You could use this alternative way if you dont want to compile to EXE:
For Running Script
Download Portable Python in Folder here
(Optional for additional packeges used) Place venv(Python Virtual Enviroment) in same folder
(Optional) Use venv with python.exe -m venv env
Open cmd in folder with python.exe
Run your script with python.exe script.py
For API:
You can use arguments for API ,it depends how much time and effort you want to put in.
Use sys.args and run script with required arguments
Use TCP Server on allowed ports and listen for commands* (Can be time consuming if you didnt worked with TCP)*

Use Python software without Python interpreter installed on my system

I'm new to Python and I'm trying to understand the basics things.
Before to install the python interpreter on my computer I downloaded Deluge (A torrent client written in Python) and it works without any issue, then I thought I must had Python running but if I run the command:
python --version
I get the error saying that python is not installed on my computer. How is it possible ? How is the code from Deluge executed ?
The software you've downloaded probably has python embedded in its distribution, hence it doesn't require you to install it separately.
Also, running python --version just tells you that python executable isn't in any directories on your PATH variable. It doesn't say it's not installed.
If I look at MacOS Deluge distribution, it has python bundled with it.
Generally, you need python interpreter to run any python programs.
That's probably because what you've download is an executable and does not require Python to be executed.

How can I get the path to the calling python executable [duplicate]

This question already has answers here:
How to determine which Python install is being used by the interpreter? [duplicate]
(1 answer)
How do I check which version of Python is running my script?
(26 answers)
Closed 8 years ago.
I have a series of unit tests that are meant to run in two contexts:
1) On a buildbot server
2) in developer's home environments
In both our development procedure and in the buildbot server we use virtualenv. The tests run fine in the developer environments, but with buildbot the tests are being run from the python executable in the virtualenv without activating the virtualenv.
This works out for most tests, but there are a few that shell out to run scripts, and I want them to run the scripts with the virtualenv's python executable. Is there a way to pull the path to the current python executable inside the tests themselves to build the shell commands that way?
The current python executable is always available as sys.executable, which should give full path (but you can ensure this using os.path functions).

Categories