Python3 - Trying to import module from other folder with sys not working. How to fix it?

Viewed 21

I'm using Python3 on Windows. I have the following file structure:

enter image description here

This is the folder path when I copy it from windows:

D:\5 - Coding\Back-end\CreateGames\kato_utils 

I'm trying to import the full module:

kato_utils.py

into:

main.py

But it does not work. Here are the path I tried in my main.py but none works:

import sys
sys.path.insert(1, "D:/5 - Coding/Back-end/CreateGames/kato_utils")
# sys.path.insert(1, "D:\5 - Coding\Back-end\CreateGames\kato_utils")
# sys.path.insert(1, "D:\\5 - Coding\\Back-end\\CreateGames\\kato_utils")
import kato_utils
from kato_utils import kato_utils

How to import kato_utils.py or any of his functions into my main.py?

1 Answers

if you put an __init__.py file inside the kato_utils folder you wouldn't have to worry about using the sys.path you could just use

from kato_utils import kato_utils 

As it stands now this:

import kato_utils 

should work and the second from

kato_utils .... 

is unnecessary

Related