简体   繁体   English

Flask 在 Linux 服务器(nginx+uwsgi)上找不到 Pandoc

[英]Flask cannot find Pandoc on Linux Server (nginx+uwsgi)

Hi just deployed my Flask application on my remote ubuntu server on Digital Ocean following this tutorial: https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uswgi-and-nginx-on-ubuntu-18-04 Hi just deployed my Flask application on my remote ubuntu server on Digital Ocean following this tutorial: https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uswgi-and-nginx-在 ubuntu-18-04

It all works fine except that when I import pyPandoc it cannot find pandoc .一切正常,除了当我导入pyPandoc时找不到pandoc My code to import pypandoc is this:我导入 pypandoc 的代码是这样的:

import pypandoc

try:
    from pypandoc.pandoc_download import download_pandoc
except:
    pass

and this was working fine on my local but I get an error on the server:这在我的本地工作正常,但我在服务器上收到错误:

[2020-04-09 16:16:37,027] ERROR in app: Exception on /get_all_articles [POST]
Traceback (most recent call last):
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "./main.py", line 285, in get_all_articles
    return jsonify(myFirebase.get_all_articles(pending))
  File "services/myFirebase.py", line 343, in get_all_articles
    text = pypandoc.convert_text(text,'html',format='md')
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-packages/pypandoc/__init__.py", line 103, in convert_text
    outputfile=outputfile, filters=filters)
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-packages/pypandoc/__init__.py", line 260, in _convert_input
    _ensure_pandoc_path()
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-packages/pypandoc/__init__.py", line 544, in _ensure_pandoc_path
    raise OSError("No pandoc was found: either install pandoc and add it\n"
OSError: No pandoc was found: either install pandoc and add it
to your PATH or or call pypandoc.download_pandoc(...) or
install pypandoc wheels with included pandoc.

I tried to install Pandoc via pip, apt, and even downloading the Debian file as suggested by the official Pandoc doc.我尝试通过 pip、apt 安装Pandoc ,甚至按照 Pandoc 官方文档的建议下载 Debian 文件。 Nothing seems to work.似乎没有任何效果。 on pyPandoc website: https://pypi.org/project/pypandoc/在 pyPandoc 网站上: https://pypi.org/project/pypandoc/

it says something about using wheel to install Pandoc but I'm not sure I understood what it means and I'm not familiar with the procedure.它说了一些关于使用轮子安装 Pandoc 的内容,但我不确定我是否理解它的含义并且我不熟悉该过程。 Do you have any idea on how to make pyPandoc working on my deployed Flask application?您对如何使 pyPandoc 在我部署的 Flask 应用程序上工作有任何想法吗?

ADDITIONAL INFO:附加信息:

my flask app is running in a virtual environment as by the tutorial linked above.我的 flask 应用程序按照上面链接的教程在虚拟环境中运行。 I tried to access Pandoc from within the virtual environment and this is my output:我试图从虚拟环境中访问 Pandoc,这是我的 output:

fmagarelli@InfantTestServer:~/Infant_Competition_Platform$ source venv3/bin/activate
(venv3) fmagarelli@InfantTestServer:~/Infant_Competition_Platform$ pandoc --version
pandoc 2.9.2.1
Compiled with pandoc-types 1.20, texmath 0.12.0.1, skylighting 0.8.3.2
Default user data directory: /home/fmagarelli/.local/share/pandoc or /home/fmagarelli/.pandoc
Copyright (C) 2006-2020 John MacFarlane
Web:  https://pandoc.org
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.

EDIT2 adding PDB: EDIT2 添加 PDB:

So change my imports to:所以将我的导入更改为:

from pypandoc.pandoc_download import download_pandoc
import pypandoc
import pdb; pdb.set_trace()

and now this is my output:现在这是我的 output:

[2020-04-09 17:31:46,358] ERROR in app: Exception on /get_all_articles [POST]
Traceback (most recent call last):
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-package
s/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-package
s/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-package
s/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-package
s/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-package
s/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-package
s/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "./main.py", line 285, in get_all_articles
    return jsonify(myFirebase.get_all_articles(pending))
  File "services/myFirebase.py", line 344, in get_all_articles
    art['title'] = line.replace('#','')
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-package
s/pypandoc/__init__.py", line 103, in convert_text
    outputfile=outputfile, filters=filters)
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-package
s/pypandoc/__init__.py", line 260, in _convert_input
    _ensure_pandoc_path()
  File "/home/fmagarelli/Infant_Competition_Platform/venv3/lib/python3.6/site-packages/pypandoc/__init__.py", line 544, in _ensure_pandoc_path
    raise OSError("No pandoc was found: either install pandoc and add it\n"
OSError: No pandoc was found: either install pandoc and add it
to your PATH or or call pypandoc.download_pandoc(...) or
install pypandoc wheels with included pandoc.
[pid: 1159|app: 0|req: 2/8] 46.7.82.176 () {48 vars in 893 bytes} [Thu Apr  9 17:31:46 2020] POST /get_all_articles => generated 290 bytes in 325 msecs (HTTP/1.1 500) 2 headers in 99 bytes (1 switches on core 0)
SIGINT/SIGQUIT received...killing workers...
worker 1 buried after 1 seconds
worker 2 buried after 1 seconds
worker 3 buried after 1 seconds
worker 4 buried after 1 seconds
worker 5 buried after 1 seconds
goodbye to uWSGI.
VACUUM: unix socket main.sock removed.
*** Starting uWSGI 2.0.18 (64bit) on [Thu Apr  9 17:41:27 2020] ***
compiled with version: 7.5.0 on 09 April 2020 15:04:16
os: Linux-4.15.0-66-generic #75-Ubuntu SMP Tue Oct 1 05:24:09 UTC 2019
nodename: InfantTestServer
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/fmagarelli/Infant_Competition_Platform
detected binary path: /home/fmagarelli/Infant_Competition_Platform/venv3/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
your processes number limit is 3842
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address main.sock fd 3
Python version: 3.6.9 (default, Nov  7 2019, 10:44:02)  [GCC 8.3.0]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x55c9e3a74470
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 437520 bytes (427 KB) for 5 cores
*** Operational MODE: preforking ***
> /home/fmagarelli/Infant_Competition_Platform/services/myFirebase.py(13)<module>()
-> import random
(Pdb) 
Traceback (most recent call last):
  File "./wsgi.py", line 1, in <module>
    from main import app
  File "./main.py", line 21, in <module>
    import myFirebase
  File "services/myFirebase.py", line 13, in <module>
    import random
  File "services/myFirebase.py", line 13, in <module>
    import random
  File "/usr/lib/python3.6/bdb.py", line 51, in trace_dispatch
    return self.dispatch_line(frame)
  File "/usr/lib/python3.6/bdb.py", line 70, in dispatch_line
    if self.quitting: raise BdbQuit
bdb.BdbQuit
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 893)
spawned uWSGI worker 1 (pid: 1040, cores: 1)
spawned uWSGI worker 2 (pid: 1041, cores: 1)
spawned uWSGI worker 3 (pid: 1042, cores: 1)
spawned uWSGI worker 4 (pid: 1043, cores: 1)
spawned uWSGI worker 5 (pid: 1044, cores: 1)
--- no python application found, check your startup logs for errors ---
[pid: 1040|app: -1|req: -1/1] 46.7.82.176 () {42 vars in 793 bytes} [Thu Apr  9 17:41:34 2020] GET /main.html => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (1 switches on core 0)

I solved, apparently it was such a common issue that they made a pull request in the pypandoc repo:我解决了,显然这是一个常见的问题,以至于他们在 pypandoc repo 中提出了拉取请求:

https://github.com/bebraw/pypandoc/issues/72#issuecomment-219283647 https://github.com/bebraw/pypandoc/issues/72#issuecomment-219283647

https://github.com/bebraw/pypandoc/pull/99/commits/5be3973b2a2c7eeb1abd6521c13374d82aa5ba99 https://github.com/bebraw/pypandoc/pull/99/commits/5be3973b2a2c7eeb1abd6521c13374d82aa5ba99

so after activating the virtual environment, run which pandoc to get the path to Pandoc:所以激活虚拟环境后,运行which pandoc来获取 Pandoc 的路径:

#activate env:
source myenv/bin/activate
which pandoc
OUT: '/usr/bin/pandoc'

Then add this to the flask app:然后将此添加到 flask 应用程序中:

os.environ.setdefault('PYPANDOC_PANDOC','/usr/bin/pandoc')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM