0

I have some code that uses modules that are not installed by default (eg. Numpy), and I want to give the program to a friend of mine who does not have that module.

I do not want him to have to go through the tedious process of using cmd to install the module. Is there any way to install the module from within the code itself? Like:

import pip
pip.install('numpy')

(completely hypothetical)

BTW: I am using Windows 10

tripleee
  • 175,061
  • 34
  • 275
  • 318

1 Answers1

3
from subprocess import call
module=input('Name module:   ')
try:
    call(['pip', 'install', module])
except Exception:
    print('Error')
Vikhyat Agarwal
  • 1,723
  • 1
  • 11
  • 29
  • Thanks a lot. This works really well for user installs, however when I need to install for all users, I get an error. Please fix it. And BTW, is there any way to not show all of the colourful text? – ѕняєє ѕιиgнι Aug 01 '18 at 10:50