Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 321
Broan Avatar asked Jul 18 '15 17:07

Broan


1 Answers

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.

like image 144
Simeon Visser Avatar answered Oct 02 '22 11:10

Simeon Visser