import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
但是现在我遇到了这个错误。我正在使用Spyder,第一次使用以下导入时,它可以正常工作。
from source.search.ci_search_project import CI_Search_Project
当我第二次出现这个错误时。
文件 "ipython-input-29-f35dfe634c32",位于模块中的第1行 >runfile('C:/Users/nrshakya/Documents/CI/src/Comp_IntelPython/ci_search_project_test.py', wdir='C:/Users/nrshakya/Documents/CI/src/Comp_IntelPython')
文件 "C:\Users\nrshakya\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py",位于第880行,函数runfile execfile(filename, namespace)
文件 "C:\Users\nrshakya\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py",位于第102行,函数execfile exec(compile(f.read(), filename, 'exec'), namespace)
文件 "C:/Users/nrshakya/Documents/CI/src/Comp_IntelPython/ci_search_project_test.py",位于模块中的第8行 from source.search.ci_search_project import CI_Search_Project
文件 "frozen importlib._bootstrap",位于第961行,函数 _find_and_load
文件 "frozen importlib._bootstrap",位于第946行,函数 _find_and_load_unlocked
文件 "frozen importlib._bootstrap",位于第885行,函数 _find_spec
文件 "frozen importlib._bootstrap_external",位于第1157行,函数 find_spec
文件 "frozen importlib._bootstrap_external",位于第1123行,函数 _get_spec
文件 "frozen importlib._bootstrap_external",位于第994行,迭代器 iter
文件 "frozen importlib._bootstrap_external",位于第982行,函数_recalculate
文件 "frozen importlib._bootstrap_external",位于第978行,函数_get_parent_path
KeyError:“source”