Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 854
Kazz Avatar asked Jun 11 '17 19:06

Kazz


People also ask

Can Python be portable?

In theory, Python is a portable language. You can write your script locally and distribute it to other machines with the Python interpreter. In practice, things can go wrong for a variety of reasons. The first and simpler problem is the module system: for a script to run, all of the modules it uses must be installed.

Can you install Python on a USB stick?

Yes, you literally download the installer from python.org and select the installation folder you want. This folder may very well be on a USB drive. You can also install PyCharm on your drive - and now you have a fully featured portable development environment.


1 Answers

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.

like image 143
milo Avatar answered Oct 21 '22 20:10

milo