From ca22f06a5bb673951d132571a476d1d21a904559 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Fri, 16 Jun 2017 10:50:54 -0400 Subject: [PATCH] Fix Python 3 import problems in install scripts --- assets/install.ps1 | 9 ++++++--- assets/install.sh | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/assets/install.ps1 b/assets/install.ps1 index a119e229..8d49a5f8 100644 --- a/assets/install.ps1 +++ b/assets/install.ps1 @@ -2,11 +2,14 @@ $InstallScript = @" import os import sys import json -import urllib import tempfile import tarfile import shutil from subprocess import Popen +try: + from urllib.request import urlopen +except ImportError: + from urllib import urlopen from _winreg import OpenKey, CloseKey, QueryValueEx, SetValueEx, \ HKEY_CURRENT_USER, KEY_ALL_ACCESS, REG_EXPAND_SZ import ctypes @@ -87,7 +90,7 @@ def add_to_path(location): def install(virtualenv_url, virtualenv_filename, install_dir, lib_dir): t = tempfile.mkdtemp() with open(os.path.join(t, 'virtualenv.tar.gz'), 'wb') as f: - download = urllib.urlopen(virtualenv_url) + download = urlopen(virtualenv_url) f.write(download.read()) download.close() with tarfile.open(os.path.join(t, 'virtualenv.tar.gz'), 'r:gz') as tar: @@ -127,7 +130,7 @@ def main(): print() get_confirmation() - for url in json.load(urllib.urlopen(VENV_URL))['urls']: + for url in json.load(urlopen(VENV_URL))['urls']: if url['python_version'] == 'source': virtualenv_url = url['url'] #stripping '.tar.gz' diff --git a/assets/install.sh b/assets/install.sh index f0e2c7ff..18bb8793 100644 --- a/assets/install.sh +++ b/assets/install.sh @@ -22,10 +22,13 @@ if 1: import os import sys import json - import urllib import tempfile import shutil from subprocess import Popen + try: + from urllib.request import urlopen + except ImportError: + from urllib import urlopen PY2 = sys.version_info[0] == 2 if PY2: @@ -143,7 +146,7 @@ if 1: get_confirmation() - for url in json.load(urllib.urlopen(VENV_URL))['urls']: + for url in json.load(urlopen(VENV_URL))['urls']: if url['python_version'] == 'source': virtualenv = url['url'] break