Python Forum
ModuleNotFoundError: No module named 'com'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ModuleNotFoundError: No module named 'com'
#1
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?
Reply
#2
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/
Reply
#3
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-t...ython-path
Reply
#4
The code is questionable. Looks like you want to create an object from a class. It has nothing to do with modules.
Reply
#5
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?
Reply
#6
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?
Reply
#7
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
Reply
#8
(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-t...ython-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?
Reply
#9
You can add directories to the search path at runtime.

import sys
sys.path.append("/path/to/needed/location")
import other_module
aleksg likes this post
Reply
#10
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-...#pid131935
aleksg likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  no module named 'docx' when importing docx MaartenRo 1 706 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Problem with pymodbus - ModuleNotFoundError: No module named 'pymodbus.client.sync' stsxbel 2 22,938 Nov-02-2023, 08:20 AM
Last Post: South_east
  ModuleNotFoundError: No module named 'requests' Serg 18 2,158 Oct-29-2023, 11:33 PM
Last Post: Serg
  Resolving ImportError: No module named gdb (Python in C++) mandaxyz 3 1,310 Oct-04-2023, 02:43 PM
Last Post: mandaxyz
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 1,389 Aug-07-2023, 05:32 AM
Last Post: DPaul
  ModuleNotFoundError: No module named 'eyed3' Wimpy_Wellington 2 1,223 Jul-10-2023, 03:37 AM
Last Post: Wimpy_Wellington
  How to fix this error: ModuleNotFoundError: No module named 'notears' yaoyao22 2 961 Jul-09-2023, 11:24 AM
Last Post: yaoyao22
  Help with pyinstaller "No module named" korenron 9 8,198 Jun-15-2023, 12:20 PM
Last Post: snippsat
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 932 May-15-2023, 02:38 PM
Last Post: tonynapoli2309
  ModuleNotFoundError: No module named 'omsdk.sdkproto' donvito7 4 1,769 Oct-20-2022, 02:56 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020