PyCharm#
PyCharm is a well-known integrated development environment (IDE) for Python offered by JetBrains. We offer the PyCharm community edition (based on PyCharm modules) as a web-based app via Open OnDemand.
VSC clusters that support this app are:
Selecting a suitable Python environment#
Aside from code editing, PyCharm also allows you to run your Python scripts and use a Python console from within the IDE. By default, PyCharm will use an available system Python installation for this purpose (such as the Python 3.9 installation currently present in the OnDemand container for PyCharm). Depending on your needs you can either accept this default choice (and make other configuration changes) or select or create a different Python environment:
Creating a new virtual environment using the default Python interpreter
Use an existing Python virtual environment based on Python modules
Creating a new Conda environment
Using an existing Conda environment
For more advanced configuration options, see also the JetBrains documentation.
Note
Make sure you do not use your VSC_HOME
(starting with /user/...
)
for storing your virtual environment, Mamba or Conda,
because your home directory can get quickly filled up leading to possible
issues with your login and/or job submission. Instead, we recommend using
your VSC_DATA
directory (starting with /data/...
).
Note
For long-running jobs or for jobs using more than one node (with e.g.,
mpi4py
or dask.distributed
), we recommend submitting batch
jobs instead.
Using the default Python interpreter#
The following steps (adopted from the official PyCharm documentation) show how you can create a PyCharm Project using the system Python installation automatically detected by PyCharm.
Note
Keep in mind that this will typically be a fairly old version of Python. You furthermore run the risk that your environment will no longer work at some point since the container’s Python installation will upgrade as part of the maintenance cycle of the OnDemand infrastructure.
Click on the ‘New Project’ on the welcome screen, or choose ‘File’ -> ‘New Project’.
Choose a ‘Location’ for your project hierarchy, preferably in your
VSC_DATA
(such as/data/<institute>/xxx/vscxxxxx/python-projects/pre-processing
).For the ‘Interpreter type’ choose ‘Custom environment’.
For the ‘Environment’ select ‘Generate new’ (and you only need to do this once).
For the ‘Type’ of the environment choose ‘Virtualenv’. At this point, the ‘Base python’ is already selected as
Python 3.9
, pointing to/usr/bin/python3
.For the ‘location’ of your Python virual environment, choose a new folder in your
VSC_DATA
, such as/data/<institute>/xxx/vscxxxxx/pycharm-venvs/pandas
.It is OK to select ‘Inherit packages from base interpreter’.
Click on ‘Create’. At the bottom right, you see the environment name
Python 3.9 (pandas)
appearing.If you are asked about how to open the new project, you may select ‘New Window’.
As an example, to add the
pandas
package from Scikit-Learn, click on the ‘Python Packages’ icon on the left tray, and putpandas
in the search box. From the long list of available packages, choose thesklearn-pandas
package and click on the ‘Install’ button. You may choose the latest version. The installation of dependencies and preparation of the virtual environment may take a minute or two.
Using an existing Python virtual environment#
PyCharm also supports virtual environments which were created outside of PyCharm. Due to limitations regarding the use of centrally installed modules in the PyCharm container, however, this will only work under specific conditions:
The Python module (from which the virtual environment has been derived) needs to have been built using RPATH linking. On the Tier-2 clusters hosted at KU Leuven this is only the case starting from the
2025a
toolchain generation.The environment doesn’t require any other module except for
Python
.
Even if these conditions are met, there is no guarantee that the environment will continue to work across OS and other upgrades of the PyCharm container. We would therefore usually recommend to consider other apps such as JupyterLab for this use case.
With this in mind, these are the steps to set up a PyCharm project with such a virtual environment:
Click on the ‘New Project’ on the welcome screen, or choose ‘File’ -> ‘New Project’.
Choose a ‘Location’ for your project hierarchy, preferably in your
VSC_DATA
(such as/data/<institute>/xxx/vscxxxxx/python-projects/pre-processing
).For the ‘Interpreter type’ choose ‘Custom environment’.
For the ‘Environment’ choose ‘Select existing’.
For the ‘Type’ of the environment choose ‘Python’.
For the ‘Python path’ use the browse button to select the interpreter in your virtual environment (
/path/to/your/venv/bin/python
).Click on ‘Create’. The interpreter name at the bottom right will refer to your chosen virtual environment.
To install more packages in your virtual environment from within PyCharm, see the last steps from the previous paragraph.
Creating a new Conda environment in PyCharm#
Assuming for instance, you have a local Miniconda installation, you may create a new Conda environment in PyCharm
after you start a ‘New Project’ by following the steps below. Make sure you
do not install Miniconda via PyCharm because it will end up in your
VSC_HOME
which is strongly discouraged.
Select a ‘Location’ starting in your
VSC_DATA
.For the ‘Interpreter type’ choose ‘Custom environment’.
For the ‘Environment’ choose ‘Generate new’.
For the ‘Type’ choose ‘Conda’.
For the ‘Python version’ pick one that suits your needs.
For the ‘Name’ again choose a unique and representative (e.g.,
conda-pandas
).For the ‘Path to conda’ set the path to your
conda
executable (a typical location would be/data/<institute>/xxx/xxxxx/miniconda3/bin/conda
).Click on the ‘Create’ button and wait for a minute. Eventually, the interpreter at the bottom right tray will show e.g.,
conda-pandas
.
Using an existing Conda environment#
You can also let PyCharm use Conda (or Mamba) environments that you created outside PyCharm. The steps are the same as in the previous paragraph, except:
For the first ‘Environment’ box, choose ‘Select existing’.
For the second ‘Environment’ box, choose your Conda or Mamba environment from the list.
Using the terminal#
PyCharm also offers a Bash terminal, but it will lack some functionalities.
Loading and using the centrally installed modules will not work, for example,
and neither will Slurm commands such as squeue
. For a more fully
featured environment we recommend to use the Interactive Shell app or the integrated terminal from the
VS Code Server app instead.