How to import a function from parent folder in python?

后端 未结 2 412
离开以前
离开以前 2021-01-21 03:17

I need to perform an import of a function on my python project.

I know there\'re dozens of similar questions on SO, however, unfortunately, I couldn\'t find the right so

2条回答
  •  半阙折子戏
    2021-01-21 03:47

    The fact that you have an __init__.py tells me that PythonClient is itself a library. Do from PythonClient.hashes.hash_function import hash_function. I always like fully qualified paths.

    You need to install your library too before you can import from it. That requires a setup.py file in your home directory. After that, you should pip install your library for testing, e.g., `pip install -e .

提交回复
热议问题