Skip to content

Setup (Pycharm)

manx52 edited this page Sep 20, 2024 · 31 revisions

Pycharm Professional

(Optional) Auto Sync using settings repository

Python Intepreter
  • Note: Do not use the virtualenv intepreter (ROS uses the system intepreter and it will cause inconsistency when running the code
  • Use the System Intepretor
    • Go to File > Setting > Project:xxxx > Python Interpreter > Show All > Add > Add local intepreter > System Intepreter and choose /usr/bin/python3.8
    • Click File > Setting > Project:xxxx > Python Interpreter > Show All > Python 3.8 > Show paths for the selected interpreter (5th button from the left) > Add the Intepreter Paths (Replace $USER with your computer user)
      /opt/ros/noetic/lib/python3/dist-packages
      /home/$USER/catkin_ws/devel/lib/python3/dist-packages
      /home/$USER/catkin_ws/src/soccerbot/external/webots/lib/controller/python38
  • OR Use the docker-compose Intepretor
    • Go to File > Setting > Project:xxxx > Project Interpreter > (Click on the Gear) > Add > Docker Compose
      • choose the docker-compose.yaml file
      • choose service as friendly
      • choose python interpreter path as /usr/bin/python3
    • Click on the gear > show all > Select python 3.8 > Show paths for the selected interpreter (5th button from the left) > Add the Intepreter Paths
Other settings (suggested)
  • Install the *.launch file plugins. Look up duckietown/hatchery from the third party repositories in Preferences/Plugins
Debugging
  • Edit the file /etc/sysctl.d/10-ptrace.conf and change the line kernel.yama.ptrace_scope = 1 to kernel.yama.ptrace_scope = 0. and then run sudo service procps restart
  • Run > Attach to Process > Select the Process you want to attach to, you might want to rosnode info to identify it's PID. Add a breakpoint
Debugging in the container (Optional)
  • Run sudo visudo and add the lineshahryar ALL=NOPASSWD:/usr/bin/gdb (replace shahryar with your name)
  • Edit the ~/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/221.5080.212/plugins/python/helpers/pydev/pydevd_attach_to_process/add_code_to_python_process.py line 470 and add the sudo to it so it looks like the following (Note: 221.5080.212 folder might differ on your computer but follows the same number.number.number format)
    cmd = [
        'sudo',
        'gdb',
        '--nw',  # no gui interface
        '--nh',  # no ~/.gdbinit
        '--nx',  # no .gdbinit
#         '--quiet',  # no version number on startup
        '--pid',
        str(pid),
        '--batch',
#         '--batch-silent',
    ]
  • Edit the ~/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/221.5080.212/plugins/python/helpers/pydev/pydevd_attach_to_process/attach_pydevd.py line 470 and change the setup host to '172.17.0.1' on line 12
def process_command_line(argv):
    setup = {}
    setup['port'] = 5678  # Default port for PyDev remote debugger
    setup['pid'] = 0
    setup['host'] = '172.17.0.1'
    setup['protocol'] = ''
  • Run > Attach to Process > Select the Process you want to attach to, you might want to rosnode info to identify it's PID. Add a breakpoint
Pytest

Add this to Environmental Variables LD_LIBRARY_PATH=/usr/local/lib:/opt/ros/noetic/lib:/usr/local/bin/python3 Add -s to additional argumement

CLION Version

Pytest

Add this to Environmental Variables LD_LIBRARY_PATH=/usr/local/lib:/opt/ros/noetic/lib:/usr/local/bin/python3 LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/ros/noetic/lib:/home/jonathan/catkin_ws/devel/lib Add -s to additional arguments to print out stdout while pytest is running

CMAKE

add this to CMake options

-DCATKIN_DEVEL_PREFIX:PATH=/home/jonathan/catkin_ws/devel -DPYTHON_VERSION:STRING=3.8 -DCMAKE_PREFIX_PATH:PATH=/home/jonathan/catkin_ws/devel;/opt/ros/noetic