Django is an open-source Python-based framework that deters the architectural pattern of model-template-views. It is maintained by the Django Software Foundation, an independent non-profit organization in the US. Since Django is a python-based framework, Python has to be installed on our Chromebook to do anything with Django. In simple terms, Django is useless without Python. Therefore, we shall first install Python on our Chromebook to kick start this tutorial guide.
Installing Python on Chrome OS
The latest version of Python is 3. Hence you need to upgrade if you have an older version of Python.
Note: Don’t mind if you have Python 3.6 and above already installed.
Latest Chromebook releases support Linux apps. However, the Linux applications support is not enabled by default. Therefore, we ought to first enable the Linux application support on our Chromebooks. Once you have the Linux applications support enabled, you will access the Terminal window, which we shall use to execute the Linux commands. Our article on How to set up and configure Linux on a Chromebook will give you a clear insight into enabling Linux applications on your Chromebook.
Since Python is a Linux application, we shall install it using the terminal, but first, we must check and confirm if it is installed on our Chromebook or not. To do so, run the command line provided below:
python3 --version or python --version
The commands above will check if Python has been installed or not. If the output shows a version number, Python is installed. However, if you get an error such as “-bash:python: command not found,” it means Python has not been installed, and therefore, we need to install it.
Run the commands below to install Python on your Chromebook:
sudo apt update sudo apt install software-properties-common sudo add-apt-repository ppa:deadsnakes/ppa sudo apt install python3 python3 --version
Those commands will install Python and check if it has been successfully installed. Once you are certain that Python has been installed, you can install Django.
Installing Django on Chrome OS
Now that Python is installed, let us install Django using the terminal.
Installation guides are always different depending on installing an official release package or a specific distribution package. However, installing the official release package is recommended as it contains all bug fixes that might prevent your application from running into errors. So, to install Django on your Chromebook, stick to this article guide.
We shall be using two different methods to illustrate how to install Django on our Chromebook.
Method 1: Using Pip
This is the widely used method of installing Django. To use this method, we must have a pip installed. If you are not sure whether pip is installed on your Chromebook or not, you can try running the installation command and see if everything works as expected. If you get an error, you can return and try installing pip.
Pip is automatically installed on your Chromebook when:
- You are using the official Python downloaded from the official download page
- You are working in a virtual environment
- The python version you are using has not to be modified to remove the ensurepip file.
Install pip
First, download the pip script from here.
Once you have downloaded the script, open your terminal and use the cd command to navigate to the folder containing the downloaded script and run the command below:
python get-pip.py
Alternatively, you can run this command to install pip directly from the terminal:
sudo apt install python3-pip
Check the installed pip version by running the code below:
pip3 --version
That’s all. Pip has been installed on your Chromebook; you can continue with the installation phase.
Create a virtual environment
Virtual environments aids users create a Python environment. A virtual environment usually referred to as “virtualenv,” is used to create organized Python environments. The environment has its installation directories and does not share libraries with other virtual environments. To create a virtual environment, we shall use “virtualenvwrapper.” It is a set of useful scripts used to create and delete virtual environments.
Features of virtualenvwrapper
- Organizes all the virtual environments in one location
- Uses a single command to switch between different virtual environments
- Has tab-completion advantages
- It contains a plugin system that creates a sharable extension
- Includes wrappers for managing the virtual environment (Creating, deleting, and copying)
Run the command below to create a virtualenv:
pip install virtualenvwrapper or pip3 install virtualenvwrapper
Once the command has been successfully executed, add the following command line to your shell’s startup file.
source /usr/local/bin/virtualenvwrapper.sh
Note: The path should be changed depending on where your virtualenvwrapper is located. This will prevent unnecessary errors from occurring the next time you get to the virtual environment.
Once you have created a virtual environment, execute the command line below from your terminal to install Django.
pip install Django or pip3 install Django
Once that command is executed, run the commands below to confirm if Django has been installed correctly on your Chromebook.
python3 >>> import django >>> print(django.get_version())
Alternatively, you can check the installed packages by running the command provided herein:
lssitepackages
Method 2: Using Conda
With this method, we shall be using conda to install Django. If you don’t have conda, this process won’t succeed since conda is a basic prerequisite. Our post, “How to install and update Anaconda on Chromebook,” will help you install conda on your Chromebook.
Once you have conda installed, run the command below to install Django:
conda install django
Note: I am not using the conda method since I removed it from my Chromebook
confirm the Django installation by running the commands below:
python3 >>> import django >>> print(django.get_version())
That’s all. Django has been installed on your Chromebook.
Note: Remember to check out the article posts provided herein to help you with the specific installations, such as installing Conda and enabling Linux support which by default is disabled.
Conclusion
The latest releases of Chromebook come equipped with Linux support enabling us to run Linux applications natively on our Chromebooks. Developers will conquer with us that Django is one of the widely used languages in the market. Therefore, those using Chromebooks for development or learning purposes are lucky as they can now use Django without any hindrance.