How to use PythonAnywhere 3


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.

Setting up an account

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.

Using the console to navigate the server

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:

mkdir myproject

Now do:

ls

That will output:

README.txt myproject

Those are the files and folders in your current directory. Let’s now change our current directory to myproject:

cd myproject

And you can check to see where you are:

pwd

So, we’re inside myproject which is an empty folder. Let’s create a Python file there:

nano myscript.py

That will open the nano text editor where you can write your Python code. Type something such as print("Hello") and then press Control + X to exit, y to save and thenEnter.  Try ls again and you will see your new file is there. You can now run your Python program with:

python3 myscript.py

You should now see your program output in the terminal.

If you want to run a Python shell, you can execute:

python3

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

And uninstall:

pip3 uninstall pandas

In PythonAnywhere you can also schedule a Python script for execution at a particular time every day. For that please see the article 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.


Leave a comment

Your email address will not be published. Required fields are marked *

3 thoughts on “How to use PythonAnywhere