本文介绍了在带有numpy,pandas等的python 3.7+中的wfastcgi上在IIS上部署Python Flask应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用wfastcgi在IIS上部署python 3.7+烧瓶或Dash应用程序时,有很多很棒的教程来使Hello工作程序正常工作,例如

然后我点击添加"以添加用户并弹出以下窗口

在对象类型"下,我选择了所有选项,在位置"中选择了顶层位置.

在对象名称下,我编写了iis apppool< yoursitename>.例如,对于一个名为app的IIS站点,它将是iis apppool \ app

然后我单击检查名称以确保可以找到该应用程序,然后继续单击确定"并应用.

添加权限后,IIS站点可以访问所有必需的dll等,并且应用程序正常运行

When deploying a python 3.7+ flask or Dash application on IIS using wfastcgi, there are many great tutorials to get a hello work program working such as

https://medium.com/@bilalbayasut/deploying-python-web-app-flask-in-windows-server-iis-using-fastcgi-6c1873ae0ad8

Where this process fell apart for me and seeming for other users such as

Can't get dash app run on IIS with flask server

How to deploy python flask application in conda base environment on IIS server?

was when other packages started coming into the mix such as Numpy, Pandas, Dash, Plotly Express, etc.

The error that get throw tended to depend on the package but usually resembled a large block of test that looks like the error bellow starting with Error occurred while reading WSGI handler and featuring things like Dll load failures or missing components.

Error occurred while reading WSGI handler: Traceback (most recent call last): File "C:\ProgramData\Anaconda3\envs\dash_search_app\lib\site-packages\wfastcgi.py", line 791, in main env,
handler = read_wsgi_handler(response.physical_path) File "C:\ProgramData\Anaconda3\envs\dash_search_app\lib\site-packages\wfastcgi.py", line 633,
in read_wsgi_handler handler = get_wsgi_handler(os.getenv("WSGI_HANDLER")) File "C:\ProgramData\Anaconda3\envs\dash_search_app\lib\site-packages\wfastcgi.py", line 616,
in get_wsgi_handler raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb)) ValueError: "dashapp.server" could not be imported: Traceback
(most recent call last): File "C:\ProgramData\Anaconda3\envs\dash_search_app\lib\site-packages\wfastcgi.py", line 600,
in get_wsgi_handler handler = __import__(module_name, fromlist=[name_list[0][0]]) File ".\dashapp.py", line 3, in from flaskapp import app File ".\flaskapp\__init__.py",
line 67, in register_dashapps(app) File ".\flaskapp\__init__.py", line 19, in register_dashapps from flaskapp.dashapp_searchtool.layout import layout File ".\flaskapp\dashapp_searchtool\layout.py", line 30,
 in import pandas as pd File "C:\ProgramData\Anaconda3\envs\dash_search_app\lib\site-packages\pandas\__init__.py", line 17, in "Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
 ImportError: Unable to import required dependencies: numpy: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the numpy c-extensions failed. -
 Try uninstalling and reinstalling numpy. - If you have already done that, then: 1. Check that you expected to use Python3.7 from "C:\ProgramData\Anaconda3\envs\dash_search_app\python.exe",
 and that you have no directories in your PATH or PYTHONPATH that can interfere with the Python and numpy version "1.17.3" you're trying to use. 2. If (1) looks fine,
 you can open a new issue at https://github.com/numpy/numpy/issues. Please include details on: - how you installed Python
 - how you installed numpy - your operating system - whether or not you have multiple versions of Python installed - if you built from source, your compiler versions and
 ideally a build log - If you're working with a numpy git repository, try `git clean -xdf` (removes all files not under version control) and rebuild numpy. Note:
 this error has many possible causes, so please don't comment on an existing issue about this - open a new one instead. Original error was: DLL load failed:
 The specified module could not be found. StdOut: StdErr: C:\ProgramData\Anaconda3\envs\dash_search_app\lib\site-packages\flask_sqlalchemy\__init__.py:794:
 FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.

The most common advice is to downgrade to python 3.6, however this is not possible for every project.

I've answered bellow my solution in case others may have the same issue as my hours of googling did not result in me finding a solution.

解决方案

For me, this came down to a permissions issue. My first speculation was that the environment was not registering correctly, however in fact it was that IIS did not have permission to access all the dependencies of the environment.

How I resolved this was to navigate to my Anaconda3 folder, right click and select properties. In the properties window, I navigated to the security tab and clicked Edit

I then clicked 'Add' to add users and bring up the following window

Under Object Type, I selected all the options, and Locations I selected the top level location.

Under Object names I wrote iis apppool<yoursitename>for example, for an IIS site named app, it would be iis apppool\app

I then clicked check names to ensure the app could be found, and then proceeded to click ok and apply.

Once the permissions were added, the IIS site could access all the required dlls and such and the app functioned correctly

这篇关于在带有numpy,pandas等的python 3.7+中的wfastcgi上在IIS上部署Python Flask应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:00