ms-iot / vscode-ros

Visual Studio Code extension for Robot Operating System (ROS) development
https://marketplace.visualstudio.com/items?itemName=ms-iot.vscode-ros
MIT License
410 stars 95 forks source link

[bug] Python Unresolved Import Error for Catkin Workspace[bug] #299

Open cmuell89 opened 4 years ago

cmuell89 commented 4 years ago

general information Linux Mint 19.3 ROS Melodic ROS Extension v0.6.4

what is the bug None of my locally developed ROS Python packages built using catkin_make/catkin build are successfully resolved as imports despite the inclusion of python.autoComplete.extraPaths field in settings.json.

expected behavior I would hope to have my local ROS packages incorporated into the import tree for happy development.

additional context

Tested with jedi, Microsoft, and Pylance Language Servers. It appears that imports are working correctly with the jedi language server, but I know that VSCode has moved onto the Pylance Language Server.

The update path commands seem to be updateding my settings.json and c_cpp_properties.json correctly files within the .vscode directory. I have it setup such that .vscode exists at the sample level of src/ in my catkin workspace.

settings.json

{
    "python.autoComplete.extraPaths": [
        "/home/carl/cairo/sawyer_ws/devel/lib/python2.7/dist-packages",
        "/opt/ros/melodic/lib/python2.7/dist-packages"
    ],
    "ros.distro": "melodic",
    "python.pythonPath": "/usr/bin/python",
    "python.linting.pylintEnabled": false,
    "python.linting.enabled": true,
    "python.linting.flake8Enabled": true
}
cmuell89 commented 4 years ago

Could be related to: https://github.com/microsoft/vscode-python/issues/13357

cmuell89 commented 4 years ago

Many users of ROS still use Python 2.7. Pylance Language Server does not support Python 2.7 syntax and the linking and path updates inside the init.py of your built ROS packages in devel/lib/python2.7/dist-packages directory fails to parse correctly.

I think it would be worth documenting this. Switching to Jedi language server works correctly.

BRNKR commented 4 years ago

How did you fix it?

In Settings (UI) i have set the language server to Jedi. Thats it? Doesnt work for me.

cmuell89 commented 4 years ago

Yea Jedi seems to work for me out of the box. Not sure what else to recommend.