The main issues for portable python
-
python hardcoded full path in installed binary tool like pip.exe, easy_install.exe, ipython.exe, it is in main header located the end of exe file
#!C:\"path"\python.exe
you will get in trouble when you change parent directory of python or move it to another different drive. -
if there are multi python version installed on window, only first one python path working fine
Let me show you how to easily to make multi portable python on window.
1) install multi python
standard installation to local drive then move to portable drive
L:\oldhorse\portableapps\Python27 L:\oldhorse\portableapps\Python3
now you can uninstall them from local drive.
2) setup multi python env
under msys /usr/local/bin,
the key just to add python folder and Script folder to PATH
/usr/local/bin/mypy2
#!/bin/bash OLD_PATH="$PATH" PATH=/portable/Python27:/portable/Python27/Scripts:$PATH PYPATH=/portable/Python27 alias mypip="$PYPATH/python $PYPATH/Scripts/pip.exe" alias myipy="$PYPATH/python $PYPATH/Scripts/ipython.exe" alias mynb="$PYPATH/python $PYPATH/Scripts/jupyter-notebook.exe" alias myeasy="$PYPATH/python $PYPATH/Scripts/easy_install.exe" export OLD_PATH PATH export PS1='(mypy27) \u> \w $ '
/usr/local/bin/mypy3
#!/bin/bash OLD_PATH="$PATH" PATH=/portable/Python3:/portable/Python3/Scripts:$PATH PYPATH=/portable/Python3 alias mypip="$PYPATH/python $PYPATH/Scripts/pip.exe" alias myipy="$PYPATH/python $PYPATH/Scripts/ipython.exe" alias mynb="$PYPATH/python $PYPATH/Scripts/jupyter-notebook.exe" alias myeasy="$PYPATH/python $PYPATH/Scripts/easy_install.exe" export OLD_PATH PATH export PS1='(mypy3) \u> \w $ '
add alias to /etc/profile:
alias mypy2='source /usr/local/bin/mypy2' alias mypy3='source /usr/local/bin/mypy3'
start new session with expected python version:
$ mypy2 (mypy27) oldhorse> ~ $ which -a python /portable/Python27/python.exe /c/Python27/python.exe $ mypy3 (mypy3) oldhorse> ~ $ which -a python /portable/Python3/python.exe /c/Python27/python.exe
3) portable python tool
option1 – scite or notepad++ to replace
#!C:\"path"\python.exe to #!python.exe
option2 – directly run without any change even the path inside pip.exe could be wrong
python /"path"/pip.exe list
option3 – add alias in /etc/profile
alias mypip=’python /"path"/pip.exe’
then run as
mypip list
I prefer option3 since it has less effort but working good.