我想和Sphinx一起记录我的django项目,但我遇到了一些麻烦。
当我运行make html
命令时,我收到此错误:
/home/santoryu/richiestaTesi/docs/models/models.rst:3: WARNING: autodoc:
failed to import module u'myapp.models'; the following exception was
raised:
Traceback (most recent call last):
File "/home/santoryu/anaconda2/lib/python2.7/site-packages/Sphinx-
1.5.6-py2.7.egg/sphinx/ext/autodoc.py", line 560, in import_object
__import__(self.modname)
File "/home/santoryu/richiestaTesi/myapp/models.py", line 8
SyntaxError: Non-ASCII character '\xc3' in file
/home/santoryu/richiestaTesi/myapp/models.py on line 8, but no encoding
declared; see http://python.org/dev/peps/pep-0263/ for details
很明显,错误发生是因为在Anaconda中,非ASCII字符本身不受支持,但在Python 3.5.2中则是如此。所以我猜测如何强制由Python 3.5.2执行Sphinx?
答案 0 :(得分:1)
错误消息表明您已将Sphinx安装到Python 2.7虚拟环境中。
File "/home/santoryu/anaconda2/lib/python2.7/site-packages/Sphinx-
1.5.6-py2.7.egg/sphinx/ext/autodoc.py", line 560, in import_object
__import__(self.modname)
你也可能安装了Anaconda for Python 2.7而不是3.6。
确保下载并安装Anaconda for Python 3.6,并use Anaconda to create a virtual environment using Python 3.6安装Sphinx。