HOW TO RUN, DEPLOY & EXECUTE PYTHON SCRIPTS ON PYTHONANYWHERE (FREE PLAN)
We’ll go step-by-step from signing up to running your code live — no experience required.
🔧 PART 1: SIGN UP FOR PYTHONANYWHERE (FREE ACCOUNT)
-
Open your browser (e.g., Chrome or Firefox).
-
In the address bar at the top, type:
https://www.pythonanywhere.com
Then press [Enter]. -
On the homepage, click the big blue button labeled "Create a Beginner Account".
-
On the sign-up form:
-
Click the Username box → Type your desired username (e.g.,
myfirstscript
) -
Click the Email address box → Type your email
-
Click the Password box → Type your new password (twice)
-
Click the checkbox “I agree…”
-
-
Click the green button “Register”
-
If you see a CAPTCHA, follow the instructions to complete it.
💡 PART 2: ACCESS YOUR DASHBOARD
After signing up:
-
You’ll land on your Dashboard.
If not, in the top-right corner:
-
Click Log in
-
Type your username and password
-
Click the Log in button
-
-
Your Dashboard has 5 tabs:
-
Dashboard
-
Files
-
Consoles
-
Web
-
Tasks
-
We'll use Files to upload code, and Consoles to run it.
📁 PART 3: UPLOAD YOUR PYTHON SCRIPT
You’ll now upload your .py
file (e.g., myscript.py
).
-
At the top, click the Files tab.
-
On the new screen, scroll down until you see a button labeled “Upload a file”.
-
Click that button.
-
A popup will appear.
-
Click the Choose File or Browse… button.
-
Your computer’s file manager will open.
-
-
Navigate to the folder where your
.py
file is saved. -
Click the file once to select it.
-
Click Open.
-
Back on PythonAnywhere, click Upload to upload the file.
✅ You should now see your script listed under your files (e.g., myscript.py
).
💻 PART 4: RUN YOUR PYTHON SCRIPT IN A CONSOLE
-
At the top, click the Consoles tab.
-
On this screen, click the button labeled "Start a new console".
-
Click Python 3.x (choose the latest version — e.g., Python 3.10).
-
A terminal (black screen) will appear with a flashing cursor.
-
Type this command exactly (replace
myscript.py
with your filename):python3 myscript.py
-
Press [Enter].
✅ Your script will now run. You’ll see the output printed below the command.
🌐 PART 5: MAKE IT A WEB APP (OPTIONAL — FOR WEB-BASED SCRIPTS)
If your script uses Flask
, Django
, or similar to serve a web app:
-
Click the Web tab at the top.
-
Then click the big green button: "Add a new web app".
-
On the first screen:
-
Click Next
-
-
On the Framework screen:
-
Choose Flask if you're using Flask
-
Or choose Manual configuration if unsure
-
-
Pick the latest Python version (e.g., Python 3.10)
-
Click Next
-
Once done, you'll land on a page where you can:
-
Edit the WSGI file
-
Set your script path
-
If you’re using Flask, update the WSGI file like this:
-
Click the WSGI file link (ends with
.py
). -
Delete everything and replace with:
import sys path = '/home/yourusername' if path not in sys.path: sys.path.append(path) from myscript import app as application
⚠️ Replace
yourusername
with your PythonAnywhere username.
⚠️ Replacemyscript
with your Python file name (without.py
).
⚠️ Ensure your script ends with something like:app = Flask(__name__)
-
Click the blue Save button at the top-right.
-
Go back to the Web tab and click the Reload button.
✅ Your web app will now be live at:
https://yourusername.pythonanywhere.com
🧯 PART 6: COMMON ERRORS TO AVOID
-
⚠️ File not found? Double-check you uploaded your
.py
file into your home directory. -
⚠️ Permission denied? You’re likely trying to use a restricted folder — only use
/home/yourusername/
. -
⚠️ App crashes? Check the Web tab → Scroll down to Error log for the cause.
-
⚠️ Reload doesn’t update? Try clearing your browser cache or using [Ctrl] + [Shift] + [R].
🧰 TROUBLESHOOTING FALLBACKS
If your script doesn't run in console:
-
Try running with:
python myscript.py
or
python3.10 myscript.py
If the script requires packages like requests
, install them with:
pip3 install --user requests
If your web app won’t load:
-
Go to the Web tab → Click View Error Log and Server Log for exact issues.
Comments
Post a Comment