-
-
Save Qumeric/c553685cad24b1b1268eac20d7afa81b to your computer and use it in GitHub Desktop.
Script to install ensurepip to Python. Works on macOS and Linux for Anaconda and classic python installs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import sys | |
| import io | |
| import tarfile | |
| import urllib.request | |
| import re | |
| ARCHIVE_URL = 'http://d.pr/f/YqS5+' | |
| print('Downloading ensurepip module archive...') | |
| response = urllib.request.urlopen(ARCHIVE_URL) | |
| data = response.read() | |
| tar_f = tarfile.open(fileobj=io.BytesIO(data)) | |
| package_roots = [x for x in sys.path] | |
| i = 1 | |
| for root in package_roots: | |
| print("{}.".format(i), root) | |
| i += 1 | |
| x = int(input("Choose installation directory (.../lib/pythonX.X)\n")) | |
| while 1 > x or x > len(package_roots): | |
| x = int(input("Try again: ")) | |
| package_root = package_roots[x-1] | |
| print('Extracting files to', package_root) | |
| os.chdir(package_root) | |
| try: | |
| tar_f.extractall() | |
| except: | |
| print('Extraction failed! Please ensure you have appropriate ' | |
| 'permissions and try again. May you should use "sudo"?') | |
| else: | |
| print('All done!\n') |
Looks like something happened with the archive? Try to download manually and try to open with some other tool to verify
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Downloading ensurepip module archive...
Traceback (most recent call last):
File "/home/marka/qemu-8.1.1/ens.py", line 15, in
tar_f = tarfile.open(fileobj=io.BytesIO(data))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/tarfile.py", line 1639, in open
raise ReadError(f"file could not be opened successfully:\n{error_msgs_summary}")
tarfile.ReadError: file could not be opened successfully: