我只想使用Pylatex来生成pdf文件。我查看了基本的示例并重新运行了脚本,但它引发了错误: OSError: Errno2没有这样的文件或目录。
下面是我的脚本:
import sys
from pylatex import Document, Section, Subsection, Command
from pylatex.utils import italic, NoEscape
def fill_document(doc):
"""Add a section, a subsection and some text to the document.
:param doc: the document
:type doc: :class:`pylatex.document.Document` instance
"""
with doc.create(Section('A section')):
doc.append('Some regular text and some ')
doc.append(italic('italic text. '))
with doc.create(Subsection('A subsection')):
doc.append('Also some crazy characters: $&#{}')
if __name__ == '__main__':
reload(sys)
sys.setdefaultencoding('utf8')
# Basic document
doc = Document()
fill_document(doc)
doc.generate_pdf("full")
doc.generate_tex()以及错误:
Traceback (most recent call last):
File "/Users/code/Test Generator/Generate.py", line 34, in <module>
doc.generate_pdf("full")
File "/Library/Python/2.7/site-packages/pylatex/document.py", line 227, in generate_pdf
raise(os_error)
OSError: [Errno 2] No such file or directory有人能帮帮我吗?:-D非常感谢。
发布于 2016-10-20 03:49:02
根据错误周围的代码,您可能缺少一个latex编译器:
compilers = (
('latexmk', latexmk_args),
('pdflatex', [])
)试着这样做:
apt-get install latexmk发布于 2017-08-20 16:26:50
在运行python脚本时,您的PATH中是否包含pdflatex命令?并且要确保你已经安装了texlive,如果它仍然不能工作,请尝试安装latexmk。
我也有同样的问题,只要设置你的路径,考虑到你已经安装了texlive。
在我的例子中,问题在于路径。我使用Flask运行一个网站,使用uWsgi作为服务进行托管,路径是用我的virtualenv设置的。
所以我修复了添加":/usr/bin“的问题,并工作了,如下所示:
[Unit]
Description=uWSGI instance to serve myproject
After=network.target
[Service]
User=www-data
Group=www-data
WorkingDirectory=/sites/simapp
Environment="PATH=/env/flask3/bin:/usr/bin"
ExecStart=/env/flask3/bin/uwsgi --ini /sites/simapp/simapp.ini
[Install]
WantedBy=multi-user.targethttps://stackoverflow.com/questions/40039763
复制相似问题