gpt4 book ai didi

python - couchbase 已安装,但仍然出现导入错误(Pyinstaller)

转载 作者:行者123 更新时间:2023-11-30 23:10:18 24 4
gpt4 key购买 nike

我正在尝试使用pyinstaller构建Python源代码。构建成功后,我将运行二进制文件。运行二进制文件后,我收到以下 ImportError:

PyUtils.CouchbaseClient", line 13, in <module>
ImportError: No module named couchbase

但是 couchbase 已经安装,并且我能够运行原始的 Python 源代码而不会出现任何导入错误。转换为二进制文件后,我收到 ImportError。

任何帮助将不胜感激。

最佳答案

由于您的程序动态导入couchbasepyinstaller无法检测到它是必需的,如 documentation 中指定的那样。 :

Some Python scripts import modules in ways that PyInstaller cannot detect: for example, by using the __import__() function with variable data, or manipulating the sys.path value at run time.

Another section of the documentation扩展了这个问题并提出了一些处理这种情况的解决方法:

If Analysis thinks it has found all the imports, but the app fails with an import error, the problem is a hidden import; that is, an import that is not visible to the analysis phase.

Hidden imports can occur when the code is using __import__ or perhaps exec or eval. You get warnings of these (see Build-time Messages).

Hidden imports can also occur when an extension module uses the Python/C API to do an import. When this occurs, Analysis can detect nothing. There will be no warnings, only a crash at run-time.

To find these hidden imports, set the -v flag (Getting Python's Verbose Imports above).

Once you know what they are, you add the needed modules to the bundle using the --hidden-import= command option, by editing the spec file, or with a hook file (see Using Hook Files below).

因此,您需要明确要求pyinstaller在构建过程中包含所需的模块。似乎最简单的方法是使用 --hidden-import论据:

--hidden-import=modulename
Name an imported Python module that is not visible in your code. The module will be included as if it was named in an import statement. This option can be given more than once.

因此,请在构建应用程序时添加以下参数:

--hidden-import=couchbase

<小时/>

但是,一旦PyInstaller检测到需要couchbase,运行生成的可执行文件就会失败,并出现ImportError:

ImportError: No module named _libcouchbase

This answer描述了应该采取哪些措施来解决该问题。

关于python - couchbase 已安装,但仍然出现导入错误(Pyinstaller),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30752558/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com