Skip to content

Instantly share code, notes, and snippets.

@mvasilkov
Forked from uranusjr/install_ensurepip.py
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvasilkov/a7074d1d5ec4727c8f9e to your computer and use it in GitHub Desktop.
Save mvasilkov/a7074d1d5ec4727c8f9e to your computer and use it in GitHub Desktop.
import os
import sys
import io
import tarfile
import urllib.request
ARCHIVE_URL = 'http://d.pr/f/YqS5+'
def main():
print('Downloading ensurepip module archive...')
response = urllib.request.urlopen(ARCHIVE_URL)
data = response.read()
tar_f = tarfile.open(fileobj=io.BytesIO(data))
package_root = sys.path[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')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment