0

I im using Git bash to open jupyter lab and a notebook file. I want to import a file such as test.py, with a function such as test_func(x). The test.py is in another folder then the working directory. using pwd in the notebook i get something like "C:\Users\Documents\Code_folder\". I have added the path of the test.py using sys.path.insert(1, "C:\Users\Code\), where the test.py is located.

I then have no issues with importing the module, but if i add another module, test_func2(y), and i say run test.test_func2??, i cant find the function, and when running test.test_func??, i see that the output on line: File: "c:\users\code\". I belive is the lower case of the File that gets me the missing module.

Why does this happen, and can i change it in a simple say without changing all my codes?

Edit: test_func2 is another function in test.py

Keweik
  • 187
  • 1
  • 9
  • Do you mean another function (not module?) for test_func2(y)? Where is that located? Try sys.path.append("C:/Users/Code") (you can use forward slashes in your python code it works on windows too) – AbdurRehman Khan Oct 15 '19 at 08:46
  • i mean another function, not module, sorry. – Keweik Oct 15 '19 at 08:48
  • Try sys.path.append and let me know if it's still not working, also what is the exact import statement that you are using? – AbdurRehman Khan Oct 15 '19 at 08:50

1 Answers1

1

This may simply be an issue with how you're importing. I'm not sure of the internal mechanics of Jupyter, but in a terminal window if you change the module it has to be reloaded (reimported.) In Python3 the reload was moved to the imp module.

See stackoverflow:How do I unload (reload) a module?

For Jupyter, I assume you have the import test.py in a previous window. If you add a function to a .py file, just go back to that window and rerun the import...although I'm not sure that will guarantee a reload (since just re-running the command import test.py in the terminal Python would not work.)

RightmireM
  • 2,381
  • 2
  • 24
  • 42