我認爲自己是python中的中間用戶,這是一個新的用戶。在Linux上測試IDLE(Python 3.2.3)中的代碼。這裏是整個腳本:IDLE中的導入錯誤
Python 3.2.3 (default, Apr 10 2013, 05:29:11)
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
==== No Subprocess ====
>>> from os import listdir, getcwd, chdir
>>> chdir('Documents/matrix')
>>> getcwd()
'/home/bradfordgp/Documents/matrix'
>>> listdir('.')
['__init__.py', 'vec.zip', 'hw1.pdf', 'politics_lab.pdf', 'submit_hw1.py', 'submit_politics_lab.py', 'test_vec.py', 'Week1', 'Week0', 'python_lab.py~', 'Week2', 'vec.pdf', '__pycache__', 'hw1.zip', 'politics_lab.zip', 'voting_record_dump109.txt', 'my_stories.txt~', 'hw1.py', 'politics_lab.py', 'submit_vec.py', 'vec.py']
>>> from vec import Vec
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
from vec import Vec
ImportError: No module named vec
>>>
我已經瀏覽到正確的目錄,而我從同一目錄導入和vec.py存在。爲什麼不在本地目錄中查找文件?從終端窗口命令行運行此腳本可正常工作。
對此提出建議?
查看[** this **](http://stackoverflow.com/questions/279237/import-a-module-from-a-relative-path)以獲取更多詳細信息和解答 – Adil