Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
habrok:examples:vscode_python [2025/05/27 09:11] – created fokkehabrok:examples:vscode_python [2025/05/27 09:17] (current) fokke
Line 1: Line 1:
 ===== Using Python modules in VScode ==== ===== Using Python modules in VScode ====
 +
 +VScode is available on the cluster in the Web portal or through an ssh connection from your local VScode software. See [[../connecting_to_the_system/connecting_via_vsc]] for details on the connection methods.
  
 When using VScode to develop your software on the cluster it is best to make use of virtual environments. When using VScode to develop your software on the cluster it is best to make use of virtual environments.
Line 7: Line 9:
 ==== Creating the virtual environment ==== ==== Creating the virtual environment ====
  
-Setting up the virtual environment is best done within the **"Terminal"** window of VScode. The first step is to load a Python module with the version that you want to use. You can find the available versions using:+Setting up the virtual environment is best done within the **Terminal** window of VScode. The first step is to load a Python module with the version that you want to use. You can find the available versions using:
 <code> <code>
 module spider Python module spider Python
Line 16: Line 18:
 module load Python/3.11.5-GCCcore-13.2.0 module load Python/3.11.5-GCCcore-13.2.0
 </code> </code>
 +
 +Create and activate a virtual environment in the expected ''.venv'' location.
 +<code>
 +python -m venv .venv
 +source .venv/bin/activate
 +</code>
 +
 +You will probably get a pop-up from VScode that it noticed the new .venv. It will offer to select it for this project. You can say yes, to switch to this environment.
 +
 +You can also select the Python version from the virtual environment using the Python version selection box at the bottom right of the VScode window.
 +
 +After this you can proceed to install packages into the virtual environment using pip in the "Terminal" window, e.g.:
 +<code>
 +pip install matplotlib
 +</code>
 +