I recently installed PyCharm 2019 professional edition in Windows 10. I created a new Project 'Sample' and two files 'file1.py' and 'file2.ipynb'. I have installed jupyter notebook from the chosen python interpreter.
- class Foo is defined in file1.py
- I then import file1.py into file2.ipynb to use Foo
Here, I encounter a strange error. 2019 professional edition has local notebook server installed in it.
from file1 import Foo
I ran the above code sample in a cell both in editor inside PyCharm IDE as well as in browser, after turning on the jupyter server on localhost.
For some reason, the code sample throws out import error problem in IDE but runs smoothly in browser. I tried looking if there are any issues with project path but couldn't figure out the reason yet. Anyone encountered this before ?
os.getcwd() helped me understand the problem. The jupyter notebook editor is running under Main directory 'Sample'. Whereas my files are in 'Sample/Resource/file1.py', 'Sample/Resource/file2.ipynb' .
Now If I import using the following commands in file2.ipynb file, it worked:
Thank you very much for the help @Vishal @IonicSolutions