Installating and using portable VScode (version of 2019-08-30)

read also https://code.visualstudio.com/docs/editor/portable

Portable mode is only supported on the Windows ZIP archive of vscode


In [ ]:
!echo %winpydirbase%

1 - Downloading and Installing the right VScode binary in the right place

go to https://code.visualstudio.com/Download

download a VSCode "zip" version for Windows

unzip it and rename the top directory as "VScode" (from, for example, "VSCode-win32-ia32-1.38.0")

place it under Winpython base directory %winpydirbase%\t\

you must have the code.exe executable in %winpydirbase%\t\VSCode\code.exe

2 - prepare Portable VScode

create the directory %winpydirbase%\t\VSCode\data : seeing it VScode will put all is parametrizing there.

create the directory %winpydirbase%\t\VSCode\data\user-data\user\settings.json as follow:

{
    "python.pythonPath": "${env:WINPYDIR}\\\\python.exe",
}

nota: the "VS Code" icon of WinPython should work with a fixed-PC installed VScode, by changing the setting of python.pythonPath as indicated above


In [ ]:
import os
os.environ["tmpjson"] = os.environ["winpydirbase"]+"\\t\\VSCode\\data\\user-data\\user\\settings.json"
!rem set tmpjson=%winpydirbase%\t\VSCode\data\user-data\user\settings.json
!if not exist "%winpydirbase%\t\vscode" mkdir "%winpydirbase%\t\vscode"
!if not exist "%winpydirbase%\t\vscode\data" mkdir "%winpydirbase%\t\vscode\data"
!if not exist "%winpydirbase%\t\vscode\data\user-data" mkdir "%winpydirbase%\t\vscode\data\user-data"
!if not exist "%winpydirbase%\t\vscode\data\user-data\user" mkdir "%winpydirbase%\t\vscode\data\user-data\user"
!if exist "%tmpjson%.txt" del "%tmpjson%.txt"
!if not exist %tmpjson% echo { > "%tmpjson%.txt"
!if not exist %tmpjson% echo "python.pythonPath": "${env:WINPYDIR}\\\\python.exe", >> "%tmpjson%.txt"
!if not exist %tmpjson% echo } >> "%tmpjson%.txt"
!if not exist "%tmpjson%" copy "%tmpjson%.txt" "%tmpjson%"
!if exist "%tmpjson%.txt" del "%tmpjson%.txt"

In [ ]:
!type "%tmpjson%"

3 - Launch "VS Code" icon (at base directory of Winpython)

nota: it will launch the %winpydirbase%\scripts\winvscode.bat:

DOS
@echo off
rem launcher for VScode
call "%~dp0env_for_icons.bat"
cd/D "%WINPYWORKDIR%"
if exist "%WINPYDIR%\..\t\vscode\code.exe" (
    "%WINPYDIR%\..\t\vscode\code.exe" %*
) else (
    "code.exe" %*
)

In [ ]:
#launching for you
!%winpydirbase%\scripts\winvscode.bat

4 - add the python extension

go to vscode menu "View --> Extensions" to select an extension (it's also the left-bottom_of_the_top icon)

Type "Python" to search the Python ones

select the "Python" from author Microsoft (the most popular extension), and click "install"

5 - using "VS Code"

Python file (.py)

Opening a first Python file will launch the Python extension

After about 20 seconds, Your WinPython Python Interpreter must appear on bottom left of the vscode window, as a proof it is recognized

.. if not, the Python extension will propose you to select it manually.

Open via "File->Open" of VScode a python file, like for example %winpydirbase\notebook\minesweeper.py

"Right-Click" in the middle of the source file and choose "Run Python File in Terminal"

Ipython Notebook (.ipynb)

see https://code.visualstudio.com/docs/python/jupyter-support

on the File Explorer of VS Code, right click on "baresql experiment.ipynb" and choose "Import Jupyter Notebook"

(yes, it does an import with some transformation)

"Right Click" on the source file obtained and choose "Run all cells" or click on individual "Run cell" that are displayed in the imported source.

beware Jupyter is very slow to start (twice slower than in direct mode ?)

6 - checking / changing the path to WinPython (if not done properly in step 2)

go to vscode men "Files --> Preferences -> Settings

look for python.pythonPath and press enter

to get an automatically movable path, type in it

${env:WINPYDIR}\\python.exe

press enter to validate

The Selected Python Interpreter must appear on bottom left of the vscode window, as a proof it is recognized


In [ ]: