1

I want to import functions in Python 3.8 from a subfolder. This is what worked for me in earlier versions but does not seem to work now:

Folder structure:

/MainProject
  runFile.py 
    /Folder1
      pyscript.py
      __init__.py

Run runFile.py from MainProject directory:

from Folder1.pyscript    import function

I also tried

from Folder1 import pyscript1 

I get the following error:

"ModuleNotFoundError: No module named 'Folder1.pyscript'; 'Folder1' is not a package"
Clemetti
  • 63
  • 1
  • 5

1 Answers1

1

In your __init__.py, you should have this

# encoding: utf-8

# this is a namespace package
try:
    import pkg_resources
    pkg_resources.declare_namespace(__name__)
except ImportError:
    import pkgutil
    __path__ = pkgutil.extend_path(__path__, __name__)
Pepe Lucho
  • 129
  • 5