问题描述
环境:
Mac OS X Catalina 10.15.6 Python 8
嗨, 我尝试用py2app编译我的python代码。 这是我的setup.py:
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['MyApp.py']
APP_NAME = "MyApp"
DATA_FILES = [ 'necessary_files/create_db.sql','necessary_files/fra.traineddata','necessary_files/ui.txt','MyApp_Install.sh','necessary_files/assets','necessary_files/cgi','necessary_files/selenium','ui/']
OPTIONS = {
'iconfile': 'MyApp_icon.icns','packages': ['requests','selenium'],'plist': {
'CFBundleName': APP_NAME,'CFBundledisplayName': APP_NAME,'CFBundleGetInfoString': "Marketing Bot",'CFBundleIdentifier': "com.cff.MyApp",'CFBundLeversion': "0.0.2",'CFBundleShortVersionString': "0.0.2",'NSHumanReadablecopyright': u"copyright © 2020,CFF,All Rights Reserved"}
}
setup(
app=APP,data_files=DATA_FILES,options={'py2app': OPTIONS},setup_requires=['py2app'],)
编译完成后,我在终端中使用此命令运行应用程序,以查看错误并得到此信息:
/Users/gauthierbtz/DropBox/cff/Python/MyApp_0002_FINAL/dist/MyApp.app/Contents/MacOS/MyApp ; exit;
(base) gauthierbtz@MacBook-de-Gauthier ~ % /Users/gauthierbtz/DropBox/cff/Python/MyApp_0002_FINAL/dist/MyApp.app/Contents/MacOS/MyApp ; exit;
Traceback (most recent call last):
File "/Users/gauthierbtz/DropBox/cff/Python/MyApp_0002_FINAL/dist/MyApp.app/Contents/Resources/__boot__.py",line 115,in <module>
_run()
File "/Users/gauthierbtz/DropBox/cff/Python/MyApp_0002_FINAL/dist/MyApp.app/Contents/Resources/__boot__.py",line 84,in _run
exec(compile(source,path,"exec"),globals(),globals())
File "/Users/gauthierbtz/DropBox/cff/Python/MyApp_0002_FINAL/dist/MyApp.app/Contents/Resources/MyApp.py",line 29,in <module>
import mymodules
File "<frozen zipimport>",line 259,in load_module
File "mymodules.pyc",line 5,in <module>
File "<frozen zipimport>",in load_module
File "ssl.pyc",line 98,in <module>
ImportError: dlopen(/Users/gauthierbtz/DropBox/cff/Python/MyApp_0002_FINAL/dist/MyApp.app/Contents/Resources/lib/python3.8/lib-dynload/_ssl.so,2): Library not loaded: @rpath/libssl.1.1.dylib
Referenced from: /Users/gauthierbtz/DropBox/cff/Python/MyApp_0002_FINAL/dist/MyApp.app/Contents/Resources/lib/python3.8/lib-dynload/_ssl.so
Reason: image not found
2020-09-12 22:15:58.769 MyApp[81463:1290389] MyApp Error
我使用命令“ brew reinstall openssl”重新安装openssl
export PATH="/usr/local/opt/openssl\@1.1/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl\@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl\@1.1/include"
我重新启动终端。
我在终端中输入了以下几行:
export LDFLAGS="-L/usr/local/opt/openssl\@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl\@1.1/include"
我仍然收到相同的错误消息。我不知道该怎么办。
如果可以,我在这里上传了编译日志。我没有看到任何奇怪的东西: https://github.com/gauthierbuttez/public/blob/master/logs_py2app.txt
有人可以帮我吗?
解决方法
我偶然发现了在构建可执行文件的链接器阶段可以链接共享库但在运行时找不到的相同问题。在我的情况下,解决方案是在我运行程序时告诉 dyld 在正确的路径中查找共享库:
DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/PATH_TO/YOUR_/DYLIB_FILE Run_me
我希望这对你也有用。