Skip to content

Commit 50a41eb

Browse files
committed
Adding check for pip
1 parent 102b004 commit 50a41eb

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

graalpython/lib-python/3/tkinter/__init__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,14 @@ def run_tkinter_build_script():
146146

147147
def setup_tkinter():
148148

149-
packages = ["cffi", "setuptools"]
149+
packages = ["pip", "cffi", "setuptools"]
150+
151+
sys.stdout.write("Checking for required packages before importing tkinter:\n")
152+
sys.stdout.flush()
150153

151154
to_install = []
152155
for pkg in packages:
153-
sys.stdout.write(f"Checking {pkg}...")
156+
sys.stdout.write(f" {pkg}...")
154157
sys.stdout.flush()
155158

156159
if check_package(pkg):
@@ -160,12 +163,15 @@ def setup_tkinter():
160163
to_install.append(pkg)
161164

162165
if to_install:
163-
if prompt_user_install(', '.join(to_install)):
166+
response = input(f"{YELLOW} Would you like to install {', '.join(to_install)} {"package" if len(to_install) == 1 else "packages"}? [Y/n]: {RESET}").strip().lower()
167+
if response in ("", "y", "yes"):
168+
if "pip" in to_install:
169+
subprocess.check_call([sys.executable, "-m", "ensurepip", "--default-pip"])
170+
to_install.remove("pip")
164171
subprocess.check_call([sys.executable, "-m", "pip", "install", *to_install])
165-
print(f"{GREEN}{', '.join(to_install)} installed successfully.{RESET}")
172+
print(f"{GREEN}All required packages were installed successfully.{RESET}")
166173
else:
167-
print(f"{RED}Cannot continue without: {', '.join(to_install)}{RESET}")
168-
print(f"Please install manually using: pip install {' '.join(to_install)}")
174+
print(f"{RED}Cannot import tkinter without {"this package" if len(to_install) == 1 else "these packages"}: {' '.join(to_install)}")
169175
sys.exit(1)
170176

171177
install_system_dependencies()

0 commit comments

Comments
 (0)