Importing from python namespace to different folders

I have python code organized like this:

part_one
  namespace
    __init__.py
    one.py

part_two
  namespace
     __init__.py
     two.py

      

If both __init__.py

contain:

import pkg_resources
pkg_resources.declare_namespace("namespace")

      

My problem comes when I import them like this:

import sys
sys.path.append("part_one")
import namespace.one

sys.path.append("part_two")
import namespace.two # ImportError

      

The obvious fix is ​​to move path.append("part_two")

before import namespace.one

, however the first import is in the script that my company uses to configure and run ipython, so I cannot add part_two there (part_one is my company's main api, part_two is my project).

It also explains why the error occurred.

+3


source to share





All Articles