0

I am importing lots of packages into other packages. The imported packages can be executed without any problems, as I used Python installers and the right structure. But the linking in VS code is not working, Pylance is giving me import errors.

I have a workspace called happyspace. The path to the dist-packages is

/home/flo/happyspace/devel/lib/python3/dist-packages

so I added this to my workspace config:

{
    "folders": [
        {
            "path": "."
        }
    ],
    "settings": {
        "editor.fontSize": 15,
        "[python]": {
            "editor.defaultFormatter": "ms-python.autopep8"
        },
        "python.formatting.provider": "none",
        "editor.defaultFormatter": null,
        "python.autoComplete.extraPaths": [
            "/home/flo/happyspace/devel/lib/python3/dist-packages",
            "/opt/ros/noetic/lib/python3/dist-packages"
        ],
        "python.analysis.extraPaths": [
            "/home/flo/happyspace/devel/lib/python3/dist-packages",
            "/opt/ros/noetic/lib/python3/dist-packages"
        ]
    }
}

however, upon imports of one package into another, like for example in my in execute_poses_record.py located in

/home/flo/happyspace/src/fmp_tools/src/fmp_tools/execute_poses_record.py

the line

from fmp_tracepen_node.tracepen_node import TracepenNode

gets the error

Import "fmp_tracepen_node.tracepen_node" could not be resolvedPylancereportMissingImports (module) fmp_tracepen_node

while the file to be imported sits in

/home/flo/happyspace/src/fmp_tracepen_node/src/fmp_tracepen_node/tracepen_node.py

I JUST REALIZED A THING!

Changing the import structure from

from fmp_tools.console_messager import ConsoleMessager

to

from fmp_tools.console_messager.src.console_messager import ConsoleMessager

the import error is gone.

But then I can no longer import the packages in python and get real import errors:

from fmp_tools.src.fmp_tools.console_messager import ConsoleMessager ModuleNotFoundError: No module named 'fmp_tools.src'

Also when I add "/home/flo/happyspace/src/fmp_tools/src" to my pyhton paths it resolves the pylance error.

/home/flo/happyspace/src/fmp_tools/src/fmp_tools/console_messager.py is also the structure to the python files of my ros packages.

I heard that one should configure packages like this, and then construct a setup.py like this

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

d = generate_distutils_setup(
    packages=['fmp_tools'],
    package_dir={'': 'src'}
)

setup(**d)

Is this wrong?

help is greatly appreciated.

1 Answers1

1

Add the following configuration:

    "python.analysis.extraPaths": [
        "/home/flo/happyspace/src/fmp_tracepen_node/src"
    ],
JialeDu
  • 6,021
  • 2
  • 5
  • 24
  • I did. Still have this stupid pylance error. – Florian Schneider Aug 01 '23 at 20:19
  • { "python.formatting.provider": "none", "python.autoComplete.extraPaths": [ "/home/flo/happyspace/devel/lib/python3/dist-packages", "/home/flo/ws_moveit/devel/lib/python3/dist-packages", "/opt/ros/noetic/lib/python3/dist-packages" ], "python.analysis.extraPaths": [ "/home/flo/happyspace/devel/lib/python3/dist-packages", "/home/flo/ws_moveit/devel/lib/python3/dist-packages", "/opt/ros/noetic/lib/python3/dist-packages" ] } – Florian Schneider Aug 01 '23 at 20:19
  • you did it? Is your setup the same as in the answer?It seems different. /(ㄒoㄒ)/~~ – JialeDu Aug 02 '23 at 07:16