0

I have python 3.7 installed with mod_Wsgi and Apache2.4. A simple website works on the server but when I try to import my own python modules or other modules like numpy the server just hangs and never fully loads.

I tried looking at windows event logger and logs in my apache file but there was nothing there that said there was any problems. I also tried sys.path.append(path) before each library but that didn't work.

This is an example code that I'm using to test why the server doesn't work when I import other libraries. I already did "pip install numpy"

web.wsgi file:
import numpy as np
import sys
sys.path.append('C:/myapp/app/')
from app import app as application

app.py
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
      a = np.arrange(12).reshape(2,2,3)
      return "f"

if __name=="__main__"
     app.run()
  • Does [this post](https://stackoverflow.com/questions/31815716/why-cant-apache-see-my-python-module) help? – d_kennetz Aug 07 '19 at 19:18
  • On his, he has an ImportError: No Module, but on my apache logs, it doesn't show any errors unless its my own python files that I created – Knickfan07 Aug 07 '19 at 19:37
  • I came across something similar to this. Could you change the log level to info and post it. Are you getting any segmentation fault in apache log? – P K Aug 08 '19 at 12:24
  • Does this answer your question? [Flask hangs after importing pandas (also numpy, matplotlib etc.)](https://stackoverflow.com/questions/41099433/flask-hangs-after-importing-pandas-also-numpy-matplotlib-etc) – CDJB Dec 19 '19 at 16:23

1 Answers1

1

I am not much familiar with the environment you have, however, I suggest you check the location of the "site_packages" and make sure that the pip is installing in the same path of the "site_packages" that you are mainly using to install your packages. Also, you may consider creating a Python virtual environment in which you install all your packages in and ensure that it is activated while executing your code.

Noha Elprince
  • 1,924
  • 1
  • 16
  • 10
  • Hi, if i have most of the code written for the actual site. Do i just make a new folder and pip install virtualenv? Sorry I'm still new to python. Thanks! – Knickfan07 Aug 07 '19 at 19:31
  • Hi, I have a MAC and to create a virtual env: I open a new shell terminal and navigate to the parent folder of my project then issue the command $ python3 -m venv my_env then activate the venv named "my_env" by $ source my_env/bin/activate. Next, I check that the Python interpreter is pointing to the new venv by $which python3 . If all good, then I start installing the desired package using pip and all confident that they will be stored in the appropriate folder. You may look up the equivalent commands in windows but the logic is the same. – Noha Elprince Aug 08 '19 at 20:31