tjcsl / director

Director (web3)
https://director.tjhsst.edu
MIT License
11 stars 5 forks source link

Python 3.5 not reading modules installed with pip3 #48

Closed liamrathke closed 6 years ago

liamrathke commented 6 years ago

I want to run a Python 3 app that I currently have running locally through Director, but, for some reason, it isn't reading the modules I have installed.

I'm using this in my run.sh:

#!/bin/sh
python3.5 main.py

I've installed all the modules through pip3, which lists these:

Package             Version
------------------- ----------------------
acme                0.22.2
appnope             0.1.0
asn1crypto          0.22.0
beautifulsoup4      4.6.0
bs4                 0.0.1
certbot             0.22.2
certbot-nginx       0.22.0
certifi             2017.7.27.1
chardet             3.0.4
click               6.7
command-not-found   0.3
ConfigArgParse      0.11.0
configobj           5.0.6
cryptography        1.9
decorator           4.1.2
Django              1.11.7
django-extensions   1.9.7
djangorestframework 3.7.3
enum-compat         0.0.2
eventlet            0.21.0
fcm-django          0.2.11
Flask               0.12.2
Flask-Login         0.4.0
Flask-SocketIO      2.9.2
funcsigs            0.4
future              0.15.2
gevent              1.2.2
greenlet            0.4.12
gunicorn            19.7.1
httplib2            0.10.3
idna                2.5
ipython             6.2.1
ipython-genutils    0.2.0
itsdangerous        0.24
jedi                0.11.0

and so on, with all the dependencies that I have installed locally.

However, Director gives a FATAL Exited too quickly error when running the main.py file that requires some dependencies (which should be installed via pip3):

Traceback (most recent call last):
  File "main.py", line 5, in <module>
    import eventlet
ImportError: No module named 'eventlet'

Am I doing anything wrong or is there a workaround for Director?

ezwang commented 6 years ago

You want to use a python virtual environment. You can do so using the following commands.

virtualenv --python=python3 venv
source venv/bin/activate
pip install <all your packages>

In your run.sh, you want to put something like:

#!/bin/sh
venv/bin/python main.py

The reason for this is because the user the web server is running under is not the same as your user account. This is done for security reasons, to ensure that if your app is ever compromised nothing else on your account is affected.

liamrathke commented 6 years ago

OK, thanks for the help, I'll try that and report back.

liamrathke commented 6 years ago

@ezwang thanks for the help, I set up a virtualenv in Python 3.5 but I'm still getting the same issue. All the dependencies are installed and check out, but it can't find the first module I try and import. Maybe it's something with my file structure? I have it set up like this right now:

screen shot 2018-06-05 at 11 53 45 am

I also followed [https://director.tjhsst.edu/docs/dynamic-sites-on-director/](these instructions) and changed my run.sh file to match:

#!/bin/bash

source venv/bin/activate
gunicorn server:app -b 127.0.0.1:$PORT -w=4

Is this structure correct?

ezwang commented 6 years ago

By default the script is run in the public folder. You can either move your venv folder to the public folder, or use source ../venv/bin/activate instead of source venv/bin/activate.

Hope that helps!

liamrathke commented 6 years ago

Thanks again for the suggestions, @ezwang. Unfortunately, that was not able to fix the problem. I tried both ways, and I'm getting the same error. For now, I've moved venv to public/venv.

For some reason, Gunicorn can't import Eventlet, a module I'm using, so it keeps shutting down and restarting again. I can run the server fine via the Online Terminal, but it doesn't run when I use run.sh (with Gunicorn, as per the documentation). When I remove the Gunicorn line and just run python3 server.py in the virtual env, nothing is printed to the speedia.log file (although I can still print to files).

Is there a way to just run everything without Gunicorn? I'm already using Flask and Eventlet, and I don't really understand why Gunicorn specifically is helpful in this instance.

Also, I must have somehow messed up somewhere else, since I'm also not able to make a domain.

screen shot 2018-06-06 at 1 21 48 pm

Is there another domain I'm supposed to be using instead?

ezwang commented 6 years ago

You should be able to run the server without gunicorn, just listen on the port specified by the PORT environment variable. In python, you can access this through os.environ["PORT"].

If you want to use a custom domain that does not end with .tjhsst.edu, you need to obtain one from somewhere like NameCheap and point it in the right place.

I've updated the domain to the correct value, you should be able to access it at speedia.sites.tjhsst.edu.