My files are placed as below in the apache shared hosting server –
/public_html/cgi-bin --- myenv (directory - virtual env) --- hello.cgi --- myapp.py
.htaccess is in the root directory.
Now when I activate the virtual environment and run the
myapp.py file –
this works fine. I get this –
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
But now when I try to launch my page in the web browser, I get the below Import error in the logs (on the web page its 500 – Internal Server Error) –
'No module named flask'
Please suggest if I need to give the path of the flask package anywhere in the
.cgi or the
flask is installed in the
#!/usr/bin/env python import sys from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello Ejaz" if __name__ == "__main__": app.run()
#!/usr/bin/env python import os from wsgiref.handlers import CGIHandler from myapp import app os.environ['SERVER_NAME'] = "www.mypage.com" os.environ['SERVER_PORT'] = "" os.environ['REQUEST_METHOD'] = 'GET' os.environ['PATH_INFO'] = "" CGIHandler().run(app)
hello.cgi to this-
#!/usr/bin/env python import os from wsgiref.handlers import CGIHandler from myapp import app CGIHandler().run(app)
and added these lines in
import os import sys sys.path.insert(0, '/home/username/public_html/cgi-bin/myenv/lib/python2.6/site-packages')
It works fine.
Answered By – Ejaz
Answer Checked By – Katrina (Easybugfix Volunteer)