我一直在尝试使用 py2exe 为以下脚本生成 .exe :
import snowflake.connector
import os
import sys
# Setting your account information
ACCOUNT = '########'
USER = '#######'
PASSWORD = '#######'
ROLES=[]
DATABASE=[]
ROLES.append(sys.argv[1])
DATABASE.append(sys.argv[2])
print(ROLES)
print(DATABASE)
cnx = snowflake.connector.connect(
user=USER,
password=PASSWORD,
account=ACCOUNT,
)
cur = cnx.cursor()
list_of_grants=[]
for rl in ROLES:
print("Role: "+rl )
db_res=cur.execute("SHOW DATABASES").fetchall()
for db in DATABASE:
print("Database: "+ db)
use_db_query = "USE DATABASE " + db
print(use_db_query)
cur.execute(use_db_query)
schema_res= cur.execute("SHOW SCHEMAS").fetchall()
for sch in schema_res:
print("schema: "+ sch[1])
list_of_grants.append("GRANT ALL ON SCHEMA "+db+"."+sch[1]+" to role "+rl+" with grant option")
use_db_query = "USE SCHEMA " + sch[1]
cur.execute(use_db_query)
tables_res=cur.execute("SHOW TABLES IN "+sch[1]).fetchall()
for tbl in tables_res:
print("table: "+ tbl[1])
list_of_grants.append("GRANT ALL ON TABLE "+db+"."+sch[1]+"."+tbl[1]+" to role "+rl+" with grant option")
for grant in list_of_grants:
cur.execute(grant)
代码非常简单,就像一个魅力。
我希望使用 py2exe 将其转换为 .exe,但当时我收到以下错误:
running py2exe
Error: Namespace packages not yet supported: Skipping package 'snowflake'
Traceback (most recent call last):
File "setup.py", line 13, in <module>
'packages': ['snowflake']
File "C:\Anaconda3\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Anaconda3\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Anaconda3\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Anaconda3\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
self._run()
File "C:\Anaconda3\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
builder.analyze()
File "C:\Anaconda3\lib\site-packages\py2exe\runtime.py", line 168, in analyze
mf.import_package(modname)
File "C:\Anaconda3\lib\site-packages\py2exe\mf3.py", line 92, in import_package
self.import_hook(name)
File "C:\Anaconda3\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:\Anaconda3\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
return self._find_and_load(name)
File "C:\Anaconda3\lib\site-packages\py2exe\mf3.py", line 337, in _find_and_load
raise ImportError(name)
ImportError: snowflake
Snowflake 是一个允许我连接到我的数据库的包(一个雪花数据库,相当新)
我的操作系统是:Windows 10,Python 版本 3.5.1
我的 py2exe 的 setup.py :
from distutils.core import setup
import snowflake.connector
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
console=['grants.py'],
options = {
'py2exe': {
'packages': ['snowflake']
}
}
)
我环顾四周,找不到这个问题的任何答案。如果有人有想法。
在此先感谢您的帮助。