Skip to content

Setup (Pycharm)

Shahryar Rajabzadeh edited this page Apr 19, 2022 · 31 revisions

Pycharm Professional

Auto Sync using settings repository
Python Intepreter
  • Use the System Intepretor
    • Go to File > Setting > Project Interpreter > Add > System Intepreter and choose /usr/bin/python3.8
    • 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 (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
  • Use the docker-compose Intepretor
    • Go to File > Setting > Project Interpreter > Add > Docker Compose
      • choose the docker-compose.yaml file
      • choose service as friendly
      • choose python interpreter path as /usr/bin/python3.8
    • 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
      /usr/lib/python3.8
      /usr/local/lib/python3.8/dist-packages
      /usr/lib/python3/dist-packages
      /opt/ros/noetic/lib/python3/dist-packages
      /root/catkin_ws/devel/lib/python3/dist-packages
    • Under path mappings, add the path mapping
      /home/$USER/catkin_ws -> /root/catkin_ws
      
Optional
  • Install the *.launch file plugins. Look up duckietown/hatchery from the third party repositories in Preferences/Plugins
Debugging in the container
  • 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 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
    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