Programming in Python on a 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
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 typepython3 -V
and notpython -V
! Typingpython
will check the Python 2 version which does not come preinstalled.yourusername@penguin:~$ python3 -V
If this worked, it should display your Python 3 version.
yourusername@penguin:~$ python3 -V Python 3.7.3
If it didn’t work (or if you typed in
python
instead ofpython3
), you will see something like:yourusername@penguin:~$ 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.
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 usingwget
but will show both approaches.Using
wget
First, you’ll need to move into the
/usr/src
folder in your terminal. Then, when using thewget
command, you would change the Python version to match the one you are trying to download:yourusername@penguin:~$ cd /usr/src yourusername@penguin:/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.
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 themv
command.yourusername@penguin:~$ sudo mv https://www.python.org/ftp/python/3.8.8/Python-3.8.8.tgz /usr/src/
You will now need to unzip the file and check if it worked! We will use the
tar
command to unzip it.yourusername@penguin:/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 ofpython3
since we downloaded Python 3.8.8 in this example.yourusername@penguin:~$ 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.
It’s recommended that, in addition to running
sudo apt-get update
, we install the dependencygnome-keyring
. You can do this with the commandsudo apt-get install -y gnome-keyring
.yourusername@penguin:~$ sudo apt-get install -y gnome-keyring
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
.yourusername@penguin:~$ dpkg --print-architecture
You will see either
amd64
orarm64
.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.
- If you saw
Open your “Files” on your Chromebook and go to your “Downloads” section. Double-click on the installer to begin the installation.
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.
Now, you can search for VS Code whenever you’re ready to start coding!
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:
- Share your “Downloads” folder with your “Linux Files” folder by right-clicking on “Downloads” and then pressing “Share with Linux”.
- Now, you can move your file to “Linux files” and it will be accessible from your terminal!
- You can also view the files in “Linux files” by going to your terminal and using the
ls
command.yourusername@penguin:~$ ls move_me.py my_first_program.py
- You can run your program using the
python
command. You will writepython3 name_of_file.py
(for Python 3) andpython name_of_file.py
for Python2. If you’re using a different version of python, your command will look a little different.yourusername@penguin:~$ 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:
Author
'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'
Meet the full teamRelated articles
- Article
Web Programming on a Chromebook
This article will teach you how to set up for web development on Chromebooks so you can do off-platform web development projects on your Chromebook. - Article
Programming Locally on a Chromebook
This article will teach you how to set up the Linux environment on your Chromebook so you can program and do Codecademy off-platform projects on your Chromebook.