I am currently trying to use pydev for my ROS project (I am using pydev because I use eclipse for c++) Now I have some issues with importing some modules. The current structure looks like this:
src
package_name
__init__.py
src
__init__.py
package_name
my_file.py
__init__.py
scripts
my_module.py
__init__.py
I used the catkin_ws as my project root wth the src folder as the sourcefolder for pydev. When I want to import a module e.g. my_module from my_file I have to use (that's what eclipse says)
from package_name.scripts.my_module import XYZ
This works fine if I am running my_file in pydev but it does not work from the console (e.g. rosrun or python3 my_file.py). How would I have to import my_module in this case and how does pydev recognize this as correct??
Another thing when I try to import my_module from another python script in the scripts folder I would assume that using
from my_module import XYZ
would work fine ( it does using the console as well as using pydev run) but eclipse still marks it as an error. How can I fix this?
Thank you
This means that the wrong folder is set as the source folder for Python code.
You probably have /src
as the source folder and you should probably have /src/package_name/src
and src/scripts
set in the PYTHONPATH -- Still, note that I'm not completely sure as the structure of the package seems a bit strange... for instance, why do you have an __init__.py
right under the /src
folder? (that seems wrong...)
Note: source folders are the folders added to the PYTHONPATH
. See: http://www.pydev.org/manual_101_project_conf2.html for details.