我正在使用Django 1.8和Python-3.4开展项目
我想安装mockups包,以便在我的应用程序中自动创建数据。
我已使用pip install django-mockups
和easy_install django-mockups
我在settings.py文件中的INSTALLED_APPS中添加'mockups'条目
INSTALLED_APPS = (
'suit',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mockups',
'tracks',
'albums',
'artists',
'userprofiles',
)
我想在我的控制台里面的django管理实用程序中看到我的命令与我安装的软件包有关,但最后,我收到了有关我的环境变量DJANGO_SETTINGS_MODULE
的注释信息,我看不到列表中的django-mockups包
(venv)➜ myproject django-admin help
Type 'django-admin help <subcommand>' for help on a specific subcommand.
Available subcommands:
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
runfcgi
runserver
shell
showmigrations
sql
sqlall
sqlclear
sqlcustom
sqldropindexes
sqlflush
sqlindexes
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
syncdb
test
testserver
validate
Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.).
(venv)➜myproject
我检查安装了django-mockups包,检查以下路径目录,实际上存在。
/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django_mockups-0.4.8.dist-info` and
/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/mockups`
已安装django-mockups
个包
(venv)➜ mockups pip freeze
Django==1.8.2
django-mockups==0.4.8
django-suit==0.2.13
Pillow==2.9.0
wheel==0.24.0
(venv)➜ mockups
我的DJANGO_SETTINGS_MODULE
就是这样的:
在manage.py
文件
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sfotipy.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
在wsgi.py
中"""
WSGI config for myproject project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
application = get_wsgi_application()
最后当我尝试启动django服务器时,我得到了这个输出:
(venv)➜ myproject ./manage.py runserver
/home/bgarcial/.virtualenvs/venv/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
return f(*args, **kwds)
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django/apps/config.py", line 86, in create
module = import_module(entry)
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
File "<frozen importlib._bootstrap>", line 2203, 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 1448, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/mockups/__init__.py", line 2, in <module>
from mockups.factory import Factory
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/mockups/factory.py", line 1, in <module>
from mockups import generators
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/mockups/generators.py", line 100, in <module>
class StringGenerator(Generator):
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/mockups/generators.py", line 101, in StringGenerator
coerce_type = unicode
NameError: name 'unicode' is not defined
(venv)➜ myproject
如何正确设置我的DJANGO_SETTINGS_MODULE环境变量? 这个DJangO_SETTINGS_MODULE配置是该模型的起源不起作用吗? 坦克很多:)
由于
答案 0 :(得分:3)
我在github中找到了这个issue。
可能 django-mockups不支持Python 3。
Python 3将unicode
更改为str
,将旧版str
更改为bytes
。
因此,如果您使用Python 3运行django-mockups。NameError
将被引发
正如追溯所示,django-mockups是用Python 2编写的。