1. 调用manage.py报错
在安装Mathematica的开源替代版Mathics后初始化时,调用manage.py报错:
Traceback (most recent call last):
File "mathics/manage.py", line 3, in <module>
from django.core.management import execute_manager
ImportError: cannot import name execute_manager
经搜索后找到解决方法(产生这一错误的原因参见https://docs.djangoproject.com/en/1.4/releases/1.4/#updated-default-project-layout-and-manage-py),需要修改所调用的manage.py。
对Mathics所用的manage.py,修改前的manage.py:
#!/usr/bin/env python
from django.core.management import execute_manager
try:
import settings # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write(
"""Error: Can't find the file 'settings.py' in the directory containing
%r. It appears you've customized things.\n
You'll have to run django-admin.py, passing it your settings module.
(If the file settings.py does indeed exist, it's causing an ImportError.)\n"""
% __file__)
sys.exit(1)
if __name__ == "__main__":
execute_manager(settings)
# fix known PyPy bug (see https://bugs.pypy.org/issue1116)
import gc
gc.collect()
gc.collect()
修改后的manage.py:
#!/usr/bin/env python
import os, sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
# fix known PyPy bug (see https://bugs.pypy.org/issue1116)
import gc
gc.collect()
gc.collect()
主要改动是将import execute_manager 修改为 import execute_from_command_line。更详细的修改说明参见上文链接。
2. 使用django.utils.simplejson报错
上述初始化成功后,Mathics仍无法正常启动,报错如下:
Traceback (most recent call last):
File "/usr/local/bin/mathics", line 9, in <module>
load_entry_point('Mathics==0.6.0rc1', 'console_scripts', 'mathics')()
File "/usr/local/lib/python2.7/dist-packages/Mathics-0.6.0rc1-py2.7.egg/mathics/main.py", line 214, in main
definitions = Definitions(add_builtin=True)
File "/usr/local/lib/python2.7/dist-packages/Mathics-0.6.0rc1-py2.7.egg/mathics/core/definitions.py", line 49, in __init__
from mathics.builtin import modules, contribute
File "/usr/local/lib/python2.7/dist-packages/Mathics-0.6.0rc1-py2.7.egg/mathics/builtin/__init__.py", line 21, in <module>
from mathics.builtin import (
File "/usr/local/lib/python2.7/dist-packages/Mathics-0.6.0rc1-py2.7.egg/mathics/builtin/graphics.py", line 9, in <module>
from django.utils import simplejson
ImportError: cannot import name simplejson
报错信息看下来是在“django.utils”中没有simplejson这一模块所致,经搜索后得知simpljson已在最新版的django中移除了(参见https://docs.djangoproject.com/en/dev/releases/1.7/#features-removed-in-1-7),而这一模块可用标准库中的json代替。解决方法为将py脚本中所有使用simplejson的地方改为json。如将报错信息中提到的graphics.py里的
from django.utils import simplejson
改为:
import json as simplejson