Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将python瓶子应用程序打包为单个应用程序_Python_Pyinstaller_Bottle - Fatal编程技术网

将python瓶子应用程序打包为单个应用程序

将python瓶子应用程序打包为单个应用程序,python,pyinstaller,bottle,Python,Pyinstaller,Bottle,我使用BATTLE(Linux)开发了一个python应用程序,并尝试使用以下方法将其打包为单个文件:- pyinstaller --add-data 'static:static' --add-data 'views:views' myapplication.py --onefile --noconsole @route('/' + TEMP_DIR + '/<filename:path>') def send_static(filename): return stati

我使用BATTLE(Linux)开发了一个python应用程序,并尝试使用以下方法将其打包为单个文件:-

pyinstaller --add-data 'static:static' --add-data 'views:views' myapplication.py --onefile --noconsole
@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)
Pyinstaller没有显示任何错误,但是当我启动应用程序时,我在web浏览器中收到一个错误,说找不到模板

该应用程序无需包装即可正常工作

有人能给我指一下正确的方向吗?多谢各位

=================================

其他信息:

在我的瓶子代码中,我有以下内容:-

pyinstaller --add-data 'static:static' --add-data 'views:views' myapplication.py --onefile --noconsole
@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)
@route('/'+TEMP_DIR+'/'))
def send_静态(文件名):
返回静态_文件(文件名,根='./'+TEMP_DIR)
@路由(“/css/”)
def send_静态(文件名):
返回静态_文件(文件名,根='./static/css')
@路由(“/js/”)
def send_静态(文件名):
返回静态文件(文件名,根='./static/js')
@路由('/img/'))
def send_静态(文件名):
返回静态文件(文件名,根='。/static/img')
@路由(“/”)
def home():
信息={'application\u name':application\u name,'version':version}
返回模板('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>
myapp.py
+
+----静止的
|+----css/
|+----js/
|+----img/
|
+----观点
+-----

顺便说一句,如果我将static和views目录放入包含编译过的二进制文件的文件夹中,应用程序就会工作。

我通过详细阅读PyInstaller和瓶子文档,最终使它工作起来。我就是这样做的:-

在PiInstaller将文件解包到tmp目录时,我在瓶子应用程序中添加了以下内容(仅示例)。代码告诉瓶子在哪里找到未打包的文件

BUNDLE_TEMP_DIR = ''

try:

if getattr(sys, 'frozen') and hasattr(sys, '_MEIPASS'):
    BUNDLE_TEMP_DIR = sys._MEIPASS
    #Modify template
    bottle.TEMPLATE_PATH.insert(0,BUNDLE_TEMP_DIR + '/views')

except:

BUNDLE_TEMP_DIR= '' 

@route('/css/<filename:path>')
def send_static(filename):
    if (BUNDLE_TEMP_DIR != ''):
        return static_file(filename, root= BUNDLE_TEMP_DIR + '/static/css')
    else:
        return static_file(filename, root='./static/css')
BUNDLE\u TEMP\u DIR=''
尝试:
如果getattr(sys,'冻结')和hasattr(sys,'u MEIPASS'):
捆束温度目录=系统
#修改模板
瓶子模板路径插入(0,捆绑临时目录+'/views')
除:
BUNDLE_TEMP_DIR=''
@路由(“/css/”)
def send_静态(文件名):
如果(BUNDLE_TEMP_DIR!=''):
返回静态文件(文件名,root=BUNDLE\u TEMP\u DIR+'/static/css')
其他:
返回静态_文件(文件名,根='./static/css')
然后,我使用以下命令运行PyInstaller(我的目录结构如下所示):

python3-m PyInstaller--name busker-helper--add data'static/css/:static/css'--add data'static/js/:static/js'--add data'static/css/:static/css'--add data'views/:views'busker-helper.py--onefile--noconsole

以上内容在linux下运行。在Windows中,将“:”(冒号)替换为“;”(分号)

您可能还需要在PyInstaller中包含--hidden import选项


希望以上内容能对您有所帮助。

欢迎来到StackOverflow!为了帮助您,我们需要查看代码的一部分以及您得到的确切错误(回溯)。