mod_wsgi
mod_wsgi copied to clipboard
Unable to import connexion of flask on windows
Hi @GrahamDumpleton using flask wrapper connexion inside code, plain flask working properly but for connexion getting errir
wsgi file import sys sys.path.insert(0, 'C:\server') from openapi_server import app as application
.conf file <VirtualHost *:8068> ServerName localhost
WSGIScriptAlias / "C:\\server\\wsgi_script\\newapp.wsgi"
<Directory C:\server>
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
folder structure server ->openapi_server(inside server) ->init.py(inside openapi_server) ->controller(inside openapi_server) ->model (inside openapi_server) ->openapi(inside openapi_server)
You need to set WSGIPythonPath directive in Apache configuration to where your project code is located else the embedded Python doesn't know where to find it.
@GrahamDumpleton tried adding WSGIPythonPath but not resolve to get the same error.
so basically, the simple flask is running without specifying WSGIPythonPath but when I want to import another lib getting an error not found & logged in apache error.log could you please possibly give me the exact steps, as I searched on the net not haven't got anything.
error in
ModuleNotFoundError: No module named 'connexion'
the last question, does mod_wsgi + python for production deployment is it good combination on windows?
If you are using a Python virtual environment where your Python packages are installed, you must set WSGIPythonHome to indicate where the Python virtual environment is located.
BTW, do not use backslashes in strings of Python code files for paths. You should use forward slashes. Backslashes causes certain characters to be interpreted as special characters and not the character you think. In other words, the backslashes get ignored for purposes of file paths and special characters is used in string.
Use of forward slashes is also recommended in the Apache configuration file.
For production systems for web applications I would recommend you use Linux instead of Windows, unless your code is specifically dependent on Windows features for some reason.
@GrahamDumpleton Thanks i am able to set up code could you please tell me, on windows mod_wsgi does support multiprocess or multithread or both. If anyone of those supports how to specify on windows env?
Thanks in advance..
Python virtual environments are the generally recommended approach, especially for production systems, so you can have isolation from the system Python site packages directory. You don't have to use one, I only mentioned them since the package wasn't being found and so you may have been using one but not told mod_wsgi where it was.
Windows only supports multithread, which is another reason Windows is a bad option. For more details see:
- https://modwsgi.readthedocs.io/en/master/user-guides/processes-and-threading.html
@GrahamDumpleton Thanks for you i/p and time. Another question can we explicitly mention no of thread in child process in windows? Thanks in advance!
That is an Apache level configuration parameter. See:
- https://httpd.apache.org/docs/2.4/mod/mpm_winnt.html
- https://httpd.apache.org/docs/2.4/mod/mpm_common.html#threadsperchild
Large numbers of threads are bad for Python web applications if there are CPU intensive, which is another reason why Windows is a bad platform to run Apache/mod_wsgi for a production system. That is, no option for multiple processes.
@GrahamDumpleton Thank you!!