Skip to content

Instantly share code, notes, and snippets.

@Qumeric
Forked from antoine-lizee/install_ensurepip.py
Last active October 8, 2023 07:13
Show Gist options
  • Select an option

  • Save Qumeric/c553685cad24b1b1268eac20d7afa81b to your computer and use it in GitHub Desktop.

Select an option

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.
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')
@MetaB0y

MetaB0y commented Oct 8, 2023

Copy link
Copy Markdown

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