Python Remote Development
Sleep Revolution projects that depend on data sets hosted on the Reykjavík University cluster during development will benefit greatly from having access to the data sets through a modern project IDE such as PyCharm.
This guide outlines how you can configure PyCharm to execute code on a remote machine while at the same time ensuring that the development environment stays identical to what you would use for local development.
Other programming languages
This specific setup is for python development, however JetBrains offers similar solutions for many other programming languages through IDEs’ such as the ones listed below.
- IntelliJ: Java
- Rider: DotNet & C#
- CLion: C \& C++
- WebStorm: JavaScript & WebFrameworks
- GoLand: Go & JavaScript
Step 1: Request professional license
The PyCharm IDE’s professional version is required for the setup and is available for free to all students, but requires sending a request for a free educational license.
Apply for the free license by following this web link: JetBrains Students
Step 2: Download PyCharm professional edition
Download and install PyCharm Professional edition to your machine.
Download link: PyCharm Download
Step 3: Connect to vpn.ru.is
Using a VPN client such as Cisco Anyconnect or OpenConnect, establish a secure connection to vpn.ru.is and use your Sleep Revolution credentials for authentication.
Step 4: Create a working directory on remote machine
When we work remotely, all project files are copied from the local machine to the server. We want to store these copied files on the server in a neatly located folder within our server user’s home directory so that we can easily find them again.
- Open a terminal and SSH into your server user:
$ ssh <username>@<ip_address>
- Create a new directory for project files:
$ mkdir sleepy_project_files
Step 5: Open project in PyCharm
Open your project in PyCharm. We recommend you to always open the project from the directory where your source code resides. This is most often named the src/
directory.
Step 6: Configure a remote interpreter
Once the project is open we need to configure a python interpreter to use as a remote execution
environment. Navigate to file → settings → project → python interpreter
. Press the wheel icon in the corner that is seen circled in red in the image below and select the add…
option
Once the window is open we select the SSH interpreter option on the left, then fill in the IP address of the server and our username on the remote machine. Finally, we press next. The image below illustrates the process.
Once you are on the next tab, enter your server user's authentication password and press next. See the below image.
On the next tab, change the interpreter to /usr/bin/python3
. Then change the sync folder to
the folder you created in step 4. The path should be /home/<username>/sleepy_project_files
unless you created the directory not in your home directory on the remote machine. Then press
Ok and Finish. The below image illustrates the process.
Step 7: Configure remote terminal
For some things such as executing tests in the terminal or browsing project files on the remote machine you might want to have the remote terminal handy in your PyCharm editor.
Navigate to file → settings → SSH terminal
. From there in the SSH interpreter drop-down, select the remote connection you created earlier, e.g username@ip_address
. Then click apply before closing the tab if the option to do so is available. See the below image.
Once this is done, you need to start the SSH session to get the terminal running. To do this,
click tools → Start SSH session
in the editors top toolbar. If you open a new tab in the
editor’s terminal you should see that you are no longer in your machines terminal but in the
server terminal.
Manually syncing project files
When we are working on a remote development environment the files are continuously uploaded to the remote server. This is done automatically by PyCharm by default. Sometimes, especially when we are restructuring our files and folders, PyCharm may get confused about what changes must be uploaded and thus corrupting the sync between your local environment and your remote environment.
In such cases we can manually trigger a re-upload of our files to the remote server. See the image below for how to do this.