0

I am a novice programmer and have ran into an issue trying to import a function I have written into another file. I think my issue probably has something to do with how my directory is set up. I run python in a jupyter notebook, and my directory looks something like this now:

-Desktop
   |
   -pythonCode
        |
        -leisure
            |
            -quadratics
                 |
                 -quadEquatSolver.ipynb
                 -_init_.ipynb
                 -problems.ipynb

I want to import the function quadSolver() from quadEquatSolver.ipynb into my problems.ipynb file. I have read a few solutions on this forum, but what I found either did not work for me, or was over my head.

I have tried

from quadEquatSolver import quadSolver

But I get an error message that states the module is not found.

I also have tried

from . quadEquatSolver import quadSolver

and

from .quadEquatSolver import quadSolver

But this gives me the same issue.

Any guidance would be greatly appreciated.

  • 2
    Possible duplicate of [ipynb import another ipynb file](https://stackoverflow.com/questions/20186344/ipynb-import-another-ipynb-file) – andrewgu Jul 25 '19 at 21:00
  • 2
    Possible duplicate of [How can I import from another ipython-notebook?](https://stackoverflow.com/questions/19564625/how-can-i-import-from-another-ipython-notebook) – ZiGaelle Jul 25 '19 at 21:05

2 Answers2

0

Have you tried eliminating the spacebetween the . and quadEquatSolver.

So

from .quadEquatSolver import quadSolver
MattFitz
  • 11
  • 1
0

If you read the first sentence in this link, you would realize that import simply doesn't assist in loading the file because you are dealing with python notebooks and not python files. Try using the steps given here

There is another way of using ipynb, so first install ipynb from your command prompt using following command: pip install import-ipynb

import import_ipynb
import quadEquatSolver
Trasha Dewan
  • 93
  • 1
  • 8