py2exe和Django导入错误没有名为apps的模块

时间:2015-09-23 09:16:47

标签: python django py2exe

我正在尝试使用py2exe创建一个独立的Django(1.8.2)应用程序。

为了实现这一点,我有一个setup.py文件,包含py2exe所需的所有设置:要包含的模块,不包括等等.py2exe控制台参数(在我的setup.py中)设置为'manage.py' 。用python setup.py py2exe py2exe运行后,成功运行所有(?)所需的模块和我的Django应用程序。我收到了一个manage.exe文件 - 看起来这个工作正常吗?

但是,运行manage.exe文件后,我收到以下错误:

File "manage.py", line 11, in <module>
File "django\core\management\__init__.pyo", line 338, in execute_from_command_line
File "django\core\management\__init__.pyo", line 312, in execute
File "django\__init__.pyo", line 18, in setup
File "django\apps\registry.pyo", line 85, in populate
File "django\apps\config.pyo", line 112, in create
File "importlib\__init__.pyo", line 37, in import_module
ImportError: No module named apps

我已将django.apps添加到setup.py导入模块部分,但未解决问题。为什么会发生这种情况以及如何解决这个问题?

更新:

对于setup.py文件,我已经关注了这个网站:https://misunderstandings.wordpress.com/2008/06/26/django-desktop-app/并在根据我的需求定制它之后就是我最终得到的结果:

setup.py:

# encoding: utf-8
from distutils.core import setup
import py2exe
import os
import reportlab

def add_path_tree( base_path, path, skip_dirs=[ '.svn', '.git' ]):
  path = os.path.join( base_path, path )
  partial_data_files = []
  for root, dirs, files in os.walk( os.path.join( path )):
    sample_list = []
    for skip_dir in skip_dirs:
      if skip_dir in dirs:
        dirs.remove( skip_dir )
    if files:
      for filename in files:
        sample_list.append( os.path.join( root, filename ))
    if sample_list:
      partial_data_files.append((
        root.replace(
          base_path + os.sep if base_path else '',
          '',
          1
        ),
        sample_list
      ))
  return partial_data_files


 py2exe_options = {
    'py2exe': {
      'compressed': 1,
      'optimize': 2,
      'ascii': 1,
      'bundle_files': 1,
      'dist_dir': 'dist',
      'packages': [ 'encodings','gabinet','pacjent','kalendarz','terapeuta','superwizja','ustawienia','zapiszsesje_registration', ],
      'excludes' : [
        'pywin',
        'pywin.debugger',
        'pywin.debugger.dbgcon',
        'pywin.dialogs',
        'pywin.dialogs.list',
        'Tkconstants',
        'Tkinter',
        'tcl',
      ],
      'dll_excludes': [ 'w9xpopen.exe', 'MSVCR71.dll' ],
      'includes': [
        'django.template.loaders.filesystem',
        'django.template.loaders.app_directories',
        'django.middleware.common',
        'django.contrib.sessions.middleware',
        'django.contrib.auth.middleware',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.sessions.backends.db',
        'django.contrib.sites',
        'django.contrib.admin',
        'django.core.cache.backends',
        'django.db.backends.sqlite3.base',
        'django.db.backends.sqlite3.introspection',
        'django.db.backends.sqlite3.creation',
        'django.db.backends.sqlite3.client',
        'django.template.defaulttags',
        'django.template.defaultfilters',
        'django.template.loader_tags',
        'django.contrib.admin.views.main',
        'django.core.context_processors',
        'django.contrib.auth.views',
        'django.contrib.auth.backends',
        'django.views.static',
        'django.views.defaults',
        'django.core.cache.backends.locmem',
        'django.templatetags.i18n',
        'django.views.i18n',
        'django.apps',
        'email.mime.audio',
        'email.mime.base',
        'email.mime.image',
        'email.mime.message',
        'email.mime.multipart',
        'email.mime.nonmultipart',
        'email.mime.text',
        'email.charset',
        'email.encoders',
        'email.errors',
        'email.feedparser',
        'email.generator',
        'email.header',
        'email.iterators',
        'email.message',
        'email.parser',
        'email.utils',
        'email.base64mime',
        'email.quoprimime',
            'django.db.backends.sqlite3.base',
        'django.db.backends.sqlite3.introspection',
        'django.db.backends.sqlite3.creation',
        'django.db.backends.sqlite3.client',
        'django.apps', 
        'django.template.defaulttags',
        'django.template.defaultfilters',
        'django.template.loader_tags',
        'django.core.wsgi',
        'gabinet.forms',
        'gabinet.models',
        'gabinet.urls',
        'gabinet.views',
        'kalendarz.forms',
        'kalendarz.models',
        'kalendarz.urls',
        'kalendarz.views',
        'pacjent.forms',
        'pacjent.models',
        'pacjent.urls',
        'pacjent.views',
        'superwizja.models',
        'superwizja.urls',
        'superwizja.urls',
        'superwizja.views',
        'terapeuta.models',
        'terapeuta.settings',
        'terapeuta.urls',
        'terapeuta.views',
        'terapeuta.wsgi',
        'ustawienia.forms',
        'ustawienia.models',
        'ustawienia.urls',
        'ustawienia.views',
        'zapiszsesje_registration.auth_urls',
        'zapiszsesje_registration.forms',
        'zapiszsesje_registration.models',
        'zapiszsesje_registration.urls',
        'zapiszsesje_registration.views',
      ],
    }
  }

  # Take the first value from the environment variable PYTHON_PATH
  python_path = os.environ[ 'PYTHONPATH' ].split( ';' )[ 0 ]

  django_admin_path = os.path.normpath( python_path + '/lib/site-packages/django/contrib/admin' )
  py2exe_data_files = []

  # django admin files
  py2exe_data_files += add_path_tree( django_admin_path, 'templates' )
  py2exe_data_files += add_path_tree( django_admin_path, 'media' )
  # project files
  py2exe_data_files += add_path_tree( '', 'db' )
  py2exe_data_files += add_path_tree( '', 'templates' )

  setup(
    options=py2exe_options,
    data_files=py2exe_data_files,
    zipfile = None,
    console=[ 'manage.py' ],
  )

0 个答案:

没有答案