Import 3rd party module in SublimeREPL

回眸只為那壹抹淺笑 提交于 2019-12-11 03:59:45

问题


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?


回答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



来源:https://stackoverflow.com/questions/22058396/import-3rd-party-module-in-sublimerepl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!