ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS melodic import error "No name hello in module XXXXX" in VScode

asked 2020-04-03 05:12:28 -0600

Ale_Palu gravatar image

updated 2020-04-03 07:02:24 -0600

Hi there!

I was trying to create a proper structure for my ROS project in python, following this guide: http://wiki.ros.org/rospy_tutorials/T...

I successfully got to the end of the tutorial and ran my "hello" script correctly, that printed the message "Hello my friend!"

My question is about VScode. In fact, opening the working "hello" script, located in my_package/bin, gives me this import error in VScode and i can not figure out why...

No name 'hello' in module 'XXXX' pylint(no-name-in-module)
Unable to import 'XXXXX.hello' pylint(import-error)

I have installed the ROS extension as this page said http://wiki.ros.org/IDEs, but nothing changed...

This is not a problem right now, because the script, ran by terminal, works fine, but in a future where my code will be more complex, this VScode issue could be very annoying.

I am not posting my code because it's the same of the link above.

I am new to ROS and i cannot understand why i got this problem, can someone help me?

Thanks a lot

edit retag flag offensive close merge delete

Comments

First stop for all IDE related questions would be wiki/IDEs, specifically, the VSCode section.

Not claiming this will solve all your problems, but please take a look there first.

gvdhoorn gravatar image gvdhoorn  ( 2020-04-03 06:10:44 -0600 )edit
1

not quite sure if this solves the problem. however, I've found the VScode plugin does not automatically always pick up the right paths.

What I've found to work quite well is:

  1. create a "ROS workspace" with in VScode with the respective plugin.
  2. source the ros workspace in the built-in terminal
  3. call "ROS: Update Python Path" and "ROS: Update C++ Properties" in VScode, especially after adding new packages.
mgruhler gravatar image mgruhler  ( 2020-04-03 08:36:36 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-09-30 03:55:02 -0600

F1iX gravatar image

updated 2020-10-01 02:16:48 -0600

As discussed here, the following is needed:

  1. Place your module in <ws>/src/<pkg-name>/src/<pkg-name>
  2. Create an empty file <ws>/src/<pkg-name>/src/<pkg-name>/__init__.py
  3. Create <ws>/src/<pkg-name>/setup.py with

    from distutils.core import setup from catkin_pkg.python_setup import generate_distutils_setup

    setup_args = generate_distutils_setup() setup_args['packages'] = ['<pkg-name>'] setup_args['package_dir'] = {'': 'src'}

    setup(**setup_args)

  4. Add catkin_python_setup() to <ws>/src/<pkg-name>/CMakeLists.txt
  5. Build workspace with catkin_make
  6. Open <ws> in VS Code with ROS and Pylint extensions installed
  7. Add src/<pkg-name>/src to "python.autoComplete.extraPaths" in <ws>/.vscode/settings.json

You can then from <pkg-name>.<module-name> import <your-content> from any node script (e.g. <ws>/src/<pkg-name>/scripts/mynode)

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-04-03 05:12:28 -0600

Seen: 1,412 times

Last updated: Oct 01 '20