Python Forum
ModuleNotFoundError: No module named 'com' - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: ModuleNotFoundError: No module named 'com' (/thread-31433.html)



ModuleNotFoundError: No module named 'com' - aleksg - Dec-10-2020

Hello. I have a simple class and a simple test.
I've created packages com.my.pack and class My1.py
class My1:
      val1="ABC"
      val2=12345

      def init(self):
            print("init class My1")
And I've created class TestMy1.py
from com.my.pack import My1

class TestMy1:
      my1 = My1()
When I'm trying to run a test the exception occurs
Error:
from com.my.pack import My1 ModuleNotFoundError: No module named 'com':
What is the problem?


RE: ModuleNotFoundError: No module named 'com' - Larz60+ - Dec-10-2020

I don't know of any package named com.
perhaps you want pyserial? see: https://pythonhosted.org/pyserial/
Or, for async: https://pyserial-asyncio.readthedocs.io/en/latest/


RE: ModuleNotFoundError: No module named 'com' - Marbelous - Dec-10-2020

Where is the com module? Is it in the same directory as the main program or somewhere in the PYTHONPATH so your programs can find it?

Setting PYTHONPATH: https://www.techwalla.com/articles/how-to-set-your-python-path


RE: ModuleNotFoundError: No module named 'com' - MK_CodingSpace - Dec-10-2020

The code is questionable. Looks like you want to create an object from a class. It has nothing to do with modules.


RE: ModuleNotFoundError: No module named 'com' - deanhystad - Dec-10-2020

Python is complaining that it cannot find a module named com. When this happens to me it usually means the com.py module is not in the Python search path (use src.path to see this). I don't know what you mean by "I've created packages com.my.pack". Could you describe further please?


RE: ModuleNotFoundError: No module named 'com' - aleksg - Dec-12-2020

Thank you.
Actually, I'm Java developer. So, as usual, I have created the class in a certain package
package com.my.pack1
class MyClass {
}
Now I'm trying to utilize the same approach in Python.
So I've created the package 'com.my.pack1' and class 'MyClass' there.
I've created the test and trying to launch it. The structure of the project

http://prntscr.com/w17ee3
http://prntscr.com/w17h2m

Maybe some additional settings should be made?


RE: ModuleNotFoundError: No module named 'com' - aleksg - Dec-12-2020

When I test what packages are available from folder main it shows : ['TestPackage', 'com', 'package1', 'setup'] but not 'com.my.pack'.
http://prntscr.com/w18js9


RE: ModuleNotFoundError: No module named 'com' - aleksg - Dec-14-2020

(Dec-10-2020, 06:51 PM)Marbelous Wrote: Where is the com module? Is it in the same directory as the main program or somewhere in the PYTHONPATH so your programs can find it?

Setting PYTHONPATH: https://www.techwalla.com/articles/how-to-set-your-python-path

Thank you. But I need a portable code. Actually, it's a Gradle build. So all settings regarding paths should be configured inside of build and should not depend on settings of OS. Are there any solutions?


RE: ModuleNotFoundError: No module named 'com' - bowlofred - Dec-14-2020

You can add directories to the search path at runtime.

import sys
sys.path.append("/path/to/needed/location")
import other_module



RE: ModuleNotFoundError: No module named 'com' - Larz60+ - Dec-14-2020

You can use pathlib to keep your complete diretory structure relative to a project.
Cross platform safe.
see a former post here: https://python-forum.io/Thread-Automate-the-Boring-Stuff-with-Python-creating-a-path-works-but-only-for-CMD-promt?pid=131935#pid131935