简体   繁体   English

如何安装特定 python package 的零件?

[英]How to install parts of specific python package?

I am looking at a code that uses acicobra package.我正在查看使用 acicobra package 的代码。 Acicobra library is 670MB. Acicobra 库为 670MB。 The python code uses only a few functions from acicobra library. python 代码仅使用 acicobra 库中的几个函数。 Is there a way to install only the required modules from this acicobra library and not the entire library?有没有办法从这个 acicobra 库中只安装所需的模块而不是整个库? If I install the entire library, my docker image size gets inflated because of this gigantic library.如果我安装整个库,我的 docker 图像大小会因为这个巨大的库而膨胀。

root@1f5edb150a78:/usr/local/lib/python2.7/site-packages# ls -l |grep -v dist-info|du -sh *|sort -hr
659M    cobra

These are the only references to cobra in the python code这些是 python 代码中对 cobra 的唯一引用

from cobra.mit.access import MoDirectory
from cobra.mit.session import LoginSession, LoginError
from cobra.mit.request import ClassQuery, DnQuery, QueryError

As you can see, the code is referencing only 3 modules out of the entire library.如您所见,代码仅引用了整个库中的 3 个模块。

I am looking for ways to avoid installing the entire library to limit the size of the dockerimage我正在寻找避免安装整个库以限制 dockerimage 大小的方法

Not unless it relies on other smaller sublibraries that you can fetch.除非它依赖于您可以获取的其他较小的子库,否则不会。

You could check out the code and see if you can create your own smaller python package.您可以查看代码,看看是否可以创建自己的更小的 python package。
But 90% of the time you'll go down a depecdency chain and need the full library anyway.但是 90% 的时间你会 go 沿着依赖链走下去,无论如何都需要完整的库。
Also check the license if commercial use.如果商业用途,还要检查许可证。

This should be the correct github for the source:这应该是源的正确 github:
https://github.com/datacenter/cobra https://github.com/datacenter/cobra

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

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