Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top