简体   繁体   中英

How to 'partially' install a Python package

I need to use a function in numpy package, say numpy.random.choice (another Python lib function random.choice samples the list uniformly while I want it to do that from some discrete distributions).

My program will be distributed to a lot of people to develop and test. So that means they should also install numpy before they are able to run the code. I'm now trying to find a way to get rid of installing the whole numpy library.

Definitely rewriting the function myself is a solution (for example using alias method). But I'm wondering that is there a way that I can only install the part of numpy related to numpy.random.choice ?

This is probably not worth the hassle but it's up to you to make that trade-off. numpy.random.choice is not implemented in Python but in a .pyx file which needs to be compiled to C using Cython.

You could refactor it and construct a new package which implements only that functionality (possibly with a few related data structures). But with recent improvements with Python wheels files installation of numpy should be much easier than in the past. So I reckon it's easier to install numpy as it is and accept that you have it as a dependency.

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