Portable Python — все свое ношу с собой!
Если встретить linux-дистрибутив без интерпретатора python почти невозможно, то по отношению к Windows ситуация диаметрально противоположная. А питон ведь кроссплатформенный!
Конечно, можно поставить интерпретатор и на windows, но если хочеться запустить любимый скрипт на чужом/рабочем компьютере, под управлением данной ос?
Что, тоже мучиться с установкой? А если на машину нельзя/нецелесообразно ставить ПО. Да и время на это тратить, ради запуска одного скрипта не хочется?
Тогда, на помощь нам придет Portable Python!
- Собственно сам интерпретатор версии 2.5, способный запускаться прямо с флешки, без каких либо настроек/установок.
- Django 0.96 — Высокоуровневый Web-фреймворк удобный в разработке cайтов с базами данных (SQLite в комплекте).
- Scite 1.71 — неплохой текстовый редактор с подсветкой синтаксиса и поддержкой табов для документов.
Внимание! Проект находится в стади beta.
Также, пока что нет возможности установить рабочую папку для скриптов.
Личные впечатления:
Я фактически только изучаю питон, гуи-шных программ под портативным интерпретатором запускать не пробовал, но все мои нехитрые скрипты работают нормально. Для меня он полезен, поскольку будучи жертвой нашей прекрасной системы образования, мне сейчас приходится по четыре с половиной часа сидеть за компьютером, на котором опция установки ПО, заблокирована админом, и заниматься учебной ерундой. Когда с ерундой покончено, или иногда вместо нее, я открываю учебник и практикуюсь в питоне(уходить с «учебно-рабочего места» раньше времени тоже обычно не разрешают).
Надеюсь вам эта сборка тоже пригодится.
Как установить python на флешку
This project is a python CLI that aims to make compiling portable python binaries automatable.
What is a “portable python”?
It’s a binary python distribution (.tar.gz or .zip) that can be decompressed in any folder, and used from there without further ado (ie: no need to run an “installer” and things like that).
The idea here is to allow for automated systems to:
- Easily obtain a python binary, that can be used in sandboxes / workstations / laptops / instances…
- Have an open source tool that can compile such portable pythons reliably, without having to worry about the compilation part.
- Be able to inspect any python installation, and point out how portable it is, which shared or non-standard libraries it is using
Guiding principles
- Focuses on just one thing: compile a portable python, and validate that it is indeed portable, produce outcome in (configurable) ./dist/ folder and that’s it
- Only the last few non-EOL versions of python are supported (no historical stuff)
- As time goes on, the code of this tool will evolve so that the latest pythons keep building (but won’t worry that older versions still keep building)
- C compilation is done as simply as possible: no “patching” of any sort, rely solely on the upstream make/configure scripts, typically via stuff like --enable-shared=no
- Builds are validated, an important part of the effort was to write up code that is able to inspect a python installation and detect whether it is portable or not (and why not if so).
- cpython is initially supported, but aiming to compile any python family in the future (pypy, conda, …)
- Cross-compilation would be cool, but only if upstream supports it (ie: only if doable via stuff like ./configure --host=. — no on-the-fly patching allowed)
For this repo itself:
- Code is pure python, it is a CLI with one entry-point called portable-python
- Can be ran in a debugger
- 100% test coverage, has a --dryrun mode to help with testing / debugging / seeing what would be done quickly
- No shell scripts (those are hard to maintain/test/debug)
- Can be pip install-ed and reused
Installation
portable-python is a regular python CLI, it can be installed with:
You can also run it directly (without explicit install) with pipx:
Using pip install (a CI builder would probably do this):
Invoke a build from python code:
Invoke an inspection from python code:
From source, contributions welcome!:
Building a portable cpython
Once you’ve installed portable-python , you can get going like so:
Note that you can use --dryrun mode to inspect what would be done without doing it:
Build folder structure
portable-python uses this file structure (build/ and dist/ folders configurable):
How to make python portable?
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.
3 Answers 3
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).

Embeddable python may be portable solution in the future, but currently it doesn’t support easy install of pip, tkinter, and possibly other dependencies.
For the standard (non-embeddable) environments, sometimes just combining them with binaries and replacing absolute paths with relatives is enough.
But this will create very large portable archive >100MB, while online install initial distribution overhead <1MB.Both options can be done via powershell without packing into custom binaries, here is example which couples original pyton binaries and environment (with tkinter and pandas dependency) into portable folder.
Name already in use
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.rst
Portable python binaries
This project is a python CLI that aims to make compiling portable python binaries automatable.
Supported operating systems
Currently Windows is not supported, contributions are welcome.
Python binaries can be produced as «portable» (statically linked, can run from any folder where the binary is unpacked in), or with a —prefix (build targeted to live in a pre-determined folder, like /apps/pythonM.m )
Operating system Portable —prefix Linux ✅ ✅ Macos ✅ ✅ Windows ❌ ❌ What is a «portable python»?
It’s a binary python distribution ( .tar.gz or .zip ) that can be decompressed in any folder, and used from there without further ado (ie: no need to run an «installer» and things like that).
The idea here is to allow for automated systems to:
- Easily obtain a python binary, that can be used in sandboxes / workstations / laptops / instances.
- Have an open source tool that can compile such portable pythons reliably, without having to worry about the compilation part.
- Be able to inspect any python installation, and point out how portable it is, which shared or non-standard libraries it is using
- Focuses on just one thing: compile a portable python, and validate that it is indeed portable, produce outcome in (configurable) ./dist/ folder and that’s it
- Only the last few non-EOL versions of python are supported (no historical stuff)
- As time goes on, the code of this tool will evolve so that the latest pythons keep building (but won’t worry that older versions still keep building)
- C compilation is done as simply as possible: no «patching» of any sort, rely solely on the upstream make/configure scripts, typically via stuff like —enable-shared=no
- Builds are validated, an important part of the effort was to write up code that is able to inspect a python installation and detect whether it is portable or not (and why not if so).
- cpython is initially supported, but aiming to compile any python family in the future (pypy, conda, . )
- Cross-compilation would be cool, but only if upstream supports it (ie: only if doable via stuff like ./configure —host=. — no on-the-fly patching allowed)
For this repo itself:
- Code is pure python, it is a CLI with one entry-point called portable-python
- Can be ran in a debugger
- 100% test coverage, has a —dryrun mode to help with testing / debugging / seeing what would be done quickly
- No shell scripts (those are hard to maintain/test/debug)
- Can be pip install -ed and reused
portable-python is a regular python CLI, it can be installed with:
You can also run it directly (without explicit install) with pipx:
Using pip install (a CI builder would probably do this):
Invoke a build from python code:
Invoke an inspection from python code:
From source, contributions welcome!:
Building a portable cpython
Once you’ve installed portable-python , you can get going like so:
Note that you can use —dryrun mode to inspect what would be done without doing it:
Build folder structure
portable-python uses this file structure (build/ and dist/ folders configurable):