Python external on Azure ImportError No Module Found

爱⌒轻易说出口 提交于 2019-12-11 16:33:12

问题


If i locally run my code with python main.py, then this error occurs locally. If i run it with python3 main.py, it works as expected. I suspect my azure app service is not running the correct version of python, however, it is set to python 3.4

    StdErr: 
2018-06-30 19:47:13.785205: Unhandled exception in wfastcgi.py: Traceback (most recent call last):
  File "D:\Python34\Scripts\wfastcgi.py", line 711, in main
    env, handler = read_wsgi_handler(response.physical_path)
  File "D:\Python34\Scripts\wfastcgi.py", line 568, in read_wsgi_handler
    return env, get_wsgi_handler(handler_name)
  File "D:\Python34\Scripts\wfastcgi.py", line 541, in get_wsgi_handler
    handler = handler()
  File ".\ptvs_virtualenv_proxy.py", line 120, in get_venv_handler
    handler = get_wsgi_handler(os.getenv('WSGI_ALT_VIRTUALENV_HANDLER'))
  File ".\ptvs_virtualenv_proxy.py", line 89, in get_wsgi_handler
    raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb))
ValueError: "main.app" could not be imported: Traceback (most recent call last):
  File ".\ptvs_virtualenv_proxy.py", line 73, in get_wsgi_handler
    handler = __import__(module_name, fromlist=[name_list[0][0]])
  File "D:\home\site\wwwroot\main.py", line 2, in <module>
    from newspaper import Article
ImportError: No module named 'newspaper'

UPDATE

So I went to the debug console in kudo and i ran python -m pip install --upgrade -r d:\home\site\wwwroot\requirements.txt.

Here is the error

 ERROR: b"'xslt-config' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n" ** make sure the development packages of libxml2 and libxslt are installed ** Using build configuration of libxslt

One of the requirements is Pillow which requires libxml2 and libxslt. I've tried using wheels however, I've had no success.

UPDATE II I tried to install virtualenv since it does not exist and I receive a permissions error.

UPDATE III I ran this command

D:\home\python364x64>python -m pip install newspaper3k

I test everything locally, and it works perfect. I push and receive this error below.

Error occurred while reading WSGI handler:

Traceback (most recent call last):
  File "D:\home\python364x64\wfastcgi.py", line 791, in main
    env, handler = read_wsgi_handler(response.physical_path)
  File "D:\home\python364x64\wfastcgi.py", line 633, in read_wsgi_handler
    handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
  File "D:\home\python364x64\wfastcgi.py", line 600, in get_wsgi_handler
    handler = __import__(module_name, fromlist=[name_list[0][0]])
  File ".\app.py", line 8, in <module>
    from newspaper import Article
  File "D:\home\python364x64\lib\site-packages\newspaper\__init__.py", line 10, in <module>
    from .api import (build, build_article, fulltext, hot, languages,
  File "D:\home\python364x64\lib\site-packages\newspaper\api.py", line 12, in <module>
    import feedparser
  File "D:\home\python364x64\lib\site-packages\feedparser.py", line 316
    raise KeyError, "object doesn't have key 'category'"
                  ^
SyntaxError: invalid syntax


StdOut: 

StdErr: 

回答1:


Per my experience, we have no permission to modify D:\home environment.

So , It's better to use python extension. Please follow the steps in this case: Azure Flask Routes Not found and use command python -m pip install newspaper to install additional packages in python extension.

Please make sure the package you want to install must match with version of python extension. Otherwise, it will throw error as follows.

Hope it helps you.



来源:https://stackoverflow.com/questions/51118110/python-external-on-azure-importerror-no-module-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!