MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / execute_pip_install_package

Function execute_pip_install_package

PySimpleGUI/PySimpleGUI.py:24541–24625  ·  view source on GitHub ↗

Pip installs a package using the currently running interpreter :param package: The name of the package to install :type package: str :param interpreter: The interpreter to use for the install. If none specified, then the currently running interpreter is used

(package, interpreter=None, force_reinstall=False, upgrade_pip=False, no_gui=False)

Source from the content-addressed store, hash-verified

24539
24540
24541def execute_pip_install_package(package, interpreter=None, force_reinstall=False, upgrade_pip=False, no_gui=False):
24542 """
24543 Pip installs a package using the currently running interpreter
24544
24545 :param package: The name of the package to install
24546 :type package: str
24547 :param interpreter: The interpreter to use for the install. If none specified, then the currently running interpreter is used
24548 :type interpreter: str
24549 :param force_reinstall: If True package will be uninstalled before installing
24550 :type force_reinstall: bool
24551 :param upgrade_pip: If True pip will first be upgraded
24552 :type upgrade_pip: bool
24553 :param no_gui: If True no GUI to output to
24554 :type no_gui: bool
24555 """
24556
24557
24558 if interpreter is None:
24559 python_command = sys.executable # always use the currently running interpreter to perform the pip!
24560 if 'pythonw' in python_command:
24561 python_command = python_command.replace('pythonw', 'python')
24562 else:
24563 python_command = interpreter
24564
24565 if '#egg=' in package: # if this is a long pip string with a security token, get the pacakge name from the string
24566 package_name = package[package.index('#egg=')+5:]
24567 for i, char in enumerate(package_name):
24568 if not char.isalnum():
24569 package_name = package_name[:i]
24570 break
24571 # package_name = package[package.index('#egg=')+5:-1]
24572 elif '.whl' in package:
24573 if '/' in package:
24574 file_name = package.split("/")[-1]
24575 else:
24576 file_name = package
24577 package_name = file_name.split("-")[0]
24578 else:
24579 package_name = package
24580
24581 # If need to upgrade pip, do that first by calling our own function recursively
24582 if upgrade_pip:
24583 execute_pip_install_package('pip')
24584
24585
24586 pip_command = f'-m pip install --upgrade --no-cache-dir {package} {"--force-reinstall" if force_reinstall else ""}'
24587
24588 if no_gui:
24589 print(f'Installing {package_name} with the Python interpreter =', python_command)
24590
24591 sp = execute_command_subprocess(python_command, pip_command, pipe_output=True, wait=True)
24592 __show_package_version(package_name, print, python_command)
24593 print(f'Done Installing {package_name}.')
24594 return
24595
24596 layout = [[Text(f'Installing {package_name}', font='_ 14')],
24597 [Multiline(s=(90, 15), k='-MLINE-', write_only=True, expand_x=True, expand_y=True)],
24598 [Push(), Button('Downloading...', k='-EXIT-'), Sizegrip()]]

Callers 1

upgrade_PySimpleGUI_guiFunction · 0.85

Calls 15

disable_debuggerMethod · 0.95
start_threadMethod · 0.95
readMethod · 0.95
closeMethod · 0.95
__show_package_versionFunction · 0.85
TextClass · 0.85
MultilineClass · 0.85
PushFunction · 0.85
ButtonClass · 0.85
SizegripClass · 0.85
WindowClass · 0.85
__pip_install_threadFunction · 0.85

Tested by

no test coverage detected