Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Script to install ensurepip to Python. “Fix” the Ubuntu 14.04 / Debian Sid bug.
import os
import sys
import io
import tarfile
import urllib.request
def main():
print('Downloading ensurepip module archive...')
response = urllib.request.urlopen(ARCHIVE_URL)
data =
tar_f =
package_root = sys.path[1]
print('Extracting files to', package_root)
print('Extraction failed! Please ensure you have appropriate '
'permissions and try again. May you should use "sudo"?')
print('All done!\n')
if __name__ == '__main__':
Copy link

Thank you!

Copy link

ducin commented Nov 7, 2014

You are my hero of the day!

Copy link

Somewhat easier in Bash:

wget -qO- | 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.

Copy link

Thank you! 😃

Copy link

moltob commented Oct 8, 2016


Copy link

Thanks a lot!

Copy link

Thank you very much, TP

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