首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wkhtmltopdf OSError:[Errno 2]没有这样的文件或目录

wkhtmltopdf OSError:[Errno 2]没有这样的文件或目录
EN

Stack Overflow用户
提问于 2018-04-12 10:43:04
回答 1查看 1.9K关注 0票数 2

我正在尝试用pdfkit在我的烧瓶应用程序中生成一个pdf。

在本地主机上,应用程序工作正常,没有任何错误,在我将应用程序部署在ubuntu服务器vps上之后,当尝试生成pdf文件时,它在控制台中给出了这个错误:

代码语言:javascript
复制
Apr 12 16:31:51 ubuntu gunicorn[18725]:     self.configuration = (Configuration() if configuration is None
Apr 12 16:31:51 ubuntu gunicorn[18725]:   File "/home/userp/app/venv/local/lib/python2.7/site-packages/pdfkit/configuration.py", line 18, in 
Apr 12 16:31:51 ubuntu gunicorn[18725]:     ['which', 'wkhtmltopdf'], stdout=subprocess.PIPE).communicate()[0].strip()
Apr 12 16:31:51 ubuntu gunicorn[18725]:   File "/home/userp/app/venv/local/lib/python2.7/site-packages/gevent/subprocess.py", line 585, in __
Apr 12 16:31:51 ubuntu gunicorn[18725]:     reraise(*exc_info)
Apr 12 16:31:51 ubuntu gunicorn[18725]:   File "/home/userp/app/venv/local/lib/python2.7/site-packages/gevent/subprocess.py", line 554, in __
Apr 12 16:31:51 ubuntu gunicorn[18725]:     restore_signals, start_new_session)
Apr 12 16:31:51 ubuntu gunicorn[18725]:   File "/home/userp/app/venv/local/lib/python2.7/site-packages/gevent/subprocess.py", line 1312, in _
Apr 12 16:31:51 ubuntu gunicorn[18725]:     raise child_exception
Apr 12 16:31:51 ubuntu gunicorn[18725]: OSError: [Errno 2] No such file or directory

在下面的configuration.py文件中,如果我试图打印出self.wkhtmltopdf的值,它将显示文件路径/usr/bin/wkhtmltopdf

代码语言:javascript
复制
if not self.wkhtmltopdf:
    if sys.platform == 'win32':
        self.wkhtmltopdf = subprocess.Popen(
            ['where', 'wkhtmltopdf'], stdout=subprocess.PIPE).communicate()[0].strip()
    else:
        self.wkhtmltopdf = subprocess.Popen(
            ['which', 'wkhtmltopdf'], stdout=subprocess.PIPE).communicate()[0].strip()

try:
    with open(self.wkhtmltopdf) as f:
        pass
except IOError:
    raise IOError('No wkhtmltopdf executable found: "%s"\n'
                    'If this file exists please check that this process can '
                    'read it. Otherwise please install wkhtmltopdf - '
                    'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)

同时,键入which wkhtmltopdf也会得到相同的结果,这意味着程序已经安装好了。

我已经安装了所有必要的库,就像在我的机器上安装它们一样。

最有趣的是,如果我从python manage.py runserver运行这个应用程序,并试图生成pdf文件,它的get生成并且没有出现错误,但是从gunicorn和nginx就会出现错误!

我已经尽了一切努力,我也看到了很多文章,他们谈论这个问题,但没有用!

EN

回答 1

Stack Overflow用户

发布于 2018-04-30 13:43:45

问题很可能是无法在服务器vps中以无头状态运行wkhtmltopdf。

请看一下https://pypi.org/project/headless-pdfkit/0.1.1/#files

这还需要安装xvfb,它将在执行之前使用/bin/bash\nxvfb-运行wkhtmltopdf命令。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49794491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档