Article

Programming in Python on a Chromebook

This article will teach you how to run Python code on Chromebooks so you can do off-platform Python projects on your Chromebook.

Setting Up Your Python Coding Environment

If you were able to enable Linux on your computer, it should automatically come with Python 3 installed. If you haven’t set up your Linux environment yet, please read the Programming Locally on a Chromebook article before continuing.

Checking Your Python Installation

  1. Let’s see which version of Python 3 you have! We can do this by typing the command python3 -V into your terminal window. Make sure you type python3 -V and not python -V! Typing python will check the Python 2 version which does not come preinstalled.

    [email protected]:~$ python3 -V
  2. If this worked, it should display your Python 3 version.

    [email protected]:~$ python3 -V Python 3.7.3

    If it didn’t work (or if you typed in python instead of python3), you will see something like:

    [email protected]:~$ python3 -V -bash: python3: command not found

    To download a new Python version on your machine, continue to the “Installing a New Python Version” section. If you already have the version of Python you want installed on your machine, skip “Installing a New Python Version”.

Installing a New Python Version

If you’re doing a Python 3 off-platform project, you probably don’t need to look at this section! This section is helpful for learners who are trying to code in Python 2 or a specific version of Python 3.

In this example, we have Python 3.7.3, and we’ll be downloading Python 3.8.8. Python 3.8.8 is the Python 3.8 Stable Release according to Python.org.

  1. You can download the Python 3.8.8 source file by using the wget command in the terminal or from Python.org’s source page. We suggest using wget but will show both approaches.

    Using wget

    First, you’ll need to move into the /usr/src folder in your terminal. Then, when using the wget command, you would change the Python version to match the one you are trying to download:

    [email protected]:~$ cd /usr/src [email protected]:/usr/src$ sudo wget https://www.python.org/ftp/python/3.8.8/Python-3.8.8.tgz

    Using Python.org

    If you want to download the file from the Python.org website instead, you will navigate to Python.org’s source page. You will want to download from the Stable Release column and click the link to get the Gzipped source tarball type of file from the version you want. An image showing the current stable releases of Python from Python.org

    You will need to move the downloaded file from your “Downloads” folder to your “Linux Files”. Then, you will need to move the file to /usr/src/. You can do this with the mv command.

    [email protected]:~$ sudo mv https://www.python.org/ftp/python/3.8.8/Python-3.8.8.tgz /usr/src/
  2. You will now need to unzip the file and check if it worked! We will use the tar command to unzip it.

    [email protected]:/usr/src$ sudo tar xzf Python-3.8.8.tgz

    Now, we’ll check if it worked by checking the version! We will need to use python3.8 instead of python3 since we downloaded Python 3.8.8 in this example.

    [email protected]:~$ python3.8 -V Python 3.8.8

Picking Your Coding Environment

VS Code is a great environment for lots of coding projects, but, depending on which off-platform project you’re doing or what you’re hoping to create, you may want a different coding environment. VS Code can be used to program in many different languages and is very versatile, and we will explain how to install VS Code in this article.

If your off-platform project requires Jupyter Notebook, you can learn how to install that in our Installing Jupyter Notebook on a Chromebook article.

Installing VS Code

You can follow the below instructions or find installation instructions from the VS Code website here.

  1. It’s recommended that, in addition to running sudo apt-get update, we install the dependency gnome-keyring. You can do this with the command sudo apt-get install -y gnome-keyring.
    [email protected]:~$ sudo apt-get install -y gnome-keyring
  2. Next, to determine which installation file you should download, we need to figure out which CPU your Chromebook has. You can do this with the command dpkg --print-architecture.
    [email protected]:~$ dpkg --print-architecture
    You will see either amd64 or arm64.
  3. Go to the VS Code Download page. The Linux installation section will be underneath the image of the penguin.
    • If you saw amd64 when you ran the previous command, click on the button that says “64 bit” in the “.deb” row underneath the image of the penguin.
    • If you saw arm64 when you ran the previous command, click the button that says “ARM 64” in the “.deb” row underneath the image of the penguin. Image of Linux download section
  4. Open your “Files” on your Chromebook and go to your “Downloads” section. Double-click on the installer to begin the installation.

Image of the install file in the Downloads folder 5. A popup will let you know that you’re going to “Install app with Linux (Beta)”. Click “Install” to start the installation. You can press “Okay” to close the installation window. An image of the popup saying "Install" 6. Now, you can search for VS Code whenever you’re ready to start coding! An image of the popup saying "Install"

How Do I Access and Run a File from the Terminal?

You can use your Linux terminal to access files stored in the “Linux files” section of “My files”. To move files you’ve downloaded from Codecademy into this folder there are a few steps:

  1. Share your “Downloads” folder with your “Linux Files” folder by right-clicking on “Downloads” and then pressing “Share with Linux”. You must share the folder with the Linux files folder
  2. Now, you can move your file to “Linux files” and it will be accessible from your terminal! The file now lives in the Linux files folder
  3. You can also view the files in “Linux files” by going to your terminal and using the ls command.
    [email protected]:~$ ls move_me.py my_first_program.py
  4. You can run your program using the python command. You will write python3 name_of_file.py (for Python 3) and python name_of_file.py for Python2. If you’re using a different version of python, your command will look a little different.
    [email protected]:~$ python3 my_first_program.py Hello World!

Programming Locally

While there are some limitations to programming locally on your Chromebook, you can still program in many languages.

The following articles will help you set up a specific language or tool on your Chromebook:

Ready to Learn More?

Find the course that's right for you! Explore our catalog or get a recommendation.
Career Path

Data Scientist

Beginner friendly

85 Lessons
Career Path

Full-Stack Engineer

Beginner friendly

137 Lessons