Integrated Development Environment (IDE)
This guide covers setting up your code editor for working with the VIKTOR SDK. Below instructions assume the app resides in a folder called 'my-app-folder'.
Pycharm
- Virtual environment
- Docker
Open the 'my-app-folder' directory. Pycharm will take this directory as the root directory from which imports are
resolved. If you have not installed your app yet Pycharm will ask you to configure a virtual environment. You can click
'Cancel' as the CLI will create a virtual environment when you use the install command. If there is a
'requirements.txt' file you can run viktor-cli install
to create a virtual environment and install the app's
dependencies. Subsequently, open the settings to select a Python interpreter:
File > Settings > Project: {Project Name} > Python interpreter > Wheel icon > Add...
The virtual environment created by the CLI will be selected as the default existing environment. You can click 'OK', 'Apply' and 'OK' again to select the Python intepreter. Now you are ready to start development in Pycharm!
Using a WSL2 based interpreter in Pycharm is only available in Pycharm Professional
Open the 'my-app-folder' directory. Pycharm will take this directory as the root directory from which imports are resolved. This works fine for the app specific code, but it cannot find the VIKTOR SDK code (and of all other dependencies). To solve this, add the 'pip-cache' folder as content root:
File > Settings > Project: {Project Name} > Project Structure > Add Content Root
Directory which should be added, in which HOME
has to be replaced with %USERPROFILE%
(usually
C:\Users\<username>
) in case of Windows, or $HOME
(usually /home/<username>
) in case of Linux:
HOME
└── .viktor
└── viktor-installs
└── my-app-folder-specific
└── pip-cache
Since the folder to be added is within a hidden folder ('.viktor'), it must be made visible by clicking the "Show Hidden Files and Directories" button in the "Select Content Root Directory" window.
Visual Studio Code
Make sure to install the "python" extension:
View > Extensions > Search for "python" by Microsoft
- Virtual environment
- Docker
Open the 'my-app-folder' directory. If a virtual environment folder is already present you are ready to start
developing your app. Otherwise, install your app with viktor-cli install
. When the virtual environment is created
Visual Studio Code detects the virtual environment and will ask you to select it for the workspace folder, click 'Yes'.
Now you are ready to start development in Visual Studio Code!
Within the app directory, add another directory named .vscode
and add a file named settings.json
.dependencies
my-app-folder
└── .vscode
└── settings.json
On Windows add the following content to settings.json (replace <USERPROFILE>
with the value of the %USERPROFILE%
environment variable (e.g. C:/Users/<username>
) and <APPFOLDERNAME>
with the name of the app folder):
{
"python.autoComplete.extraPaths": [
"<USERPROFILE>/.viktor/viktor-installs/<APPFOLDERNAME>-specific/pip-cache"
],
"python.analysis.extraPaths": [
"<USERPROFILE>/.viktor/viktor-installs/<APPFOLDERNAME>-specific/pip-cache"
],
}
On WSL2/Linux add the following content (replace <APPFOLDERNAME>
with the name of the app folder):
{
"python.autoComplete.extraPaths": [
"${env:HOME}/.viktor/viktor-installs/<APPFOLDERNAME>-specific/pip-cache"
],
"python.analysis.extraPaths": [
"${env:HOME}/.viktor/viktor-installs/<APPFOLDERNAME>-specific/pip-cache"
],
}