How to import ros to PyCharm

2019-07-27 14:43发布

问题:

I am developing a robot using the ros framework. As ide, I use PyCharm. But I can’t import ros into it. On the ros site there is the article about ide http://wiki.ros.org/IDEs. There is information about using ros with pycharm. I have to modify the .desktop file, but I installed PyCharm using a snap from the software center. Where can I find the .desktop file for snap applications? Can there be another method to import ros into PyCharm?

Edit: @hug Yes, I launched this command here is the result

/snap/pycharm-community/103/meta/gui/pycharm-community.desktop
/snap/pycharm-community/103/snap/gui/pycharm-community.desktop
/var/lib/snapd/desktop/applications/pycharm-community_pycharm-community.desktop
/var/tmp/pycharm-community.desktop.swp

I think that the .swp file has remained since the last reinstallation of PyCharm. I reinstalled when I tried to do it myself and realized that I had broken the program.

回答1:

If you want to use from the auto-suggestion with ROS packages in Pycharm IDE, you could do the following instructions:

  1. File > Settings (or Ctrl+Alt+s as shortcut)> Project: > Project interpreter.

  2. In the project interpreter dropdown list, you can specify ROS Python interpreter by selecting the appropriate from the list.


[NOTE]:

You could add a virtual environment with the above instructions, then you should add ROS distpackages (roslib) on it with this instruction.

ROS distpackages path that you need: /opt/ros/kinetic/lib/python2.7/distpackages



回答2:

If anyone else is struggling with getting PyCharm intellisense and autocomplete to work with your own ros python packages, this answer was very illuminating.

Basically PyCharm does not dynamically interpret the devel/ space __init__.py for your packages, so at runtime the packages are available, but no intellisense in PyCharm. Changing the Project Structure settings to add your <package>/src as a Source folder solved the issue for me. Bit of a pain, but hey, intellisense is back!