10

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.

Kazz
  • 528
  • 1
  • 6
  • 20
  • 3
    Possible duplicate of [How to make a Python script standalone executable to run without ANY dependency?](https://stackoverflow.com/questions/5458048/how-to-make-a-python-script-standalone-executable-to-run-without-any-dependency) – OneCricketeer Jun 11 '17 at 19:59
  • Python eggs might be what you are looking for https://stackoverflow.com/questions/2051192/what-is-a-python-egg – pmuntima Jun 11 '17 at 20:10

2 Answers2

4

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.

  1. 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

  2. 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.

milo
  • 1,267
  • 8
  • 10
  • 1
    unfortunately no, as i said i don't want to compile my code and all those portable pythons does not have pip and have lots of other stuff i don't need. I was thinking of create my own app like this but i dont know where to start. – Kazz Jun 11 '17 at 22:56
  • @Kazz, did you find the solution? – Oli May 23 '18 at 06:37
  • Unfortunately no, and even more issue came up with compiling. Turn out that even compiling it to C won't work since on fresh Win7 Installation (fully updated) there is no C runtime env by default. I personly gave up on developing python apps on windows, you might wanna look into using docker on windows 10. – Kazz May 23 '18 at 20:13
  • 3 and a half years later and there is still no good option out there. – smvd Feb 02 '21 at 13:55
  • Well you can use embeddable Python (for example for Python3.8 go to https://www.python.org/ftp/python/3.8.0/ and search for embed). Unzipped it to a folder. `cd` to the folder. Install pip (`curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python get-pip.py`). Install the packages you need (`python -m pip install x y z`). You have a portable python. I managed to package a `gradio` app (one of those on https://huggingface.co/spaces, but my friends want to run the app locally and they dont know too much about python) this way and send the whole thing to my friends. – mikey Dec 30 '21 at 12:33
0

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:

  1. Download the portablepy.ps1 from the repo : https://github.com/Dreamsavior/portable-python-maker
  2. Create a blank folder, put the portablepy.ps1 to that folder.
  3. 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).

Donovan P
  • 417
  • 4
  • 6
  • You still need Universal C Runtime present in the OS right? That's what blocked me 5y ago. What Windows versions did you test this on? – Kazz Mar 02 '22 at 15:47