我已经使用bottle开发了python应用程序(在Linux中,并一直尝试使用以下命令将其打包为单个文件:-
pyinstaller --add-data 'static:static' --add-data 'views:views' myapplication.py --onefile --noconsole
Pyinstaller没有显示任何错误,但是当我启动该应用程序时,我在网络浏览器中收到一条错误消息,指出未找到模板。
该应用程序无需包装即可正常工作。
有人可以指出我正确的方向吗?谢谢。
=================================>
附加信息:
在我的装瓶代码中,我有以下内容:-
@route('/' + TEMP_DIR + '/<filename:path>') def send_static(filename): return static_file(filename, root='./' + TEMP_DIR) @route('/css/<filename:path>') def send_static(filename): return static_file(filename, root='./static/css') @route('/js/<filename:path>') def send_static(filename): return static_file(filename, root='./static/js') @route('/img/<filename:path>') def send_static(filename): return static_file(filename, root='./static/img') @route('/') def home(): info = {'application_name': APPLICATION_NAME, 'version': VERSION} return template('main_page.tpl', info)
HTML中的代码示例:-
<head> <link rel="stylesheet" href="/css/styles.css"> </head>
目录结构:-
myapp.py + +----static | +-----css/<css files> | +-----js/<js files> | +-----img/<img files> | +----views +-----<tpl files>
顺便说一句,如果我将static和views目录放入包含已编译的二进制文件的文件夹中,则该应用程序可以正常工作。
[我已经使用bottle开发了python应用程序(在Linux中,并且一直在尝试使用以下命令将其打包为单个文件:-pyinstaller --add-data'static:static'--add-data'views:views '...
我终于详细查看了PyInstaller和Bottle文档,使它正常工作。这是我的方法:-