Flask не может найти Pando c на Linux сервере (nginx + uwsgi) - PullRequest
1 голос
/ 09 апреля 2020

Здравствуйте, только что развернуло мое Flask приложение на моем удаленном сервере Ubuntu в Digital Ocean, следуя этому руководству: https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uswgi-and-nginx-on-ubuntu-18-04

Все работает нормально, за исключением того, что когда я импортирую pyPandoc он не может найти pandoc. Мой код для импорта pypando c таков:

import pypandoc

try:
    from pypandoc.pandoc_download import download_pandoc
except:
    pass

, и это нормально работает на моем локальном компьютере, но я получаю сообщение об ошибке на сервере:

[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.

Я попытался установить Pandoc через pip, apt и даже загрузку файла Debian в соответствии с рекомендациями официального Pando c do c. Ничто не похоже на работу. на сайте pyPando c: https://pypi.org/project/pypandoc/

что-то говорит об использовании колеса для установки Pando c, но я не уверен, что понял, что это значит, и я не знакомы с процедурой. Есть ли у вас какие-либо идеи о том, как заставить pyPando c работать с моим развернутым Flask приложением?

ДОПОЛНИТЕЛЬНАЯ ИНФОРМАЦИЯ:

мое flask приложение работает в виртуальной среде, как учебник, связанный выше. Я попытался получить доступ к Pando c из виртуальной среды, и это мой вывод:

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 с добавлением PDB:

Поэтому измените мой импорт на:

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

и вот мой вывод:

[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)

1 Ответ

0 голосов
/ 09 апреля 2020

Я решил, по-видимому, это была такая распространенная проблема, что они сделали запрос на удаление в pypando c репо:

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

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

поэтому после активации виртуальной среды запустите which pandoc, чтобы получить путь к Pando c:

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

Затем добавьте это приложение flask:

os.environ.setdefault('PYPANDOC_PANDOC','/usr/bin/pandoc')
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...