I've been banging my head over this for many hours and have ravished the internet for answers. I'm afraid I come up dry. This part of my program will detect if Python's MySQL Connector module is installed and if not, will use PIP to install it. There is code in here for both Windows and another. I am trying to get the Windows part working, but for the life of me, can't seem to do it. Here is the code block (forgive any nonsense, I've been stabbing in the dark):
try:
import mysql.connector as MySQL
except ImportError:
print("In order to use this program, you need a MySQL connector module,")
print("provided by MySQL. Do you wish to install this module (uses SUDO)? (y/n)")
ans = input()
if ans == "y":
import subprocess
if os.name == 'nt': # Windows users will have a different call
try:
subprocess.call("pip install mysql-connector-python", shell = True)
except:
print("Unable to install module...exiting")
exit(1)
raise SystemExit
else:
try:
subprocess.call("sudo pip3 install --allow-external mysql-connector-python mysql-connector-python", shell = True)
except:
print("Unable to install module...exiting")
exit(1)
raise SystemExit
print("The MySQL Connector module was unable to be installed...exiting.")
exit(1)
raise SystemExit
else:
print("The module mysql-connector-python needs to be installed to use this program.")
print("Module was not installed. Exiting...")
raise SystemExit
After running the program, here is the output that I get in my console:
Please choose either the 'O' or 'D' option. Print 'H' or 'HELP' for help. Print 'Q' to quit.
--> d
In order to use this program, you need a MySQL connector module,
provided by MySQL. Do you wish to install this module (uses SUDO)? (y/n)
y
Fatal Python error: Py_Initialize: unable to load the file system codec
File "C:\Python27\lib\encodings\__init__.py", line 123
raise CodecRegistryError,\
^
SyntaxError: invalid syntax
The MySQL Connector module was unable to be installed...exiting.
I'm pretty sure that the problem is not with the CodecRegistryError, but with my poor attempt at launching a pip install using 'subprocess' and the Windows Command Prompt. Very much excited for your input!
Update: I am reminded that I forgot to post my system specifications. I am running Eclipse 4.4 (Luna) with the PyDev plugin (3.6.0.201406232321). My operating system is Windows 8.1 Professional 64-bit and I have both Python 2.7 and Python 3.4 installed. My default Python version is 2.7 currently.