D
D
dojyaaaaaaaan2021-09-23 15:27:35
Python
dojyaaaaaaaan, 2021-09-23 15:27:35

How to install libraries via code without cmd?

This question has probably been asked before, but I'll ask anyway. How to install libraries without using cmd? In cmd, installation is done like this pip install name, but how to do it in the code itself?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2021-09-23
@dojyaaaaaaaan

pip - sort of like a python module - accordingly, you can programmatically run commands using module procedures:

from pip._internal.cli.main import main

main(['install', 'xlrd'])
#Collecting xlrd
#  Downloading xlrd-2.0.1-py2.py3-none-any.whl (96 kB)
#     |████████████████████████████████| 96 kB 541 kB/s 
# Installing collected packages: xlrd
# Successfully installed xlrd-2.0.1
# WARNING: You are using pip version 21.1.1; however, version 21.2.4 is available.
# You should consider upgrading via the '/opt/.../rvenv/bin/python -m pip install --upgrade pip' command.

import xlrd

xlrd.__version__
#  '2.0.1'

main(['freeze'])
# aioredis==1.3.1
# amqp==5.0.6
# argon2-cffi==20.1.0
# asgiref==3.3.4
# ...

the only thing is why do it in the code itself ...

S
Saboteur, 2021-09-23
@saboteur_kiev

1. no way
2. for some programming languages ​​there are builders (npm, maven, gradle, make) that can do this. I won’t tell you for python, but most likely the same pip will be launched under the hood

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question