0

I have the following code all in a file named baz.py

# foo.py
class Foo:
    def __init__(self,foo):
        self.foo = foo

# bar.py
class Bar:
    def __init__(self,bar):
        self.bar = bar
    # some functions

# baz.py
# calling some functions from Bar

I would like to organize my project in the following manner:

project|-model|-foo.py
              |-bar.py
              |-__init__.py
       |-test |-baz.py
       |-__init__.py

And run baz.py

To do so I added at the top of baz.py the following

from project.model import foo, bar

However I get the error "No module named project" when using

C:\...\project> & C:/Python39/python.exe "c:/.../project/test/baz.py"
Meth
  • 203
  • 1
  • 7
  • Does this answer your question? [Relative imports for the billionth time](https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time) – Jorge Luis Mar 15 '23 at 10:49

1 Answers1

2

It seems that you're running the script with project as your working directory, and python does not find a directory named project inside of project. Have you tried to modify your line to:

from model import foo, bar

Since model is inside the project directory. Or you can call the function from the parent directory of project.