导入两个具有相同名称的包 [英] import two packages with the same name

查看:119
本文介绍了导入两个具有相同名称的包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用pip来安装我需要的两个库,这些库与它们有什么关系,但是不能处理它们。问题是,一旦解压缩,它们具有相同的名称,并且它们的功能都被导入为:

  import the_package 
from the_package import a,b

更新:我的意思是以任何以前的方式导入the_package,不一定同时也不是顺序。



由于我通过pip安装它们,并且是从要求文件,所以我的队友可以像我想重命名一样的方式安装它们软件包/模块不是一个选项(如果是,我很欣赏指出如何自动执行)



我想出的一件事是提供一些可以安装的选项目录中的包含某种别名/前缀的包,所以他们的名字可能不同,但是pip文档对我来说并没有太多的用处。



提前感谢任何帮助:D

解决方案

您应该在安装

  pip install --install-option = -  prefix = $ PREFIX_PATHpackage_name 

将两个软件包安装到不同的文件夹。然后将它们导入为

 将Folder1.mymodule作为A 
导入Folder2.mymodule作为B

也可以通知包创作者。


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:

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.

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)

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.

Thanks in advance for any help :D

解决方案

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.

这篇关于导入两个具有相同名称的包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆