简体   繁体   English

Python:创建包时如何更改模块的路径

[英]Python: how to change a module's path when creating a package

We have a project in our company, developed in Python. 我们公司有一个使用Python开发的项目。 Internally, we use import our_cool_module . 在内部,我们使用import our_cool_module We'd like to open source it, but change the import path to import our_cool_company.our_cool_module . 我们想将其开源,但是将导入路径更改为import our_cool_company.our_cool_module How can we do this without making any changes to the code or to the actual directories it's in? 我们如何做到这一点而无需更改代码或代码所在的实际目录? (using Python 3 if its relevant) (如果相关,请使用Python 3)

Please do not do this. 请不要这样做。 This is against good practices. 这违反了良好做法。 There is nothing cool about doing this. 这样做很酷。 And if you do this, a lot of people who do not know your company ahead of time will not use the module. 而且,如果您这样做,那么很多不了解您公司的人将不会使用该模块。

# Can you imagine if I had to do this to install Django?
pip install microsoft

If it is a good useful module, leave it as such. 如果它是一个很好的有用模块,则保持原样。 Your company will eventually be known and get the credit for it. 最终您的公司将广为人知并获得声誉。 A good example is React , the Javascript library developped by Facebook . 一个很好的例子是React ,这是Facebook开发的Javascript库。 Nowhere in the code do you see that they developped it. 在代码中没有任何地方看到他们开发了它。 But it's good enough that everybody knows. 但是每个人都知道这已经足够了。

Note: no, Microsoft did not develop Django . 注意:不, 微软没有开发Django

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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