我正在尝试在Windows计算机上运行Django项目。我收到nomodulefounderror。该项目包含用于prod,Development和Test的多个设置文件。我正在使用一个虚拟环境,Python 2.7和Django 1.10版本我需要帮助才能在本地计算机上运行此项目。Python manage.py runserver --settings = settings_dev_sai这使我出错。这是我的错误日志
python manage.py runserver --settings=bridge.settings.settings_dev_sai
Traceback (most recent call last):
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 369, in execute
output = self.handle(*args, **options)
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\commands\runserver.py", line 67, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\conf\__init__.py", line 76, in __getattr__
self._setup(name)
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\conf\__init__.py", line 63, in _setup
self._wrapped = Settings(settings_module)
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\conf\__init__.py", line 142, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "F:\brdge\bridge_sai\bridge\settings.py", line 38, in <module>
from settings_dev_sai import *
ModuleNotFoundError: No module named 'settings_dev_sai'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 341, in run_from_argv
connections.close_all()
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\utils.py", line 225, in close_all
for alias in self:
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\utils.py", line 219, in __iter__
return iter(self.databases)
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\utils.py", line 153, in databases
self._databases = settings.DATABASES
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\conf\__init__.py", line 76, in __getattr__
self._setup(name)
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\conf\__init__.py", line 63, in _setup
self._wrapped = Settings(settings_module)
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\conf\__init__.py", line 142, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "F:\brdge\bridge_sai\bridge\settings.py", line 38, in <module>
from settings_dev_sai import *
ModuleNotFoundError: No module named 'settings_dev_sai'
我添加了elif HOST ==“ Sai”:从settings_dev_sai import *到Settings.py文件
import socket
#import settings depending on the box we are on
HOST = socket.gethostname()
TPA_CODE = "ge"
TPA_NAME = "Benefits System"
#development
if HOST == "BITS-DP-LAPTOP":
from settings_dev import *
TPA_NAME = "IA Benefit Services Ltd."
TPA_CODE = 'IA'
#DFG bridge
elif HOST == "dfginternal":
from settings_dfg_ees import *
TPA_NAME = "honey Financial Group"
TPA_CODE = 'DG'
#test
elif HOST == "DFGTEST02":
from settings_staging import *
elif HOST == "icbaweb":
from settings_production_icba import *
TPA_NAME = "IA Benefit Services Ltd."
TPA_CODE = 'IA'
elif HOST == "meritweb":
from settings_production_merit import *
TPA_NAME = "Construction Industry Benefit Plan"
TPA_CODE = 'MERIT'
elif HOST == "dfgweb" :
from settings_production_dfg import *
TPA_NAME = "honey Financial Group"
TPA_CODE = 'DG'
elif HOST == "dev" or HOST == "j-ubu" :
from settings_dev_baikal import *
elif HOST == "jdev" :
from settings_dev_juliab import *
elif HOST == "Sai" :
from settings_dev_sai import *
elif HOST == "johnstonesweb" :
from settings_production_johnstones import *
TPA_NAME = "Johnstone's Benefits"
TPA_CODE = 'JOHNSTONES'
elif HOST == "bridgedemo" :
from settings_demo import *
TPA_CODE = "Brge"
TPA_NAME = "Benefits System"
else:
raise ImportError("This server's hostname [" + HOST + "] does not have a proper expanded settings file. Please configure one.")
settings_dev_sai.py文件
import os
from settings_common import *
DEBUG = True
RUN_TYPE = RUN_DEV
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
#'NAME': 'bridge_icba',
'NAME': 'bridge_js',
#'NAME': 'bridge_dfg_internal',
#'NAME': 'bridge_dfg',
'HOST': 'localhost',
'USER': 'django',
'PASSWORD': 'bridge_user',
'PORT': '',
},
}
MEDIA_ROOT = 'C:/Users/David/Dropbox/Work - Bridge/Projects/bridge/MEDIA/'
MEDIA_URL = '/media/'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'messenger123'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = '[email protected]'
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = ("F:/brdge/bridge_sai/static",)
STATIC_PATH = 'F:/brdge/bridge_sai/static'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ["F:/brdge/bridge_sai/TEMPLATES",],
'APP_DIRS': False,
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.template.context_processors.request',
'django.contrib.messages.context_processors.messages',
'bridge.context_processors.global_settings',],
},
},
]
USE_ASSOCIATION_BANK_ACCOUNTS = True
Setting_common.py文件
ADMINS = ()
BRIDGE_VERSION = "3.6.1 Build 202004.4"
MANAGERS = ADMINS
TIME_ZONE = 'America/Vancouver'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
USE_TZ = False
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'Removed for Security reasons'
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'bridge.request_access.Middleware',
)
ROOT_URLCONF = 'bridge.urls'
WSGI_APPLICATION = 'bridge.wsgi.application'
TEST_RUNNER = ('django.test.runner.DiscoverRunner')
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'bridge',
'block',
'temporal',
'log',
'association',
'client',
'client_wizard',
'employee',
'employee_wizard',
'receivables',
'payables',
'reports',
'import_tool',
'user_accounts',
'carrier',
'commission',
# celery - async tasks.
'django_celery_results',
# ,'test_runner'
'client_portal',
#bootstrap forms for client portal
'edi',
'widget_tweaks',
'payroll_extract',
)
RQ_QUEUES = {
'default': {
'HOST': 'localhost',
'PORT': 6379,
'DB': 0,
'DEFAULT_TIMEOUT': 360,
},
}
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
# custom project settings follow...
LOGIN_URL = '/login'
LOGIN_REDIRECT_URL = '/'
AUTH_PROFILE_MODULE = "user_accounts.UserProfile"
COUNTRY_LOCALE = ''
SYSTEM_SALES_TAX = 'BC' #This is the province that the TPA client is based in. This is the fall back tax if nothing is set at the client level.
USE_ASSOCIATION_BANK_ACCOUNTS = False
ADMIN_FEE_ON_ZERO_PREMIUMS = False # overwrite by setting it to True in settings_production_BenefitAdminCompanyName.py if the Admin Fee is charged even if the current premium is zero.
# DEPRECIATED
INVOICE_ORDER = ('LIFE', 'AD&D', 'WI', 'LTD', 'DEPL', 'EHC', 'DENT', 'EAP', 'MSP', 'OPTLF', 'OSPLIF', 'OPTADD', 'OSPADD', 'VADD', 'CI',)
# END DEPRECIATED
# celery settings
CELERY_RESULT_BACKEND = 'django-db'
CELERY_IMPORTS = ("receivables.async_tasks",'edi.edi', 'payroll_extract.views')
INTERNAL_IPS = ('127.0.0.1')
'''
# RUN_TYPE is a binary flag - it can be any combination of RUN_*
# for ex. to set RUN_DEV and RUN_TEST at the same time use:
RUN_TYPE = RUN_DEV | RUN_TEST
# to check use:
if RUN_TYPE & RUN_DEV == RUN_DEV:
#...
# or
if RUN_TYPE & RUN_DEV:
#...
'''
RUN_DEV = 1
RUN_TEST = 2
RUN_PROD = 4
RUN_TYPE = RUN_PROD
USE_CACHE = True # enable/disable request level caching by @cache annotation
TRACK_CALLS = False # enable/disable function call count by @cache and @track annotations
TEST_CREATE_NEW_DUMP = True
TEST_RESTORE_DB = True
TEST_DB_TMPFS = False
TEST_LOG_FILE=''
TEST_USER = 'auto_test'
TEST_PSWD = 'pass'
LOG_SQL = False
USE_DEBUG_TOOLBAR = False
LEDGER_SWITCH_DATE = '2019-12-01'
manage.py文件
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bg.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
我认为您只需要运行它
python manage.py runserver --settings=bridge.settings_dev_sai
因为bridge.settings是文件而不是包