6

I was trying to import a module from a different directory level so I used:

import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

But now I get this error. I'm using Spyder and the first time I use the following import, it works fine.

from source.search.ci_search_project import CI_Search_Project

From the second time I get this error.

File "ipython-input-29-f35dfe634c32", line 1, in module >runfile('C:/Users/nrshakya/Documents/CI/src/Comp_IntelPython/ci_search_project_test.py', wdir='C:/Users/nrshakya/Documents/CI/src/Comp_IntelPython')

File "C:\Users\nrshakya\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile execfile(filename, namespace)

File "C:\Users\nrshakya\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/nrshakya/Documents/CI/src/Comp_IntelPython/ci_search_project_test.py", line 8, in module from source.search.ci_search_project import CI_Search_Project

File "frozen importlib._bootstrap", line 961, in _find_and_load

File "frozen importlib._bootstrap", line 946, in _find_and_load_unlocked

File "frozen importlib._bootstrap", line 885, in _find_spec

File "frozen importlib._bootstrap_external", line 1157, in find_spec

File "frozen importlib._bootstrap_external", line 1123, in _get_spec

File "frozen importlib._bootstrap_external", line 994, in iter

File "frozen importlib._bootstrap_external", line 982, in _recalculate

File "frozen importlib._bootstrap_external", line 978, in _get_parent_path

KeyError: 'source'

3
  • 1
    Please post the code required to reproduce the problem! Commented Sep 27, 2017 at 5:15
  • I added it to the main question. it's just an import: from source.search.ci_search_project import CI_Search_Project Commented Sep 27, 2017 at 5:28
  • Has anyone found a resolution to this? I'm encountering the same issue. Commented May 13, 2019 at 19:26

1 Answer 1

4

According to Vera's answer to their question, adding an empty __init__.py file in the folder containing the module will fix this problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.