gpt4 book ai didi

Python Sqlite3 not being found when packaged into an app through Py2App(通过Py2App打包到应用程序中时找不到Python sqlite3)

转载 作者:bug小助手 更新时间:2023-10-25 15:57:47 26 4
gpt4 key购买 nike



I made a stock management system using sqlite3 for the database and customtkinter for the GUI. The code works as intended when ran through VSCode. I am on MacOS Ventura on the apple silicon. I want to send the code as an app so it can be convenient for the end user.

我使用SQLITE3作为数据库,使用Customtkinter作为图形用户界面,制作了一个库存管理系统。在VSCode中运行代码时,代码可以正常工作。我在苹果硅片上的MacOS Ventura上。我想发送的代码作为一个应用程序,所以它可以方便最终用户。


After using py2app to package the code, the alias version and the deployment version runs as intended on the Dist directory. However when I take the code out of Dist, for example into my desktop, it runs into a launch error.

使用py2app打包代码后,别名版本和部署版本将按预期在dist目录上运行。然而,当我将代码从dist取出,例如放入我的桌面时,它遇到了启动错误。


ImportError: dlopen(/Users/name/Desktop/stockmanager.app/Contents/Resources/lib/python3.11/lib-dynload/_sqlite3.so, 0x0002): Symbol not found: _sqlite3_enable_load_extension
Referenced from: <8B6D5BCF-C215-35A7-B03F-EDE59AAF1BC3> /Users/name/Desktop/stockmanager.app/Contents/Resources/lib/python3.11/lib-dynload/_sqlite3.so
Expected in: <AB447288-47E6-30D9-BD4C-BDFDAE0CBBC3> /usr/lib/libsqlite3.dylib


From what I can understand it fails to find the Sqlite3 library. I installed python3.11 using homebrew and sqlite3 installs with that as default. Still I tried installing sqlite3 directly through homebrew. I even downloaded the sqlite3.dylib from the official website to insert into the package contents, but I don't know where I would do that.

从我所能理解的,它找不到Sqlite3库。我用homebrew安装了python3.11,sqlite3默认安装了它。我仍然尝试直接通过自制软件安装sqlite3。我甚至从官方网站下载了sqlite3.dylib来插入到包内容中,但我不知道在哪里可以这样做。


Since the code runs on VSCode and in the Dist directory normally, I can assume Sqlite3 is installed correctly on the system. I realise I could add the 'sqlite3.dylib' into the 'usr/lib/' directory but that feels like it would only fix it on this specific system. How can I package this correctly?

由于代码通常在VSCode上和dist目录中运行,因此我可以假定系统上正确安装了sqlite3。我意识到我可以将‘sqlite3.dylib’添加到‘usr/lib/’目录中,但感觉它只能在这个特定的系统上修复它。我怎样才能正确地包装这个呢?


更多回答

added information: I just ran the code again in VSCode and it gave me the same error I posted above. I closed out of VSCode and reopened it, and it worked as intended. Right now it seems to be an inconsistent mess, which is funny cause that's the reason I used python over java haha.

添加信息:我只是在VSCode中再次运行代码,它给了我与上面发布的相同的错误。我关闭了VSCode,然后重新打开它,它按预期工作。现在,它似乎是一个不一致的混乱,这是有趣的原因,这就是为什么我使用了Python而不是Java哈哈。

优秀答案推荐

Just to clarify, are you using a venv (virtual environment) inside of the VSCode project? If so, I might try using cxFreeze as I've personally had much more luck getting it to work consistently. You simply need to add a setup.py file to the root directory, then put this in there:

只是为了澄清一下,您是否在VSCode项目中使用venv(虚拟环境)?如果是这样的话,我可能会尝试使用cxFreeze,因为我个人让它一致工作的运气要好得多。您只需将一个setup.py文件添加到根目录,然后将以下代码放入其中:


from cx_Freeze import setup,Executable

include_files: [str] = [<files to include>]

options = {
'build.exe': {
'include_files':include_files
}
}

setup(
name="<title>",
version=<version in float (like 0.1)>,
description="<description>",
executables=[Executable("<path to main from root>", base="Win32GUI")],
options=options
)

Then run python setup.py build from the root directory, and you should have. build folder with a functioning .exe file.

然后从根目录运行python setup.py构建,您应该已经完成了。包含可正常运行的.exe文件的Build文件夹。


If, for some reason, you don't have a venv setup, your first order of business is definitely going to be to get that venv setup because it makes this whole process so much easier. Here is a pretty good guide: https://code.visualstudio.com/docs/python/environments

如果出于某种原因,您没有设置venv,您的首要任务肯定是设置venv,因为它使整个过程变得容易得多。这里有一个非常好的指南:https://code.visualstudio.com/docs/python/environments


If you have any more questions feel free to comment and I'll try to help out.

如果您还有任何问题,请随时发表意见,我会尽力帮助您的。


更多回答

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