I used pip to install two libraries I need, which are related in what they do but cannot dispose any of them. The problem is that once unpacked, they have the same name and the functionalities in both of them are imported as:
我使用pip来安装我需要的两个库,这些库与它们的相关但不能处理它们中的任何一个。问题是,一旦解压缩,它们具有相同的名称,并且它们中的功能都被导入为:
import the_package
from the_package import a, b
Update: I mean to import the_package in any of the previous ways, not necessarily both nor in sequence.
更新:我的意思是以任何先前的方式导入the_package,不一定是两者也不是顺序。
Since I install them via pip, and are installed from a requirements file so my teammates can install them the same way I guess renaming packages/modules is not an option (if it is, I appreciate pointing how to do it automatically)
由于我是通过pip安装的,并且是从需求文件安装的,所以我的队友可以安装它们的方式相同,我想重命名包/模块不是一个选项(如果是的话,我很感激指点如何自动完成)
One thing I came up with was giving pip some option that would install the packages in directories with some sort of alias/prefix so their names could be different, but pip docs didn't come much in handy for me.
我想出的一件事就是给pip一些选项,它会在包含某种别名/前缀的目录中安装这些包,所以它们的名字可能会有所不同,但是pip docs对我来说并不是很方便。
Thanks in advance for any help :D
在此先感谢您的帮助:D
2 个解决方案
#1
4
You should add this while installing
你应该在安装时添加它
pip install --install-option="--prefix=$PREFIX_PATH" package_name
and install the two packages to different folders. Then import them as
并将两个包安装到不同的文件夹。然后将它们导入为
import Folder1.mymodule as A
import Folder2.mymodule as B
Might also want to inform the package creators.
可能还想通知包装创建者。
#2
-1
import the_package
from the_package import a, b
and then:
import the_package as package_b
from the_package import a as a_, b as b_
use them accordingly and this will not conflict with the namespaces.
相应地使用它们,这不会与命名空间冲突。
#1
4
You should add this while installing
你应该在安装时添加它
pip install --install-option="--prefix=$PREFIX_PATH" package_name
and install the two packages to different folders. Then import them as
并将两个包安装到不同的文件夹。然后将它们导入为
import Folder1.mymodule as A
import Folder2.mymodule as B
Might also want to inform the package creators.
可能还想通知包装创建者。
#2
-1
import the_package
from the_package import a, b
and then:
import the_package as package_b
from the_package import a as a_, b as b_
use them accordingly and this will not conflict with the namespaces.
相应地使用它们,这不会与命名空间冲突。