portable python2/3 coexist on window
It is not big issue to install python2/3 on same Linux but some issue on window, they have same name. There is new launcher to switch different version but not support portable by natural.
Here are some tips to make both portable running smoothly on usb.
dev env
- mobaxterm as cli shell, it is all in one lightweight linux like tool on window, not prefect but it is enough for daily python scripting work
- ipython/jupyter notebook as web based edit/debug tool
- Visual Studio Code as portable IDE
portable python2/3 win installation
download and install by click, then copy to usb E driver folder,
E:\portableapps\python\python27 E:\portableapps\python\python373
don’t need launcher and add to PATH option, then you can uninstall python27 and python373 from windows.
rename python exe
copy python.exe to usb E driver,
E:\portableapps\python\python27\python2.exe E:\portableapps\python\python373\python3.exe
add python path in profile
you can add to .bashrc or portabledevops as below
export PORTABLEPATH=/path-to-portable-folder # portable win python2 if [ -d $PORTABLEPATH/python/python27 ]; then PATH=$PORTABLEPATH/python/python27:$PORTABLEPATH/python/python27/Scripts:$PATH alias pip2="$PORTABLEPATH/python/python27/python2 -m pip" fi # portable win python3 if [ -d $PORTABLEPATH/python/python373 ]; then PATH=$PORTABLEPATH/python/python373:$PORTABLEPATH/python/python373/Scripts:$PATH alias pip3="$PORTABLEPATH/python/python373/python3 -m pip" fi
native pip2/3 not working due to hard code python path in launch exe, so alias is easy option.
runtime env for python3
E:/PORTAB~1/python/python373/python3.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory
double click python.exe will ask "api-ms-win-crt-runtime-l1-1-0.dll"
remedy:
1) python3 need at least visual c++ runtime 2015, download from https://www.microsoft.com/en-ca/download/details.aspx?id=48145
2) update for Universal CRT
Microsoft Visual Studio 2015 creates a dependency on the Universal CRT when applications are built by using the Windows 10 Software Development Kit (SDK). You can install this update on earlier Windows operating systems to enable these applications to run correctly.
https://support.microsoft.com/en-us/help/2999226/update-for-universal-c-runtime-in-windows
install jupyter notebook
jupyter notebook is from ipython notebook and becomes most powerful web based edit/debug tool.
upgrade pip to latest version pip2 install --upgrade pip pip3 install --upgrade pip install jupyter pip2 install jupyter pip3 install jupyter
have to notice all installed script (*.exe) are hard coded with absolute path,
strings jupyter.exe|grep python #!c:\portab~1\python\python373\python3.exe
this is way to run them safely in any place,
python3 jupyter.exe or python3 -m jupyter
also notice there are two set of jupyter script after install it for python2 and python3, either one is working, you can check latest oen in PATH is running one, in below case it is python3 version,
which -a jupyter /cygdrive/E/PORTAB~1/python/python373/Scripts/jupyter /cygdrive/E/PORTAB~1/python/python27/Scripts/jupyter
install kernelspec in mobaxterm,
generate/install kernel,
python2 -m ipykernel install --user Installed kernelspec python2 in C:\Users\username\AppData\Roaming\jupyter\kernels\python2 python3 -m ipykernel install --user Installed kernelspec python3 in C:\Users\username\AppData\Roaming\jupyter\kernels\python3
check kernelspec
cd /drives/e/portableapps/python/python27/Scripts/ python2 jupyter-kernelspec.exe list Available kernels: python2 C:\Users\username\AppData\Roaming\jupyter\kernels\python2 python3 C:\Users\username\AppData\Roaming\jupyter\kernels\python3 cd /drives/e/portableapps/python/python373/Scripts/ python3 jupyter-kernelspec.exe list Available kernels: python2 C:\Users\username\AppData\Roaming\jupyter\kernels\python2 python3 C:\Users\username\AppData\Roaming\jupyter\kernels\python3
from any jupyter notebook you will see kernel for python2 and python3 available now.
note: when usb moved, the drive changed then only need to update kernelspec once,
python2 -m ipykernel install --user python3 -m ipykernel install --user
launch jupyter netbook
"jupyter notebook" not working well due to hard coded python full path inside jupyter.exe, so here is easy remedy,
cd /drives/e/portableapps/python/python373/Scripts/ python3 jupyter-notebook.exe [I 14:09:06.457 NotebookApp] Serving notebooks from local directory: D:\portableapps\python\python373\Scripts [I 14:09:06.457 NotebookApp] The Jupyter Notebook is running at: [I 14:09:06.457 NotebookApp] http://localhost:8888/?token=7087d05f8a9be795d1ac6b6d2674f835d8d0b832276e40c7
the jupyter start folder by default is the location you launch jupyter notebook, so above Scripts folder may not your prefer one, here is another way to launch jupyter notebook in anyplace,
python3 -m IPython notebook
portable python2/3 working with portable mobaxterm
interactive python hanging in mobaxterm due to known terminal type issue, easy remedy is to use option -i to enter interactive mode,
python2 -i python3 -i
portable vsc
download and unzip the vsc zip file, place to
E:\portableapps\vsc create data with same folder as code.exe E:\portableapps\vsc\data create own tmp under data, E:\portableapps\vsc\data\tmp
then all config/extensions will be placed under data/, vsc becomes to portable.
python config in vsc
1) first of all, need to install python extension in vsc
2) in user setting.json, add customized python full path,
{ "python.pythonPath": "E:\\portableapps\\python\\python373\\python.exe", }
conclusion
Here you go with portable python on usb:
- bash shell cli (mobaxterm)
- web based edit/debug tool (jupyter notebook)
- IDE GUI (Visual Studio Code)