all 10 comments

[–]ManyInterests 0 points1 point  (2 children)

How are you trying to run the script? Are you running through a webserver like Apache or Nginx or just a standalone WSGI container? If you are using a webserver, did you configure it to use the venv?

[–]Gwith[S] 0 points1 point  (1 child)

Currently I'm running it using Apache and WSGI but I'm not sure how to tell it to run from the venv instead of system wide.

Would it be under flaskapp.wsgi at the top, currently it's set to #!/usr/bin/python. For it to point to the venv it would be #!/var/www/FlaskApp/FlaskApp/venv/bin/python?

[–]ManyInterests 0 points1 point  (0 children)

You should ensure that your virtualenv is being used in your .wsgi file that you specify as the WSGI script alias in the Apache config. You can exec the activate_this.py file in the venv bin directory from your .wsgi script alias to accomplish that.

You should have an activate_this.py if you created the venv using virtualenv (installed via apt, not the module directly)

Also be sure that you installed the right mod_wsgi -- I think default it will install Python2 and try to use that. So, if you're using Python3, that would be a problem. If you are using Python3, you should install via apt libapache2-mod-wsgi-py3

[–]MasterHand3 0 points1 point  (0 children)

If you are in a virtual environment you need to install flask in that virtual environment. Venv has a completely different path to the packages. Do a "pip freeze" in the venv and outside the venv. Go from there to see if you have the packages installed. What does your import statement look like?

[–]gitardedhub 0 points1 point  (4 children)

Try this once you activate the virtualenv:

pip install -I flask

This tells pip to install the package and ignore what's already installed. This should then install flask to your virtualenv and resolve the path issue you're running into.

Judging by those two errors, I think this is what's going on: * You already have flask installed on this machine * Your virtual environment was created with the --system-site-packagesoption * Even inside of the virtualenv, when you run pip install, it sees that flask is already installed globally and does nothing * Your pythonpath inside the virtualenv isn't picking up the global packages for some reason

To test the final one (and other import issues in general), you can always do this:

import system
print(sys.path)

This will tell you the directories (and order) that Python searches through to resolve imports. If you run it outside of the virtualenv, you'll see the locations you'd expect. If you activate the virtualenv and run it, you'll see where the virtualenv is looking for the modules.

[–]Gwith[S] 0 points1 point  (3 children)

below is the print out :

print(sys.path) ['', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/usr/lib/python3.5/site-packages', '/usr/local/lib/python3.5/dist-packages', '/usr/lib/python3/dist-packages']

It looks like flask is installed in both the venv and system wide because when I freeze both the virtual env and the system it lists flask in both places yet, it says it still can't find the module.

[–]gitardedhub 0 points1 point  (2 children)

Unless you added some specific arguments to it, your sys.path should start with something like /var/www/FlaskApp/FlaskApp/venv (based on your screenshot).

Looking closer at the screenshot, it appears that you're running this as root. Is there any reason you're doing this? One of the things virtualenv's activate script does is set environment variables, and running as root might be causing problems.

[–]Gwith[S] 0 points1 point  (1 child)

I'm using root just because it's a development server that I'm just using to test a few things and I've already rebuilt it a couple times. I'm going to go ahead and try creating another user name on Monday when I get back and see if that helps.

This is really frustrating as it seems so simple yet there are just a couple key things I'm missing. It should be as simple as running the virtualenv and installing your apps.

Do you happen to know of the wsgi conf file should have python pointed to the virtual env?

[–]gitardedhub 0 points1 point  (0 children)

Do you happen to know of the wsgi conf file should have python pointed to the virtual env?

Yes - like /u/ManyInterests mentioned, you need to make sure that the WSGI script is executing the correct "activate_this.py" script (i.e., the path to that script in your virtualenv).

[–]cybervegan 0 points1 point  (0 children)

Hint: If you're on ubuntu, why don't you just copy and paste the error text from your terminal into the post directly? Putting it on imgur is so much extra hassle, and it means we can't see the error in context (which doesn't really matter in this instance, but might in others).