简体   繁体   中英

how to create 2 python packages with a common namespace prefix

is it possible for me to have 2 decoupled python packages where the first part of the namespace is identical:

pyPackageOne:

package_one
|
|-companyname
    |
    |-__init__py
    |-moduleone
        |
        |-__init__.py
        |-dostuff.py

pyPackageTwo:

package_two
|
|-companyname
    |
    |-__init__py
    |-moduletwo
        |
        |-__init__.py
        |-dothings.py

so companyname is a shared prefix in the name?

I want to be able to install and use both packages:

$ pip install moduleone
$ pip install moduletwo
>>> from companyname.moduleone import dostuff
>>> from companyname.moduletwo import dothings

I'm using python 3.6

as Pax0r said in his comment, my original structure works. see my minimal example:

https://github.com/omerholz/pymoduleone

https://github.com/omerholz/pymoduletwo

the place where this strategy fails is when I try to use one package inside another: for example if dothings.py includes: from companyname.moduleone import dostuff we'll get ModuleNotFoundError: No module named 'companyname.moduleone'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM