Have you wanted to create, store, and run Python scripts from the cloud? Or even deploy your Python web apps to a live server? That’s all possible with PythonAnywhere which gives you access to a Linux server via the server terminal which you can access from your internet browser. This tutorial will show you how to setup PythonAnywhere, using its Linux terminal, and creating, uploading, and running Python scripts.
You can easily sign up for a free plan on PythonAnywhere. It gives you 500 MB of disk space. If in the future you will want more server resources you can upgrade to the paid plans.
Once you have signed up and logged in, go to the Consoles menu item and then click on Bash. That will open your server terminal which is the interface that lets you interact and use your server via Linux commands. There’s no graphical interface. The terminal lets you do everything like installing Python packages, creating, writing, editing and deleting files, knowing what directory you are, etc. For example, if you type pwd and press Enter you would get as output something like /home/ardit which is your current directory in the server.
Create a new directory:
That will output:
Those are the files and folders in your current directory. Let’s now change our current directory to myproject:
And you can check to see where you are:
So, we’re inside myproject which is an empty folder. Let’s create a Python file there:
That will open the nano text editor where you can write your Python code. Type something such as:
And then press Control + X to exit, y to save and then Enter.
Try ls again, and you will see your new file is there. You can now run your Python program with:
You should now see your program output in the terminal.
If you want to run a Python shell, you can execute:
And that will open the interactive Python shell just like it does on your local computer. Once you’re done with the shell run exit() to return to the terminal.
If you have some Python script or other files already in your computer, and you want to upload them to PythonAnywhere you can go back to the Dashboard and then go to Files. There you should be able to upload a file to your server.
And lastly, you can install Python packages with pip3:
pip3 install pandas --user
pip3 uninstall pandas
In PythonAnywhere you can also schedule a Python script for execution at a particular time every day. For that, please read the following pages on "How to schedule a Python task" and if you want to know how to deploy a Flask web app on PythonAnywhere see "Deploying a Flask app".Next Lecture
Learn Flask development and learn to build cool apps with our premium Python course on Udemy.