Forums

Not sure if I've uploaded files correctly but I can't run my app

So I'm new to PythonAnywhere but I've got some coding experience with python, html, css etc. I designed my website using Python and I uploaded it to here but I can't get it to run. Here's what I've done since starting:

  1. I uploaded my project files from VS Code.
  2. I uploaded my virtual env files to my virtual env on Python Anywhere. Picture below shows my file structure. Screenshot of file structure

  3. I then uploaded my virtual env packages from VS Code into my virtual env folder. I basically mirrored my VS Code setup.

  4. I then completed the dashboard page file paths as well as I could understand them.
  5. I then tried to run the app and got an "error, something went wrong"

The error I'm getting from the log is:

2025-05-06 13:23:33,928: Error running WSGI application
2025-05-06 13:23:33,939: ModuleNotFoundError: No module named 'flask'
2025-05-06 13:23:33,939:   File "/var/www/way2go_pythonanywhere_com_wsgi.py", line 16, in <module>
2025-05-06 13:23:33,939:     from myproject import app # noqa
2025-05-06 13:23:33,939:     ^^^^^^^^^^^^^^^^^^^^^^^^^
2025-05-06 13:23:33,939: 
2025-05-06 13:23:33,940:   File "/home/way2go/myproject/__init__.py", line 2, in <module>
2025-05-06 13:23:33,940:     from flask import Flask
2025-05-06 13:23:33,940: ***************************************************
2025-05-06 13:23:33,940: If you're seeing an import error and don't know why,
2025-05-06 13:23:33,941: we have a dedicated help page to help you debug: 
2025-05-06 13:23:33,941: https://help.pythonanywhere.com/pages/DebuggingImportError/
2025-05-06 13:23:33,941: ***************************************************

My WSGI file is as follows:

# This file contains the WSGI configuration required to serve up your
# web application at http://<your-username>.pythonanywhere.com/
# It works by setting the variable 'application' to a WSGI handler of some
# description.
#
# The below has been auto-generated for your Flask project

import sys

# add your project directory to the sys.path
project_home = '/home/way2go/myproject'
if project_home not in sys.path:
    sys.path = [project_home] + sys.path

# import flask app but need to call it "application" for WSGI to work
from myproject import app # noqa

application = create_app()

I've scoured the forums to try and find something similar so I could try to fix it myself, but I'm not at the point where I'm not clever enough to understand quite what the error log is telling me to fix.

I am convinced it's either because I've not uploaded my files correctly and therefore something is wrong with the file structure and path pointing. Or I think it's due to my file code not calling for the correct packages from the correct places (sort of similar to the first point). Or there is something wrong with my virtual env setup.

Help would be gratefully received. :)

You cannot upload your virtualenv files to PythonAnywhere. Virtualenvs are generally not portable between machines. You need to create and populate the virtualenv on PythonAnywhere. You also need to ensure that you have configured your web app to use the virtualenv once you have created it and installed the packages into it.

Thanks Glenn, I wondered if it might be something like that. So can i install the packages via the requirements.txt using the bash console?

@way2go: See this help page.

@way2go @dev2karateolymp exactly

@dev2karateolmp @glenn - Thank you for the help. I think my virtual environment is setup and I've installed packages from my requirements file. I'm now getting this error in the console:

Traceback (most recent call last):
  File "/home/way2go/app.py", line 2, in <module>
    from myproject import app, db, login_manager
  File "/home/way2go/myproject/__init__.py", line 3, in <module>
    from flask_sqlalchemy import SQLAlchemy
ModuleNotFoundError: No module named 'flask_sqlalchemy'

This makes me think I might not be installing the pacakges into the right location?

So I uploaded my requirements.txt into my virtual environment folder, opened the bash and installed into the same folder. But it seems not to be able to find the packages.

Interestingly, when I installed 'flask' directly through bash, that "cannot find flask" error has now gone. This feels like it confirms that it's not installing into the correct location yes?

Were you activating the virtualenv environment (with something like workon name-of-virtualenv) before you ran those pip install commands?

@giles - I thought the virtual env was automatically activated when trying to run the app. So you're saying I need to run the virtual env first, then install packages using pip, then run my app?

I'll try that anyway and see. Thank you.

@giles - in my bash console, it already says (myvirtualenv) $. So is that different to activating the virtual environment?

No, that means that that virtualenv is active.

Ok so I feel like I'm making no progress. Over a week on this and I'm no further forward! Desperately hoping someone can help me see the light at the end of the tunnel before I jack sack the whole thing off. :(

I have tried installing my project packages into my virtual env. Everytime I try to install it into my virtual env it throws a message saying

"15:05 ~/.virtualenvs/myvirtualenv $ pip install -r requirements.txt
Defaulting to user installation because normal site-packages is not writeable

Then when I go and look, there are no packages in my virtual env and only about 4-5 in the "/usr/local/lib/python3.13/site-packages". I have no idea why this keeps doing it. I've tried saving the requirements file to different locations to see if it makes a difference but no, always the same response.

Then I noticed that the python version for "user" is 3.13 but i'm sure I set my project as 3.12. It seems as if my virtual env and the user location have two different python installations.

I just don't know what I'm supposed to do next. I've tried deleting and reinstalling. I've tried manually installing packages. Nothing I do will get my app to load on my domain.

Any last thoughts before I try another platform?

Can we take a look at your files? We can see them from our admin interface, but we always ask for permission first.

OMG!!! I fixed it. That was sooooo much more painful than it should have been!

So there is an awesome tutorial here:

How to set up your files on Pythonanywhere

If I'd have watched this first I'd have saved days of wasted time.


THE FIX - These are the steps I took to fix it:

  1. So in the end, I deleted all my files and the app to get me back to a clean install.
  2. Then I setup a new app on pythonanywhere and just looked at what it installed.
  3. I noticed the "Hello World" app.py file in "mysite" folder. I left the folder as it was and then ran the app.py file and it worked.
  4. So I thought to myself, "if that worked then what if I just load my files in the exact same way as a clean install.
  5. So then I uploaded my files to the correct directories so that app.py was where it should be. I then ran the file and it worked. Just like that.
  6. I then tested the web link and saw my website loaded.

Finally!

Now onto the next challenge of trying to recreate/setup my website database!!

Glad to hear, you're moving forward!