Search code examples
python-3.xpydev

eclipse pydev cannot find my package when trying to run a module


I am having issues with Eclipse's pydev not finding my package when trying to run my code. The layout of my project is my_project > src > my_package > modules.py The PYTHONPATH for the project includes the my_project > src and I have no problems running my tests. However when I try to run I get the message:


Traceback (most recent call last):
  File "/Users/gturek/dev/git/moniqua_maps/src/moniqua_maps/moniqua_maps.py", line 11, in <module>
    from moniqua_maps.Resources import Resources
  File "/Users/gturek/dev/git/moniqua_maps/src/moniqua_maps/moniqua_maps.py", line 11, in <module>
    from moniqua_maps.Resources import Resources
ModuleNotFoundError: No module named 'moniqua_maps.Resources'; 'moniqua_maps' is not a package


I am stumped.

Changing setting in Eclipse as suggested (launching with python -m) results in a slightly different error message

traceback (most recent call last):
  File "/Users/gturek/miniforge3/envs/mmaps/lib/python3.10/runpy.py", line 187, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/Users/gturek/miniforge3/envs/mmaps/lib/python3.10/runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
  File "/Users/gturek/dev/git/moniqua_maps/src/moniqua_maps/moniqua_maps.py", line 11, in <module>
    from moniqua_maps.Resources import Resources
ModuleNotFoundError: No module named 'moniqua_maps.Resources'; 'moniqua_maps' is not a package

enter image description here


Solution

  • Please include your full error.

    Also, how do you run it in the command line?

    If the issue is that you have relative imports, one thing that may make a difference is that you may want to launch with python -m when running from inside PyDev (you need to turn on the `Launch modules with "python -m mod.name" instead of "python filename.py").

    Launch with python -m