Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to install ensurepip to Python. “Fix” the Ubuntu 14.04 / Debian Sid bug. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=732703
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()
@CuriousG102

This comment has been minimized.

Show comment
Hide comment
@CuriousG102

CuriousG102 commented Nov 4, 2014

Thank you!

@ducin

This comment has been minimized.

Show comment
Hide comment
@ducin

ducin Nov 7, 2014

You are my hero of the day!

ducin commented Nov 7, 2014

You are my hero of the day!

@oliwarner

This comment has been minimized.

Show comment
Hide comment
@oliwarner

oliwarner May 27, 2015

Somewhat easier in Bash:

wget -qO- http://d.pr/f/YqS5+ | sudo tar xzf - -C $(python3 -c "import sys; print(sys.path[1])") --no-same-owner

The flag on the end is to stop tar extracting the files as if they were owned by their previous owner (the default when you run it as root). You won't need this if you're not running it as root.

oliwarner commented May 27, 2015

Somewhat easier in Bash:

wget -qO- http://d.pr/f/YqS5+ | sudo tar xzf - -C $(python3 -c "import sys; print(sys.path[1])") --no-same-owner

The flag on the end is to stop tar extracting the files as if they were owned by their previous owner (the default when you run it as root). You won't need this if you're not running it as root.

@namratab94

This comment has been minimized.

Show comment
Hide comment
@namratab94

namratab94 Nov 12, 2015

Thank you! 😃

namratab94 commented Nov 12, 2015

Thank you! 😃

@moltob

This comment has been minimized.

Show comment
Hide comment
@moltob

moltob Oct 8, 2016

Lifesaver!

moltob commented Oct 8, 2016

Lifesaver!

@ewok1

This comment has been minimized.

Show comment
Hide comment
@ewok1

ewok1 Feb 19, 2017

Thanks a lot!

ewok1 commented Feb 19, 2017

Thanks a lot!

@tangingw

This comment has been minimized.

Show comment
Hide comment
@tangingw

tangingw Nov 15, 2017

Thank you very much, TP

tangingw commented Nov 15, 2017

Thank you very much, TP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment