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/
Related
For test purposes,
I tried to install Blender as a Python module in a virtual environment with Python 3.7 to be sure that i can use bpy.
I follow this page for the installation (https://wiki.blender.org/wiki/Building_Blender/Other/BlenderAsPyModule)
I would like at the end, when I wrote a Python script who used blender command to be able to run outside Blender software and to get information when my script finish
So I have multiples questions:
I don't really understand this line of command for Windows and how I can adapt to my virtual environment :
xcopy /E bin\2.81 C:\Python37\2.81
I can't use 'import bpy' command even when I successfully do pip install bpy in the command line ?
For my final goal project, I'm afraid that it's impossible to do because I couldn't find examples or questions related to my project.
Can someone could explain a little if it's possible or interesting to use Blender externally ?
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)*
I have already converted my python script .py to .exe using pyinstaller. When I try to run this exe in Windows 10. It states this app can not be run on your PC.
As far as I see, I need to install Python in Windows as well, but in my situation this is not an option. In my company, every computer uses Windows 10 and there is no way for me to install Python all of them.
What I wonder is that whether there is any way to run my .py script in Windows 10 without installing anything into Windows 10. I should give a working directory to people in my company and they should run my script with just one click.
EDIT:
With the help of #Amey and #L00n3y, I managed to solve my problem. In case anyone has same problem, I explained the procedure clearly, in this link.
have you tried py2exe?
py2exe is a distutils extension which allows to build standalone Windows executable programs from Python scripts.
You can download it here:
https://pypi.org/project/py2exe/
You can also use 'Pyinstaller' which is widely used.
Install it using,
pip install pyinstaller
And create an executable using the following command,
Python pyinstaller.py --onefile pythonfile.py
With the help of #Amey and #L00n3y, I managed to solve my problem. In case anyone has same problem, I explained the procedure clearly, in this link.
I want to make a portable app that would have some code and python executable that would run on any Windows even if python is not installed.
I would like it to be python 3.6 and so it has only pip and setup tools installed.
EDIT: concerning duplicate
not quite. I don't want to compile the code. I wanted to give them .py files but realize that Windows won't have python installed on default. I want something that can be carry on a flash drive but will run my code from source not binary.
Please correct me, if I understood it wrong. I think there are at least two ways to do it.
suppose you have one portable_run.py script you want to run everywhere on a flashdisk.
Make a exe file with pyinstaller for example. you can get a exe file like portable_run.exe. On target windows system what you need to do is to run the exe direcltly protable_run.exe
Use a portable python distribution like winpython or python-xy. you just need to copy this portable distribution on the flash disk together with your portable_run.py. To run it on target system flashdisk/path-of-winpython/python portable_run.py
Hopefully it could give you some idea.
I also encountered the same problem and managed to create a portable python with Python's official Windows embeddable package.
I wrote the steps into a ps1 script so I can easily repeat the process without going through the pain.
The steps:
Download the portablepy.ps1 from the repo :
https://github.com/Dreamsavior/portable-python-maker
Create a blank folder, put the portablepy.ps1 to that folder.
Execute the portablepy.ps1
The script will create a portable python 3.9.10 with pip in the current folder by default.
To install custom version of Python run the script with -source and -destination parameter
.\portablepy.ps1 -source "https://www.python.org/ftp/python/3.9.10/python-3.9.10-embed-amd64.zip" -destination "C:\SomeDir\PortablePython\"
Where the -source is the url of the Python's Windows embeddable package from this page: https://www.python.org/downloads/windows/
And -destination is the path of your folder (ended with backslash).
I have a script that I wrote in Python. It uses some libraries such as Twython that allows me to post pictures and text to twitter. Now I am trying to make my own photo-booth that runs on Windows. I wish to run the script on the windows computer and I do not wish to install Python on the Windows machine.
I have tried to make exectuables but they do not work (I think because I have inputs that need run after the script (python script.py Message filepath). I thought there was a way to include everything of a normal Python install in the folder you run your script from and it will allow me run it cross platform.
Edit: My question is how can I package python up to run with out installing it preferably from a folder on the desktop.