PCM_Report/install_sqlserver_driver.py

58 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
安装SQL Server数据库驱动
"""
import subprocess
import sys
def install_package(package_name):
"""安装指定的包"""
try:
print(f"正在安装 {package_name}...")
subprocess.check_call([sys.executable, "-m", "pip", "install", package_name])
print(f"{package_name} 安装成功!\n")
return True
except subprocess.CalledProcessError:
print(f"{package_name} 安装失败!\n")
return False
def main():
print("=" * 50)
print("SQL Server 数据库驱动安装程序")
print("=" * 50)
print()
print("本程序将安装SQL Server数据库驱动")
print("推荐安装 pyodbc需要系统已安装ODBC驱动")
print("备选方案 pymssql纯Python实现")
print()
choice = input("请选择安装方式:\n1. 安装pyodbc推荐\n2. 安装pymssql备选\n3. 两个都安装\n请输入选择(1/2/3): ")
success = False
if choice == "1" or choice == "3":
if install_package("pyodbc"):
success = True
print("注意pyodbc需要系统安装ODBC Driver for SQL Server")
print("下载地址https://docs.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server")
if choice == "2" or choice == "3":
if install_package("pymssql"):
success = True
if success:
print("\n驱动安装完成!")
print("现在可以使用工单查询功能了。")
else:
print("\n驱动安装失败,请检查网络连接或手动安装:")
print("pip install pyodbc")
print("")
print("pip install pymssql")
input("\n按Enter键退出...")
if __name__ == "__main__":
main()