Python Forum
No module found when I run a main.py
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
No module found when I run a main.py
#1
I have info.py file in directory A

info.py has this code:
import country # country is imported from the same directory A

class Person:
    def get_city(self):
        return country.state()
Then i have a main.py that is not in directory A
main.py has this code:
from A.info import Person

person_instance = Person()
print(person_instance.get_city())
Then I will get module country not found error,
but if I instanciate the Person class in the same directory A or copy the country.py to the main.py directory it will work fine

How can I make the import of country work as I'm calling Person class in main.py that is in another directory?
the code here is just for explanation purpose only.

Your answers is highly appreciated in advance!
Reply


Messages In This Thread
No module found when I run a main.py - by tomtom - Jul-20-2022, 07:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pyside6 module not found ForeverNoob 4 1,712 Aug-18-2023, 04:36 PM
Last Post: snippsat
  Module Not Found Error bitoded 4 1,563 Jan-01-2023, 09:08 AM
Last Post: bitoded
  pdfminer package: module isn't found Pavel_47 25 9,889 Sep-18-2022, 08:40 PM
Last Post: Larz60+
  Module not found question sighhhh12 0 1,586 Sep-09-2022, 05:43 AM
Last Post: sighhhh12
  [SOLVED] Tkinter module not found Milan 7 28,719 Aug-05-2022, 09:45 PM
Last Post: woooee
  No Module found in other directory than source code [SOLVED] AlphaInc 1 2,173 Nov-10-2021, 04:34 PM
Last Post: AlphaInc
  Error when refering to class defined in 'main' in an imported module HeRo 2 2,509 Apr-13-2021, 07:22 PM
Last Post: HeRo
  KafkaUtils module not found on spark 3 pyspark aupres 2 7,613 Feb-17-2021, 09:40 AM
Last Post: Larz60+
  'urllib3' Module not found when import 'requests' spanz 5 10,749 Jan-06-2021, 05:57 PM
Last Post: snippsat
  no module named finbert found ErnestTBass 4 4,799 Dec-05-2020, 06:09 PM
Last Post: andrianas

Forum Jump:

User Panel Messages

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