9 Installation script for the eric6 IDE and all eric6 related tools. |
9 Installation script for the eric6 IDE and all eric6 related tools. |
10 """ |
10 """ |
11 |
11 |
12 from __future__ import unicode_literals, print_function |
12 from __future__ import unicode_literals, print_function |
13 try: |
13 try: |
|
14 # Python2 only |
14 import cStringIO as io |
15 import cStringIO as io |
15 import sip |
16 import sip |
16 sip.setapi('QString', 2) |
17 sip.setapi('QString', 2) |
17 sip.setapi('QVariant', 2) |
18 sip.setapi('QVariant', 2) |
18 sip.setapi('QTextStream', 2) |
19 sip.setapi('QTextStream', 2) |
|
20 input = raw_input # __IGNORE_WARNING__ |
19 except (ImportError): |
21 except (ImportError): |
20 import io # __IGNORE_WARNING__ |
22 import io # __IGNORE_WARNING__ |
21 |
23 |
22 import sys |
24 import sys |
23 import os |
25 import os |
24 import re |
26 import re |
25 import compileall |
27 import compileall |
219 try: |
221 try: |
220 import PyQt4 # __IGNORE_WARNING__ |
222 import PyQt4 # __IGNORE_WARNING__ |
221 pyqtVariant = "PyQt4" |
223 pyqtVariant = "PyQt4" |
222 del sys.modules["PyQt4"] |
224 del sys.modules["PyQt4"] |
223 except ImportError: |
225 except ImportError: |
224 pyqtVariant = "" |
226 # default to PyQt5, installation will be asked for |
|
227 pyqtVariant = "PyQt5" |
225 |
228 |
226 |
229 |
227 def initGlobals(): |
230 def initGlobals(): |
228 """ |
231 """ |
229 Module function to set the values of globals that need more than a |
232 Module function to set the values of globals that need more than a |
238 platBinDirOld = platBinDir |
241 platBinDirOld = platBinDir |
239 platBinDir = os.path.join(platBinDir, "Scripts") |
242 platBinDir = os.path.join(platBinDir, "Scripts") |
240 if not os.path.exists(platBinDir): |
243 if not os.path.exists(platBinDir): |
241 platBinDir = platBinDirOld |
244 platBinDir = platBinDirOld |
242 else: |
245 else: |
|
246 # TODO: install scripts into {venv}/bin for virtual environments |
|
247 # 1.) assume it is venv if os.path.dirname(sys.executable) is not in |
|
248 # (/opt/local/bin, /usr/local/bin, /usr/bin) and |
|
249 # 2.) directory is writable by user |
243 platBinDir = "/usr/local/bin" |
250 platBinDir = "/usr/local/bin" |
244 |
251 |
245 modDir = distutils.sysconfig.get_python_lib(True) |
252 modDir = distutils.sysconfig.get_python_lib(True) |
246 pyModDir = modDir |
253 pyModDir = modDir |
247 |
254 |
1124 macAppBundlePath, macAppBundleName, |
1131 macAppBundlePath, macAppBundleName, |
1125 ) |
1132 ) |
1126 copyToFile(fn, config) |
1133 copyToFile(fn, config) |
1127 |
1134 |
1128 |
1135 |
|
1136 def pipInstall(packageName, message): |
|
1137 """ |
|
1138 Install the given package via pip. |
|
1139 |
|
1140 @param packageName name of the package to be installed |
|
1141 @type str |
|
1142 @param message message to be shown to the user |
|
1143 @type str |
|
1144 @return flag indicating a successful installation |
|
1145 @rtype bool |
|
1146 """ |
|
1147 ok = False |
|
1148 print(message, "\n") |
|
1149 answer = input("Shall '{0}' be installed using pip? (Y/n) " |
|
1150 .format(packageName)) |
|
1151 if answer in ("", "Y", "y"): |
|
1152 exitCode = subprocess.call( |
|
1153 [sys.executable, "-m", "pip", "install", packageName]) |
|
1154 ok = (exitCode == 0) |
|
1155 |
|
1156 return ok |
|
1157 |
|
1158 |
1129 def doDependancyChecks(): |
1159 def doDependancyChecks(): |
1130 """ |
1160 """ |
1131 Perform some dependency checks. |
1161 Perform some dependency checks. |
1132 """ |
1162 """ |
1133 print('Checking dependencies') |
1163 print('Checking dependencies') |
1162 print("Found PyQt4") |
1192 print("Found PyQt4") |
1163 else: |
1193 else: |
1164 try: |
1194 try: |
1165 from PyQt5.QtCore import qVersion |
1195 from PyQt5.QtCore import qVersion |
1166 except ImportError as msg: |
1196 except ImportError as msg: |
1167 # TODO: install PyQt5 via pip upon request |
1197 installed = pipInstall( |
1168 print('Sorry, please install PyQt5.') |
1198 "PyQt5", |
1169 print('Error: {0}'.format(msg)) |
1199 "PyQt5 could not be detected.\nError: {0}".format(msg) |
1170 exit(1) |
1200 ) |
|
1201 if installed: |
|
1202 # try to import it again |
|
1203 try: |
|
1204 from PyQt5.QtCore import qVersion |
|
1205 except ImportError as msg: |
|
1206 print('Sorry, please install PyQt5.') |
|
1207 print('Error: {0}'.format(msg)) |
|
1208 exit(1) |
|
1209 else: |
|
1210 exit(1) |
1171 print("Found PyQt5") |
1211 print("Found PyQt5") |
1172 |
1212 |
1173 try: |
1213 try: |
1174 if pyqtVariant == "PyQt4": |
1214 if pyqtVariant == "PyQt4": |
1175 pyuic = "pyuic4" |
1215 pyuic = "pyuic4" |
1188 from PyQt4 import Qsci # __IGNORE_WARNING__ |
1228 from PyQt4 import Qsci # __IGNORE_WARNING__ |
1189 else: |
1229 else: |
1190 from PyQt5 import Qsci # __IGNORE_WARNING__ |
1230 from PyQt5 import Qsci # __IGNORE_WARNING__ |
1191 except ImportError as msg: |
1231 except ImportError as msg: |
1192 # TODO: install QScintilla2 via pip upon request (PyQt5 only) |
1232 # TODO: install QScintilla2 via pip upon request (PyQt5 only) |
1193 print("Sorry, please install QScintilla2 and") |
1233 if pyqtVariant == "PyQt4": |
1194 print("its PyQt5/PyQt4 wrapper.") |
1234 message = str(msg) |
1195 print('Error: {0}'.format(msg)) |
1235 else: |
1196 exit(1) |
1236 installed = pipInstall( |
|
1237 "QScintilla", |
|
1238 "QScintilla could not be detected.\nError: {0}".format(msg) |
|
1239 ) |
|
1240 if installed: |
|
1241 # try to import it again |
|
1242 try: |
|
1243 from PyQt5 import Qsci # __IGNORE_WARNING__ |
|
1244 message = None |
|
1245 except ImportError as msg: |
|
1246 message = str(msg) |
|
1247 if message: |
|
1248 print("Sorry, please install QScintilla2 and") |
|
1249 print("its PyQt5/PyQt4 wrapper.") |
|
1250 print('Error: {0}'.format(msg)) |
|
1251 exit(1) |
1197 print("Found QScintilla2") |
1252 print("Found QScintilla2") |
1198 |
1253 |
1199 if pyqtVariant == "PyQt4": |
1254 if pyqtVariant == "PyQt4": |
1200 impModulesList = [ |
1255 impModulesList = [ |
1201 "PyQt4.QtGui", "PyQt4.QtNetwork", "PyQt4.QtSql", |
1256 "PyQt4.QtGui", "PyQt4.QtNetwork", "PyQt4.QtSql", |