美好的一天,现在面临一个奇怪的问题3天,到目前为止我找不到任何解决方案。我读了很多答案,但到目前为止他们仍然没有帮助我。这是我收到的项目追溯:
(empire243)drcongo@congodevpro:~$ django-admin check
Traceback (most recent call last):
File "/home/drcongo/.virtualenvs/empire243/bin/django-admin", line 11, in <module>
sys.exit(execute_from_command_line())
File "/home/drcongo/.virtualenvs/empire243/lib/python3.4/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
utility.execute()
File "/home/drcongo/.virtualenvs/empire243/lib/python3.4/site-packages/django/core/management/__init__.py", line 303, in execute
settings.INSTALLED_APPS
File "/home/drcongo/.virtualenvs/empire243/lib/python3.4/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/home/drcongo/.virtualenvs/empire243/lib/python3.4/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/drcongo/.virtualenvs/empire243/lib/python3.4/site-packages/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/drcongo/.virtualenvs/empire243/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/drcongo/empireInstances/empireApp/dev_settings.py", line 1, in <module>
from empireMarket.settings import *
ImportError: No module named 'empireMarket'
(empire243)drcongo@congodevpro:~$
这是我的dev_settings:
dev_settings.py
from empireMarket.settings import *
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os.path
BASE_DIR = os.path.dirname(__file__)
#BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = 'sfsdvvsdfwerwrff'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
INTERNAL_HOSTS = [
'127.0.0.1',
'10.0.0.2',
]
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# BOWER_COMPONENTS_ROOT = os.path.join(BASE_DIR, 'static')
# Django Debug Toolbar
INSTALLED_APPS = list(INSTALLED_APPS) + ['debug_toolbar']
这是我的项目结构:
(empire243)drcongo@congodevpro:~/EmpireProjects$ tree
.
└── empireMarket // dJANGO GENERATED PROJECT BY DJANGO-ADMIN.PY STARTPROJECT
├── manage.py
└── src
├── empireMarket
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── empireWeb
├── admin.py
├── __init__.py
├── migrations
│ └── __init__.py
├── models.py
├── tests.py
└── views.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'empireWeb',
)
实例目录:
(empire243)drcongo@congodevpro:~/empireInstances$ tree
.
└── empireApp
├── dev_settings.py
└── __pycache__
└── dev_settings.cpython-34.pyc
2 directories, 2 files
settings.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'empireWeb',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'empireMarket.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'empireMarket.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
# }
#
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/
&#39;
一切正常但我仍然收到导入错误。任何帮助都会非常有用。我正在使用python3
答案 0 :(得分:1)
看起来项目没有安装到virtualenv中。
通常的做法是为您的包定义setup.py
,它应该包含在包的根目录中(通常是包含src
的目录)。最小的可能看起来像这样:
<强> empireMarket / setup.py 强>
from setuptools import setup, find_packages
setup(
name='empireMarket',
package_dir={'': 'src'},
packages=find_packages('src'),
include_package_data=True,
install_requires=[
'Django',
]
),
完成后,您可以使用pip install <dir>
或pip install -e <dir>
将您的软件包安装到virtualenv中。
完成后,导入empireMarket.settings
应该有效。