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

3
  • 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) Commented Oct 15, 2019 at 8:46
  • i mean another function, not module, sorry. Commented Oct 15, 2019 at 8: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? Commented Oct 15, 2019 at 8:50

1 Answer 1

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.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.