首页 > 解决方案 > 带有pyinstaller的cassandra.cluster无法正常工作

问题描述

我正在尝试在我的 Mac 上使用 pyinstaller 为一个简单的 python 文件 TestAudit.py 创建可执行文件,其中包含

from cassandra.cluster import Cluster

当我运行我的可执行文件时出现以下错误:

TestAudit.py:7: DeprecationWarning: Using or importing the ABCs from
'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
Traceback (most recent call last):
  File "TestAudit.py", line 7, in <module>
  File "cassandra/cluster.py", line 23, in init cassandra.cluster
ModuleNotFoundError: No module named 'concurrent'
[46470] Failed to execute script TestAudit

我的 Python 版本是 Python 3.7.3 Mac:MacOS High Sierra,版本 10.13.6

如果有人知道如何解决此问题,请提供帮助,否则我们如何将 TestAudit.py 与依赖项一起打包?

TestAudit.py 文件:

"""Program to initialze Cassandra driver"""
from cassandra.cluster import Cluster
from datetime import datetime
print("now =", datetime.now())

标签: pythoncassandra

解决方案


对我有用的是将每个丢失的模块添加到pyinstaller的 hiddenimports 并再次运行可执行文件,直到找不到更多丢失的模块。

使用 pyInstaller 编译可执行文件后,您会注意到目录中有一个 *.spec 文件。在那里,您可以将模块添加到 hiddenimports 列表并运行pyInstaller <yourModule>.spec以再次构建可执行文件。

这是我为我的案例找到的缺失模块列表:

hiddenimports=['concurrent', 'concurrent.futures', 'json', 'cassandra.connection', 'cassandra.marshal', 'cassandra.protocol', 'cassandra.type_codes', 'geomet.wkt', 'cassandra.compat', 'cassandra.cython_deps', 'cassandra.pool', 'cassandra.policies', 'cassandra.timestamps', 'cassandra.datastax', 'cassandra.datastax.insights', 'cassandra.datastax.insights.reporter', 'cassandra.datastax.cloud', 'cassandra.io', 'cassandra.io.asyncorereactor']

推荐阅读