R
R
Roma Kotolup2021-02-25 16:28:02
Python
Roma Kotolup, 2021-02-25 16:28:02

How to download pip module using python program?

I have been making python programs with a huge number of pip modules for different functions.
if the user of my program has not downloaded the module, but it is necessary for the robots, then how can I write a program that will install the module only if it is not installed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2021-02-25
@SoreMix

Just put all the modules you use in requirements.txt and ask them to be installed
pip install -r requirements.txt

E
Evgeniy _, 2021-02-25
@GeneD88

import pip

def import_or_install(package):
    try:
        __import__(package)
    except ImportError:
        pip.main(['install', package])

Or via subprocess

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question