【问题标题】:Unknown Command "syncdb" when calling from an external exe file made by pyinstaller从 pyinstaller 生成的外部 exe 文件调用时出现未知命令“syncdb”
【发布时间】:2014-04-08 14:09:59
【问题描述】:

我有一个名为 db 的文件夹

分贝
------ __init__.py
------ dbobject.py
------ models.py
------ settings.py

__init__.py里面

from django.conf import settings

def syncdb():
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "db.settings")
    from django.core.management import call_command
    call_command('syncdb', interactive=False)

然后我在 site-packages 中使用 python distutils 安装了这个 db 文件夹。

现在我有另一个名为 cron 的文件夹包含:

  • main.py
  • settings.py

settings.py

from db import syncdb
syncdb()

在这里有效。

然后制作了main.py的可执行文件

运行 main.exe 后出现错误:

django.core.management.CommandError: Unknown Command: 'syncdb'

【问题讨论】:

  • syncdb 可能应该在项目文件夹中运行,所以尝试将所有文​​件一起包含在 main.exe 中
  • 我需要与许多其他脚本共享同一个 db 文件夹,这就是我将其分开放置的原因。

标签: python django pyinstaller syncdb


【解决方案1】:

在运行 syncdb 函数之前尝试将工作目录更改为您的项目文件夹:

import os
from db import syncdb

os.chdir(path_to_your_project) # Change working dir.
syncdb()

【讨论】:

    猜你喜欢
    • 2022-07-19
    • 2015-04-25
    • 2015-04-11
    • 2020-12-25
    • 2022-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-21
    相关资源
    最近更新 更多