首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cherrypy无法找到wsgiserver模块当包装在cannot冷冻

Cherrypy无法找到wsgiserver模块当包装在cannot冷冻
EN

Stack Overflow用户
提问于 2015-07-15 20:21:30
回答 1查看 3.8K关注 0票数 2

我正在部署一个cherrypy应用程序,将其打包到一组带有cx_freeze的可执行文件中。

我使用python 3(通过CentOS中的scl )。为了编译二进制文件,我运行:

代码语言:javascript
复制
scl enable python33 -- cxfreeze server.py

其中server.py是条目脚本。

当我执行生成的文件时,服务器启动并立即停止,出现错误:

代码语言:javascript
复制
Traceback (most recent call last):
  File "/opt/rh/python33/root/usr/lib/python3.3/site-packages/cherrypy/process/wspbus.py", line 205, in publish
    output.append(listener(*args, **kwargs))
  File "/opt/rh/python33/root/usr/lib/python3.3/site-packages/cherrypy/_cpserver.py", line 167, in start
    self.httpserver, self.bind_addr = self.httpserver_from_self()
  File "/opt/rh/python33/root/usr/lib/python3.3/site-packages/cherrypy/_cpserver.py", line 157, in httpserver_from_self
    from cherrypy import _cpwsgi_server
  File "/opt/rh/python33/root/usr/lib64/python3.3/importlib/_bootstrap.py", line 1616, in _handle_fromlist
    _call_with_frames_removed(import_, from_name)
  File "/opt/rh/python33/root/usr/lib64/python3.3/importlib/_bootstrap.py", line 313, in _call_with_frames_removed
    return f(*args, **kwds)
  File "/opt/rh/python33/root/usr/lib64/python3.3/importlib/_bootstrap.py", line 1567, in _find_and_load
    return _find_and_load_unlocked(name, import_)
  File "/opt/rh/python33/root/usr/lib64/python3.3/importlib/_bootstrap.py", line 1534, in _find_and_load_unlocked
    loader.load_module(name)
  File "/opt/rh/python33/root/usr/lib/python3.3/site-packages/cherrypy/_cpwsgi_server.py", line 7, in <module>
    from cherrypy import wsgiserver
  File "/opt/rh/python33/root/usr/lib64/python3.3/importlib/_bootstrap.py", line 1616, in _handle_fromlist
    _call_with_frames_removed(import_, from_name)
  File "/opt/rh/python33/root/usr/lib64/python3.3/importlib/_bootstrap.py", line 313, in _call_with_frames_removed
    return f(*args, **kwds)
  File "/opt/rh/python33/root/usr/lib64/python3.3/importlib/_bootstrap.py", line 1567, in _find_and_load
    return _find_and_load_unlocked(name, import_)
  File "/opt/rh/python33/root/usr/lib64/python3.3/importlib/_bootstrap.py", line 1534, in _find_and_load_unlocked
    loader.load_module(name)
  File "/opt/rh/python33/root/usr/lib/python3.3/site-packages/cherrypy/wsgiserver/__init__.py", line 14, in <module>
    exec('from .wsgiserver3 import *')
  File "<string>", line 1, in <module>
  File "/opt/rh/python33/root/usr/lib64/python3.3/importlib/_bootstrap.py", line 1567, in _find_and_load
    return _find_and_load_unlocked(name, import_)
  File "/opt/rh/python33/root/usr/lib64/python3.3/importlib/_bootstrap.py", line 1531, in _find_and_load_unlocked
    raise exc
ImportError: No module named 'cherrypy.wsgiserver.wsgiserver3'

在其余部分中,cx冻结脚本输出包含以下一行:

代码语言:javascript
复制
Missing modules:
[...]
? wsgiserver2 imported from cherrypy.wsgiserver
[...]
This is not necessarily a problem - the modules may not be needed on this platform.

在/opt/rh/python33/root/usr/lib/python3.3/site-packages/cherrypy/wsgiserver/__init__.py中,我可以看到:

代码语言:javascript
复制
import sys
if sys.version_info < (3, 0):
    from wsgiserver2 import *
else:
    # Le sigh. Boo for backward-incompatible syntax.
    exec('from .wsgiserver3 import *')

我想知道为什么wsgiserver没有正确地进口。

我还试图将wsgiserver3模块显式地包含在setup.py中:

代码语言:javascript
复制
buildOptions = {
    'packages' : ['cherrypy'],
    'includes' : ['cherrypy.wsgiserver.wsgiserver3'],
    'excludes' : [],
    'path' : sys.path,
}

import sys
base = 'Win32Service' if sys.platform=='win32' else None

executables = [
    Executable('server.py', base=base, targetName = 'myapp')
]

setup(name='Myapp',
      version = '1.0beta1',
      description = 'My App',
      options = dict(build_exe = buildOptions),
      executables = executables)

有什么暗示吗?

谢谢,

通用汽车

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-16 13:34:01

这个问题包括了答案。一定是在做某种依赖分析。我不知道具体的方法是什么,例如,它可以是一个AST遍历,但是它正在做的是查找import,当一个库做了像exec('from .wsgiserver3 import *')这样的动态导入时,不会识别它。因此,您需要在cx冻结配置中显式列出这些模块。我看到配置选项调用--include-modules

顺便说一句,出于同样的原因,动态导入CherryPy 3.5 (据我所知)车轮分布缺乏相同的wsgiserver3模块。

更新

以下是distutils commands文档部分的引文

若要在脚本中指定选项,请在名称中使用下划线。例如: 安装程序(options= {'build_exe':{‘init_script’:‘Console’}) 若要在命令行中指定相同的选项,请使用破折号,如下所示: python setup.py build_exe -init-脚本控制台

更新2

好的,我临时安装了cx_freeze (没那么快,只是在这句话的帮助下),自己做了测试。

app.py

代码语言:javascript
复制
#!/usr/bin/env python3


import cherrypy


class App:

  @cherrypy.expose
  def index(self):
    return 'Hello world!'


if __name__ == '__main__':
  cherrypy.quickstart(App(), '/')

setup.py

代码语言:javascript
复制
import sys

from cx_Freeze import setup, Executable


options = {
  'build_exe' : {
    'includes' : 'cherrypy.wsgiserver.wsgiserver3'
  }
}
executables = [Executable('app.py')]

setup(
  name        = 'CherryPyApp',
  version     = '0.1',
  description = 'Testing CherryPy wsgiserver3 dynamic import',
  options     = options,
  executables = executables
)

它确实适用于{'includes': 'cherrypy.wsgiserver.wsgiserver3'},没有它也不行,ImportError("No module named 'cherrypy.wsgiserver.wsgiserver3'",)

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31440277

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档