use “pip install/uninstall” inside a python script

2019-03-30 02:20发布

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.

标签: python pip
7条回答
混吃等死
2楼-- · 2019-03-30 03:20

It's not a good idea to install packages inside the python script because it requires root rights. You should ship additional modules alongside with the script you created or check if the module is installed:

try:
   import ModuleName
except ImportError:
   print 'Error, Module ModuleName is required'

If you insist in installing the package using pip inside your script you'll have to look into call from the subprocess module ("os.system()" is deprecated).

There is no pip module but you could easily create one using the method above.

查看更多
登录 后发表回答