2

So I am learning to use SublimeREPL, and I encounter a problem.

I have a main.py file, and in the same folder a timer.py. I write import statement in the main.py:

import timer

Then if I open

1) SublimeREPL --> Python --> Python--IPython, and transfer the code to the InteractiveConsole, I get error:

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "<string>", line 1, in <module>
ImportError: No module named timer

2) SublimeREPL --> Python --> Python, and transfer the code to the REPL console, it runs as expected.

I wonder what is the reason?

Jonathan
  • 8,453
  • 9
  • 51
  • 74
Lelouch
  • 2,111
  • 2
  • 23
  • 33

1 Answers1

1

This is because the sys.path doesn't contain the given directory. You can edit this through the code below

import os
import sys

sys.path.append(os.getcwd()) 
# os.getcwd() is the current directory, make sure it's the right one. 

This will make it possible to import timer.py

Jonathan
  • 8,453
  • 9
  • 51
  • 74