【发布时间】:2014-09-03 12:34:49
【问题描述】:
我的 python 在同一目录中找不到任何模块。 我究竟做错了什么? (python2.7)
所以我有一个目录'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()
仍然是 python 给了我
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 4, in <module>
ImportError: No module named hello
怎么了?
【问题讨论】:
-
你是如何执行脚本的?还有
import sys; sys.path的输出是什么@ -
试试
>>> import test -
@Casy_fill 您是否从目录运行程序,文件在哪里?对于导入,导入和导入的文件共享一个目录并不重要。重要的是,您的 Python 解释器已正确设置当前目录。
-
仔细检查您正在运行预期根目录中的文件。