python - 带有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())
解决方案
对我有用的是将每个丢失的模块添加到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']
推荐阅读
- r - 尝试创建具有 10 倍交叉验证的 CART 模型时出现问题
- ios - 如何在 SwiftUI 中的形状之间画一条线?
- asterisk - PJSIP将自定义标头添加到队列
- javascript - 单击后更改按钮 URL 操作
- javascript - 在添加事件的上下文中,本机代码意味着什么?
- reactjs - useEffect 不等待 Promise.all?
- c - 为什么非原子断言匹配两个,一个相反?
- django - Django Rest-Framework 序列化错误
- python - 创建级联神经网络以及如何训练它
- android - 使用 RecyclerView 片段折叠工具栏