1. 程式人生 > >python 3 安裝mysql包時遇到的 python 3.x no found

python 3 安裝mysql包時遇到的 python 3.x no found


import sys
from winreg import *

# tweak as necessary

version = sys.version[:3]
installpath = sys.prefix
regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
    installpath, installpath, installpath)

def RegisterPy():
    try:
        reg = OpenKey(HKEY_LOCAL_MACHINE, regpath)
    except EnvironmentError:
        try:
            reg = CreateKey(HKEY_LOCAL_MACHINE, regpath)
            SetValue(reg, installkey, REG_SZ, installpath)
            SetValue(reg, pythonkey, REG_SZ, pythonpath)
            CloseKey(reg)
        except:
            print("Unable to register! %s " % (pythonpath))
            return
        print ("--- Python"+ version+"is now registered!")
        return
    print ("--- Python"+ version+"is now registered!")
RegisterPy()

儲存為*.py 然後用管理員許可權執行,跟python2.x相比有點區別,兩個方面 

1 匯入包為  winreg  python 2.x 為  _winreg

2 print 的差別