3.3. Running PyCharm¶
The following instructions describe how to run the PyCharm IDE using Docker or Singularity.
Starting the container¶
Windows with Docker¶
Follow the instructions in Setup VcXsrv X11 server on Windows in the FAQ Docker section.
Open the
C:/Users/USER_NAME/Documents/development-environment/shortcutsfolder (or where you have extracted thedevelopment-environmentfolder).Double click on the
start_pycharm_from_windows.batfile to run the container.
Linux or Mac with Docker¶
When the commands below are executed, PyCharm will automatically be downloaded and installed in the ~/work/PyCharm folder, which is a folder on the host machine that is mounted within the Docker container. This means that PyCharm will only need to be installed once and all settings will persist even after the Docker container is shutdown/restarted. The specific version of PyCharm that is downloaded can be specified in the development-environment/usr/bin/start-pycharm.sh script. By default, PyCharm 2020.2.3 is installed.
Important
Repeat the docker run command if you receive an error like: ‘docker: Error response from daemon’.
If you are running on Mac, follow the instructions in the FAQ Docker ‘Setup XQuartz X11 server on Mac’ Section.
Open a new terminal on your host machine.
Check that you are using the bash shell:
echo $SHELL
If the command above does not print
/bin/bashthen start a bash shell:
bash
If running on Linux, run the following:
docker run \ --rm \ --name development-environment \ -e DISPLAY=${DISPLAY} \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v ~/development-environment/work:/home/jovyan/work \ -v ~/development-environment/usr/local:/home/jovyan/.local \ -v ~/development-environment/usr/cache:/home/jovyan/.cache \ -v ~/development-environment/usr/config:/home/jovyan/.config \ -v ~/development-environment/usr/java:/home/jovyan/.java \ -v ~/development-environment/usr/bin/:/usr/local/bin \ researchdevresources/development-environment:1.0-tensorflow-notebook start-pycharm.shIf running on Mac, run the following:
docker run \ --rm \ --name development-environment \ -e DISPLAY=$IP:0 \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v ~/development-environment/work:/home/jovyan/work \ -v ~/development-environment/usr/local:/home/jovyan/.local \ -v ~/development-environment/usr/cache:/home/jovyan/.cache \ -v ~/development-environment/usr/config:/home/jovyan/.config \ -v ~/development-environment/usr/java:/home/jovyan/.java \ -v ~/development-environment/usr/bin/:/usr/local/bin \ researchdevresources/development-environment:1.0-tensorflow-notebook start-pycharm.shImportant
Ensure that there are no trailing spaces following the end of line backslash deliminators.
Configuring PyCharm¶
On the first run, you will need to configuring your python environment. This involves selecting the Anaconda python 3.9 interpreter that has been setup within the container.
Warning
Only use the Anaconda Python 3.9 interpreter as shown below for building your software projects within the container and not the system default in /usr/bin/python3.8. This is because only changes to the Anaconda Python 3.9 interpreter (e.g. installation of new libraries) will persist when the container is shutdown.
Note
Since the PyCharm and its settings are stored in a folder that is mapped to your host operating system, you will not need to repeat this setup next time you run the container.
New projects¶
Create a new project folder and store it in the
/home/jovyan/work/folder. e.g./home/jovyan/work/my_new_project
Important
This is important because only files/folders within
/home/jovyan/work/are mapped to the host operating systems. Files outside of this folder will be lost when the container is shutdown.
Select the Anaconda Python 3.9 interpreter that has been setup in the container:
In the Python interpreter section, select Previously configured interpreter.
Click the three dots next to the interpreter option.
![]()
Select path to python interpreter in PyCharm.¶
Specify the following path for the python interpreter:
/opt/conda/bin/python
Create the project.
Existing projects¶
On your host operating system, move or clone your project into the
development-environment/work/folder. e.g.development-environment/work/my_existing_project. This folder will be available within the container in/home/jovyan/work/my_existing_project.Upon running PyCharm from the container, select Open on the PyCharm landing page (or File → Open) and select your project folder e.g.
/home/jovyan/work/my_existing_project.Select the Anaconda Python 3.9 interpreter that has been setup in the container:
Select File → Settings.
Select Project: my_existing_project → Python Interpreter.
Click the gear icon → Add on the top right of the settings window.
Perform step 2 onwards from the previous
New projectssection.
Enabling automatic saving of open files in PyCharm¶
Enable automatic saving of open files by following the tips suggested in the PyCharm tips section of the research-software-development-tutorials.
