0

I have created utils.py and constant.py (saved in the same folder of all src file) and I wrote this in main.py

import utils
import constant

but when I try to run the entire program it gives me this error:

Unable to import 'utils'

and if I open utils.py I noticed this error:

Unable to import 'constant'

(because I need constant also in utils.py)

How can I solve it?

2 Answers2

3

You can try this from . import utils and have a look at this Relative imports for the billionth time

try this one:

import sys

sys.path.append("<path/to/project>")

import utils

Or

from .utils import *

python_user
  • 196
  • 1
  • 5
  • 15
1

The correct way of importing functions from another file is done like this:

from file_name import function_name

If you want to import everything you should do this:

from file_name import *
Ahmad Moussa
  • 876
  • 10
  • 31