Attention
This is older information related to ROS2 Humble. Newer versions, such as Jazzy, are part of the ongoing versions of this tutorial.
Note
This section is optional, the ROS2 tutorial starts at ROS2 Installation.
Editing Python source (with PyCharm)
There are near-infinite ways to manage your Python code and, in this section, we will use PyCharm. Namely, the free community version.
Installing PyCharm
PyCharm is a great program for managing one’s Python sources that is frequently updated and has a free edition. However, precisely because it is frequently updated, there is no way for this tutorial to keep up with future changes.
What we will do, instead, is to download a specific version of PyCharm for these tutorials, so that its behavior/looks/menus are predictable. If you’d prefer using the shiniest new version, be sure to wear sunglasses and not stare directly into the light.
Run
cd ~
mkdir ros2_workspace_pycharm
cd ros2_workspace_pycharm
wget https://download.jetbrains.com/python/pycharm-community-2023.1.1.tar.gz
tar -xzvf pycharm-community-2023.1.1.tar.gz
Create an alias for pycharm_ros2
To simplify the use of this version of PyCharm, let us create a bash alias for it.
echo "# Alias for PyCharm, as instructed in https://ros2-tutorial.readthedocs.io" >> ~/.bashrc
echo "alias pycharm_ros2=~/ros2_workspace_pycharm/pycharm-community-2023.1.1/bin/pycharm.sh" >> ~/.bashrc
source ~/.bashrc
Then, you can run PyCharm with
pycharm_ros2
2024.09 Update
For consistency, until I upgrade this tutorial to the new version of ROS2, the version of pycharm will remain the same. I have identified the following problem when running it on an arm64 Ubuntu VM.
CompileCommand: exclude com/intellij/openapi/vfs/impl/FilePartNodeRoot.trieDescend
Error occurred during initialization of VM
java.lang.UnsupportedClassVersionError: com/intellij/util/lang/PathClassLoader has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
at java.lang.ClassLoader.defineClass1(java.base@11.0.24/Native Method)
at java.lang.ClassLoader.defineClass(java.base@11.0.24/ClassLoader.java:1022)
at java.security.SecureClassLoader.defineClass(java.base@11.0.24/SecureClassLoader.java:174)
at jdk.internal.loader.BuiltinClassLoader.defineClass(java.base@11.0.24/BuiltinClassLoader.java:800)
at jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(java.base@11.0.24/BuiltinClassLoader.java:698)
at jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(java.base@11.0.24/BuiltinClassLoader.java:621)
at jdk.internal.loader.BuiltinClassLoader.loadClass(java.base@11.0.24/BuiltinClassLoader.java:579)
at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(java.base@11.0.24/ClassLoaders.java:178)
at java.lang.ClassLoader.loadClass(java.base@11.0.24/ClassLoader.java:527)
at java.lang.Class.forName0(java.base@11.0.24/Native Method)
at java.lang.Class.forName(java.base@11.0.24/Class.java:398)
at java.lang.ClassLoader.initSystemClassLoader(java.base@11.0.24/ClassLoader.java:1981)
at java.lang.System.initPhase3(java.base@11.0.24/System.java:2091)
My java version before updating is
openjdk version "11.0.24" 2024-07-16
OpenJDK Runtime Environment (build 11.0.24+8-post-Ubuntu-1ubuntu322.04)
OpenJDK 64-Bit Server VM (build 11.0.24+8-post-Ubuntu-1ubuntu322.04, mixed mode)
This can be solved by adding java 17, because that is what the class file version 61.0 stands for. To install java 17 we can run
sudo apt install openjdk-17-jre