Pycharm 2016.2.3,Mac OS X 10.11.1,Python 3.5(Homebrew);導入語句適用於PyCharm,但不適用於終端
我有這樣的文件夾結構
project
/somepackage
/subpackage
__init__.py
bar.py
__init__.py
foo.py
foo.py:
import somepackage.subpackage.bar
print("foo")
bar.py:
print("bar")
所以我的預期輸出是
bar
foo
從PyCharm運行時也能正常工作。然而,當我從我的終端上運行它,我得到一個ImportError:
$ pwd
$ /home/project (not the actual path; just omitting some personal stuff)
$ python3.5 somepackage/foo.py
File "foo.py", line 1, in <module>
import somepackage.subpackage.bar
ImportError: No module named 'somepackage'
我發現this question,大約是同樣的問題。然而,沒有一個建議的解決方案適用於我,因爲我確實使用了與PyCharm相同的Python解釋器,我目前位於包含somepackage/
文件夾的文件夾中。
有沒有人有任何其他建議如何解決這個問題?非常感謝你!
你somepackage有一個'__init __。py'文件嗎?這表明python是包 – Mitta
是的。我會編輯我的問題,謝謝! – Pibborn