3

I'm in the ipython shell and can't import a function from other file. When I try:

from my_functions import this_function 

I got:

No module named my_functions

But if I try the save from other file it works.

Yes, I opened the shell in the same directory of my_functions file.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Luis Ramon Ramirez Rodriguez
  • 9,591
  • 27
  • 102
  • 181

1 Answers1

0
import sys
sys.path.append('my/path/to/module/folder')

solved the problem.


This answer was posted as an edit to the question Calling a Python function from another file in ipython by the OP Luis Ramon Ramirez Rodriguez under CC BY-SA 3.0.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
  • 1
    The better solution is to install your code in a way that doesn't require modifying `sys.path` at runtime. Use a virtual environment, and package your code so that it can be installed in a virtual environment using `pip` or some other tool. – chepner Dec 11 '22 at 16:45