Cannot import .msg files from another folder (python) [closed]

asked 2021-11-25 03:53:07 -0600

WarTurtle gravatar image

updated 2022-01-31 09:45:41 -0600

lucasw gravatar image

Hello,

I have the following structure:

Package
|__"src"
   |__"node.py"
|__"msg"
   |__"message.msg"
   |__"__init__.py"

I want to access the message.msg in the node.py, but when I try to import it, I get the pylance error

Import "msg.msg" could not be resolved

I tried

from msg.msg import message.msg
from package.msg import message.msg

import sys
sys.path.append(~/workspace/src/package/msg) #with and without the ~
sys.path.append(package/msg)

And none of it works.

I followed the Creating A Message tutorial and added all the relevant dependencies in the package.xml and CMakeLists.txt, and everything also compiles fine. The __init__.py is empty

Am I messing up the path?

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by gvdhoorn
close date 2021-11-25 04:13:26.310214

Comments

I'm closing this as a duplicate of #q270568.

That question discusses a similar problem, and I believe the solution offered there should also help you.

If you don't agree, or something is still unclear, edit your question here to clarify why/what doesn't work for you.

gvdhoorn gravatar image gvdhoorn  ( 2021-11-25 04:13:04 -0600 )edit

Please do not delete questions if they are duplicates and have references to what they are duplicates of.

It's perfectly valid to keep your question around. We should just avoid posting duplicate answers.

gvdhoorn gravatar image gvdhoorn  ( 2021-11-25 04:37:42 -0600 )edit