0

i have a project structure like this:

python-modinfo
|--funcs
   |--__init__.py
   |--funcs.py
|--modules
   |--File-Operations
      |os_info.py

This is __init__.py:

from funcs.funcs import *

This is os_info.py:

import funcs.funcs

and this is terminal output:

Traceback (most recent call last):
  File "os_info.py", line 1, in <module>
    import funcs.funcs
ModuleNotFoundError: No module named 'funcs'

What is my mistake while creating a python package

deceze
  • 510,633
  • 85
  • 743
  • 889
Hapalua
  • 13
  • 4
  • What command are you running? Maybe this helps (in particular point #4): https://sinoroc.gitlab.io/kb/python/python_imports.html – sinoroc Dec 21 '20 at 17:19

2 Answers2

0

Try the __init__.py as from . import funcs as the funcs.py Is In Current Directory

Also try the same data in os_info.py

namgold
  • 1,009
  • 1
  • 11
  • 32
Akash Pattnaik
  • 83
  • 1
  • 13
  • i have tried to write from . import funcs in __init__.py but i have gotten the same error and i am running os_info.py – Hapalua Dec 21 '20 at 09:46
0

If you are just looking for a quick solution, do this in os_info.py:

import sys
sys.path.append('../../funcs')

from funcs import *

os_info.py won't know where funcs.py is located, therefore you need to tell it by providing the location.

blessthefry
  • 121
  • 7
  • thank you , it has worked but what does __init__.py file do if we can do it like this – Hapalua Dec 21 '20 at 09:54
  • To answer your question, I think this [link](https://stackoverflow.com/questions/17779459/python-init-py-vs-sys-path-append-insert) explains it quite well. – blessthefry Dec 21 '20 at 17:04