简体   繁体   English

PyInstaller 中的隐藏导入不起作用?

[英]Hidden import in PyInstaller not working?

I am trying to create an executable using PyInstaller.我正在尝试使用 PyInstaller 创建可执行文件。 Important files for my problem are: main.py and dbinterface.py which are both located at the root level.我的问题的重要文件是: main.pydbinterface.py ,它们都位于根级别。

In dbinterface.py I am doing: import mysql.connector which would need to be added as an hidden-import to PyInstaller as I assume.dbinterface.py中,我正在做: import mysql.connector ,正如我所假设的那样,它需要作为隐藏导入添加到 PyInstaller。

I tried this by adding --hidden-import pyinstaller mysql.connector and also by changing the spec-file which I am honestly not sure about whether I did this correctly.我通过添加--hidden-import pyinstaller mysql.connector以及更改规范文件来尝试此操作,老实说我不确定我是否正确地执行了此操作。

PyInstaller show in the command line following line in it's output: 4448 ERROR: Hidden import 'mysql.connector' not found PyInstaller 在命令行中的以下行中显示 output: 4448 ERROR: Hidden import 'mysql.connector' not found

The problem was that I had to install mysql-connector-python globally in Python.问题是我必须在 Python 中全局安装mysql-connector-python It's not working if you have them only instaled in your virtual environment.如果您仅将它们安装在虚拟环境中,则它不起作用。

You most probably need to also install your PyInstaller into the virtual environment and run PyInstaller from the virtual environment, not the one that is installed globally您很可能还需要将 PyInstaller 安装到虚拟环境中并从虚拟环境运行 PyInstaller,而不是全局安装的环境

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM