Python: 没有找到名为 ‘secrets’ 的模块 – oracledb 模块

huangapple go评论71阅读模式
英文:

Python: No module named 'secrets' - oracledb module

问题

我在使用PyInstaller创建的可执行文件时遇到以下错误,与oracledb模块有关。

追溯 (most recent call last): File "my_script.py", line 1, in

文件 "PyInstaller/loader/pyimod03_importers.py", 第 495 行,
在 exec_module 文件 "oracledb/init.py", 第 38 行, 在
文件 "PyInstaller/loader/pyimod03_importers.py", 第 495 行,
在 exec_module 文件 "oracledb/connection.py", 第 45 行, 在
文件 "src/oracledb/base_impl.pyx", 第 47 行, 在 init oracledb.base_impl
ModuleNotFoundError: 没有找到模块 'secrets' [23464] 由于未处理的异常,无法执行脚本 'my_script'!

Python 3.6

根据此帖子,我了解到Python 3.6是一个依赖项。

在我们的环境中,我们同时拥有Python 3.6.8和Python 2.7。

使用Python3构建

根据此帖子中的评论,我尝试了以下命令来构建我的可执行文件:

python3 -m PyInstaller -F my_script.py

我仍然遇到相同的错误。

我怀疑这与两个版本的Python有关,但我不知道如何解决。是否有人能为我提供一些建议吗?

英文:

I get the following error when running an executable created with PyInstaller. It relates to the module oracledb.

> Traceback (most recent call last): File "my_script.py", line 1, in
> <module>
File "PyInstaller/loader/pyimod03_importers.py", line 495,
> in exec_module File "oracledb/init.py", line 38, in <module>
> File "PyInstaller/loader/pyimod03_importers.py", line 495, in
> exec_module File "oracledb/connection.py", line 45, in <module>
> File "src/oracledb/base_impl.pyx", line 47, in init oracledb.base_impl
> ModuleNotFoundError: No module named 'secrets' [23464] Failed to
> execute script 'my_script' due to unhandled exception!

Python 3.6

From this post I understand that Python 3.6 is a dependency.

In our environment we have both Python 3.6.8 and Python 2.7

Build with Python3

Based on comments from this post, I then tried the following command to build my executable:

python3 -m PyInstaller -F my_script.py

I still get the same error.

I suspect it has something to do with the 2 versions of Python, but I do not know how to get around it. Does anyone have some advise for me please?

答案1

得分: 2

The oracledb module uses Cython for its base layer, which means that the modules it imports are not going to be known to PyInstaller. These modules can be found in src/oracledb/*.pyx. You can tell PyInstaller about them, or you can also just copy/paste the imports into a Python module that you include in my_script.py. I don't know PyInstaller well enough to be able to tell you how to do the first option, but I'm sure its documentation will get you going!

英文:

The oracledb module uses Cython for its base layer, which means that the modules it imports are not going to be known to PyInstaller. These modules can be found in src/oracledb/*.pyx. You can tell PyInstaller about them, or you can also just copy/paste the imports into a Python module that you include in my_script.py. I don't know PyInstaller well enough to be able to tell you how to do the first option, but I'm sure its documentation will get you going!

huangapple
  • 本文由 发表于 2023年3月1日 12:28:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75599583.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定