我的python以某種方式無法在同一目錄中找到任何模塊。 我在做什麼錯? (python2.7)Python無法在同一個文件夾中找到模塊
所以我有一個目錄 '2014_07_13_test',有兩個文件在裏面:
- test.py
- hello.py
其中hello.py:
# !/usr/local/bin/python
# -*- coding: utf-8 -*-
def hello1():
print 'HelloWorld!'
和test.py:
# !/usr/local/bin/python
# -*- coding: utf-8 -*-
from hello import hello1
hello1()
不過蟒蛇給我
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 4, in <module>
ImportError: No module named hello
有什麼不對?
你是如何執行腳本模塊的頂部將這個?另外什麼是輸入sys的輸出; sys.path' – Salem
嘗試'>>> import test' – martineau
@Casy_fill您是否從目錄運行程序,其中存在哪些文件?對於導入來說,導入和導入的文件共享一個目錄並不重要。重要的是,你的Python解釋器已經正確設置了當前目錄。 –