Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to install ensurepip to Python. Works on MacOSX 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+'
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 = [x for x in sys.path if re.compile('site-packages$').search(x)][0]
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()
@antoine-lizee

This comment has been minimized.

Copy link
Owner Author

commented May 25, 2016

Unfortunately, doesn't solve the problem of using venv with anaconda because ensurepip is still missing for the new python executable. It's quite obscure and still doesn't have a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.