Pythonは同じフォルダ内のモジュールを見つけることができません 質問する

Pythonは同じフォルダ内のモジュールを見つけることができません 質問する

私の Python はどういうわけか同じディレクトリ内のモジュールを見つけることができません。何が間違っているのでしょうか? (python2.7)

つまり、ディレクトリ '2014_07_13_test' が 1 つあり、その中に次の 2 つのファイルがあります。

  1. テスト
  2. こんにちは

ここで、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

どうしたの?

ベストアンサー1

test.py のインポートを次のように変更します。

from .hello import hello1

おすすめ記事