0

I know similar questions have been asked many, many, many, many times.

I read them thoroughly and tried plenty of solutions but apparently I can't find a way to make it work for me. So I believe this question is not a duplicate.

I have the following structure:

+ C:\etc.\etc.\maindir   <---Root Directory
|     mymainfile.py
|     __init__.py        <---this is empty
+     \AuxFun            <--- Subfolder
|         __init__.py    <---this contains: "from . import *"
|         myauxfun1.py
|         myauxfun3.py

Now, inside my main (mymainfile.py) I have:

from AuxFun.myauxfun1 import AuxFun1
import AuxFun.myauxfun3 as AuxFun3

each myauxfun consists of a single function :

def fun()
...
return output

The script works perfectly on jupyter notebook 5.6.0 with Python 3.7 (and IPython 6.5)

However it doesn't work on Spyder 3.3.1 with Python 3.7.

and when trying to import, the console returns:

ModuleNotFoundError: No module named 'AuxFun'

I originally tried without any __init__.py file and with a totally empty __init__.py in the subfolder.

I also tried the following:

from AuxiliaryFunctions import *
from .AuxFun.myauxfun1 import AuxFun1
import KR.AuxFun.myauxfun2 as AuxFun2

which return respectively:

ModuleNotFoundError: No module named 'AuxiliaryFunctions'
ModuleNotFoundError: No module named '__main__.AuxiliaryFunctions'; '__main__' is not a package
ModuleNotFoundError: No module named 'KR'

Interestingly (for me) the autocompletion recognizes the folder and files.
i.e. if I type: ".⇥ Tab" the AuxFun subfolder appears.
Alike, typing ".AuxFun.⇥ Tab" will display all the auxfun scripts within the subfolder.

CAPSLOCK
  • 6,243
  • 3
  • 33
  • 56
  • Your init files have the wrong name. They need to be named `__init__.py`, not `__init.py__` – Carlos Cordoba Jun 03 '19 at 13:08
  • Also, if you want this to work in Spyder, you need to define a project for your work placed in `C:\etc.\etc.\maindir`. You can create a new project by going to the menu `Projects > New project`. – Carlos Cordoba Jun 03 '19 at 13:10
  • @CarlosCordoba the `__init__.py` are named correctly, that was a typo. I just fixed it. I'll check if that solves it but I verified that `cd` returns the correct path already (`C:\etc.\etc.\maindir`), so I am not sure this will fix it. – CAPSLOCK Jun 03 '19 at 13:24

0 Answers0