Ask Your Question

ROS Python Module - Autocompletion doesn't work when self-compiled

asked 2020-01-10 01:49:33 -0500

TobiMiller gravatar image


i have written a package with an python module in it. I can import it in my other packages but VSCode cannot autocomplete functions.

from <ros_python_module> import <class>

when i click on <ros_python_module>, it goes into an autogenerated "_" inside of my devel folder. There is no code from me.

# -*- coding: utf-8 -*-
# generated from catkin/cmake/template/
# keep symbol table as clean as possible by deleting all unnecessary symbols

Is it possible that catkin build makes a copy of the files and moves them into the devel folder?

Example: moveit_commander -> from package manager i can autocomplete inside vscode --> compiling by myself and it doesnt autocomplete

edit retag flag offensive close merge delete


VSCode needs to know where the actual code is. You probably need to edit the configuration file of VSCode or use a plugin that knows where to look for python code in ROS packages and does this for you. Copying the files to where VSCode is now looking doesn't sound like a good idea.

davekroezen gravatar image davekroezen  ( 2020-01-10 09:07:46 -0500 )edit

VSCode knows the PYTHONPATH but how i said, catkin compiles an auto generated init py which is not introspecteable :/

TobiMiller gravatar image TobiMiller  ( 2020-01-11 04:37:02 -0500 )edit

Hi Tobi, I'm having the same problem: even though import works, I can't get autocomplete on my IDEs (PyCharm or VSCode) for my custom source modules. I'm wondering if you found a solution for this?

vbs gravatar image vbs  ( 2020-09-30 13:22:05 -0500 )edit

@vbs you have to add the folder to your vscode settings.json. "python.autoComplete.extraPaths"

TobiMiller gravatar image TobiMiller  ( 2020-10-01 02:03:25 -0500 )edit

Is that the package folder? I added it like this but made no difference: "python.autoComplete.extraPaths": [ "/home/vbs/catkin_ws/src/test_python_import/src/test_python_import" ]

vbs gravatar image vbs  ( 2020-10-01 05:20:40 -0500 )edit

extraPaths should point to the folder that contains a folder with file. In my case it was:

"python.analysis.extraPaths": [
dcardenasn gravatar image dcardenasn  ( 2021-09-28 14:00:29 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2020-03-17 07:53:29 -0500

tonyp gravatar image

You can create a .env file with a PYTHONPATH variable with all the source paths in it, then reference this file from the python.envFile setting in VS code. This path will only be used by the python extension tools and not by the terminal. In this way when running from the terminal you are still running in a "deployed" situation from devel but the tools can still find the source files. It isn't the prettiest but it is a work around.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2020-01-10 01:49:33 -0500

Seen: 675 times

Last updated: Jan 10 '20