How can I run a python script without python.exe - python

My goal is to have a python script that I can giving to someone to run on their windows machine that does not have python installed. I do want to package it up in an exe because I want the underlying code to be easily read.
I am updating an old VBscript and I want to mirror it. I am also using a few libraries.

use pyinstaller to package it up to an exe. You can still maintain your source code. Packaging it up wont remove your source code.

Related

Packing python scripts into .exe file while keeping imported modules

I have a python script I want to pack into .exe file for the ease of use. The python script makes extensive use of Tkinter module for nice GUI. I've packed it first into .exe using pyinstaller and the guide outlied here - https://datatofish.com/executable-pyinstaller/
I have two problems. First is that my script makes use of FlowCal module, which doesn't come with Python's pyinstaller (I've made script using Spyder, and I'm using Python 3.8. to compile using pyinstaller) - so I installed FlowCal with pip install FlowCal so Python gets it too (I think that's how it works? Not too sure). But then FlowCal is dependent on various sklearn modules, and it would be a headache to install modules, compile to exe, then check if it works over and over. Is there a way that ALL modules script uses (and ALL modules that imported modules use) are compiled into the script?
Second problem is that alongside GUI I get another window. Picture included. How do I remove that window?
Another thing you can do without any hassle is using auto-py-to-exe. This will generate .exe from .py with writing command, just clicking some buttons in a GUI. For this, you have to give the command: pip install auto-py-to-exe in command prompt or PowerShell, whatever you like most. After successfully installing auto-py-to-exe, give the command auto-py-to-exe in your command prompt. Then give the necessary informations, and get your generated executable file!
Add the missing modules to the hiddenimports
hiddenimports=['sklearn.neighbors.typedefs','sklearn.neighbors.quad_tree','sklearn.tree._utils']
Or use it when you create the exe in cmd as
--hidden-import=modulename

How to download python with python?

So basically what I'm trying to do is to download python with a python file. It needs to be so that user does not have to interact with the python installer at all. They just click the file and python is installed on the computer. I don't need pip I just need the computer to be able to read .py files. I seem to only be able to download the installer which the user then must open.
What would the solution to this be?
I'm using python 3.6. Also, the file must be able to be compiled to .exe so something built into python and not a module from the internet would be best (I sometimes have trouble compiling files with modules from the internet with pyinstaller) but I'm open to anything.
This is my first question so I might be doing something wrong...
You will want to start by developing a python script that does any function you want it to do. In this case, it looks like you want it to download python and install it without user interaction and you want to be able to run this as an executable on windows. So your process would be as follows.
your_script_name.py
This contains all the code to download and install python non-interactive.
Then to convert this into windows.exe install pyinstaller then run the following.
pyinstaller --onefile <your_script_name>.py
This will result in your_script_name.exe
Note: You need to run pyinstaller on a windows system for it to produce an .exe

Install and execute python3 inside one same independent folder

I have a small program written with Python3 that I'd like to install on friends computers. The main issue is that not every computer has a Python3 installed on it (mostly Python2-). Do I have to install it on each computer I want my program to run?
I thought it would be possible to install Python3 inside a separate directory, as shown below.
Then, I would be able to use a shebang to run the right version of Python installed inside myProgram folder.
#!C:\myProgram\python3 python
# Test
a = input('Entrer un nom:')
print(a)
When I double-click on myProgram.py file, a window opens and closes immediatly...
Is this a bad idea or not? Is there a way to achieve that differetnly if so?
You could create an executable from the python script rather than installing all of python 3 on their machine. There's a few ways you can do it, see this answer.
I'd have a look at pyinstaller.
Add Python 3 to your friends machine to execute your program.
What'is the utility to run such a small program on their computers?
The way you propose won't work.
Windows does not know about shebangs.
Even if it did, this one would only work if a user installed the program to C:\myProgram (which is not a really appropriate place, and the user might not have the rights to install it there).
There are ways to make a python program portable w/o having the need to have a Python runtime installed. Alas, I currently don't know their name.
Or, if that is feasible, install Python 3 on their machines, but I don't know if that might break any programs wanting to use Python 2.
There're different tools which can pack you program to single .exe file or make an installer. Here's my solution from 2016 year - Python - create an EXE that runs code as written, not as it was when compiled
Now it will be little easier :)

Can the Python interpreter and Python app source code be embedded into a compiled program?

I want to put the Python interpreter and all the source files of a fairly large Python application with multiple .py files into an executable Linux file.
Thus when running the application, the Python interpreter will run the Python source code that is embedded into the executable.
Using Python 3.
Is such a thing possible?
Edit: in addition to the selected answer another option is to use Cython.
Sounds like you're looking for a packaging module, like py2exe or cx_Freeze (I prefer the latter). They bundle the interpreter and your files together so that a machine without an installation of Python can run your program.

packaging python program in a single executable

Hi I need to package a python program in to a single executable. I need to have a executable that does not need a python installation and third party packages.
So need to have
python 2.7.5
WMI==1.4.9
pyjs==0.1.0
pywin32==219
requests==2.4.3
urllib3==1.9.1
Is this even possible? I need to able to make a executable to to be run on a freshly installed windows XP+ machine.
I tried pyinstaller but after that i could not execute the file. Which tool could provide everything needed?
Take a look at Py2exe: http://www.py2exe.org/ . It's made for that exact purpose.

Categories

Resources