Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use "pip install/uninstall" inside a python script [duplicate]

Tags:

python

pip

how, inside a python script can I install packages using pip? I don't use the os.system, I want to import pip and use it.

like image 457
Bengineer Avatar asked Oct 17 '12 15:10

Bengineer


1 Answers

pip.main() no longer works in pip version 10 and above. You need to use:

from pip._internal import main as pipmain

pipmain(['install', 'package-name'])

For backwards compatibility you can use:

try:
    from pip import main as pipmain
except ImportError:
    from pip._internal import main as pipmain
like image 84
Damian Russak Avatar answered Oct 10 '22 11:10

Damian Russak