Install Django and dependencies

After connecting to your SUSE Linux Enterprise Server (SLES) VM using SSH, you’ll install the Google Cloud CLI, update your system, install Python 3.11, and set up a virtual environment for your Django project.

Prepare the system

Update the system packages and install dependencies:

    

        
        
sudo zypper refresh
sudo zypper update -y
sudo zypper install -y curl git tar gzip

    

Install Python 3.11

Install Python 3.11:

    

        
        
sudo zypper install -y python311
which python3.11

    

Verify that Python and pip are installed correctly:

    

        
        
python3.11 --version
pip3.11 --version

    

The output is similar to:

    

        
        Python 3.11.10
pip 22.3.1 from /usr/lib/python3.11/site-packages/pip (python 3.11)

        
    

Install Google Cloud CLI (gcloud)

The Google Cloud CLI is required to authenticate with GCP and allow your Django application VM to interact with Google Cloud services such as GKE, Cloud SQL, Artifact Registry, Memorystore, and to build, deploy, and operate the Django platform.

Download and extract the Google Cloud SDK:

    

        
        
wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-460.0.0-linux-arm.tar.gz
tar -xvf google-cloud-sdk-460.0.0-linux-arm.tar.gz

    

Install gcloud:

    

        
        
./google-cloud-sdk/install.sh

    

After installation completes, exit and reconnect to apply the PATH changes:

    

        
        
exit

    

Initialize gcloud

Authenticate and configure the Google Cloud CLI:

    

        
        
gcloud init

    

During initialization, select Login with a new account. You’ll be prompted to authenticate using your browser and receive an auth code to copy back. Select the project you want to use and choose default settings when unsure.

Verify authentication

    

        
        
gcloud auth list

    

The output is similar to:

    

        
        Credentialed Accounts
ACTIVE  ACCOUNT
*       <PROJECT_NUMBER>-compute@developer.gserviceaccount.com

        
    

Create a project directory and virtual environment

Create a dedicated directory for your Django project and set up a Python virtual environment to isolate your project’s dependencies:

    

        
        
mkdir ~/myproject && cd ~/myproject
python3.11 -m venv venv
source venv/bin/activate

    

The python3.11 -m venv venv command creates an isolated Python environment named venv inside your project folder. Running source venv/bin/activate activates this environment.

Once activated, your command prompt displays (venv) at the beginning, indicating that you’re working inside an isolated Python environment.

Upgrade pip and install Django

With your virtual environment active, upgrade pip to the latest version:

    

        
        
python3 -m pip install --upgrade pip

    

Now install Django and additional useful packages for web development:

    

        
        
python3 -m pip install django gunicorn

    

This installs:

  • Django - the web framework for building your application
  • Gunicorn - a production-ready WSGI (Web Server Gateway Interface) server for running Django applications

Verify that Django is installed correctly:

    

        
        
django-admin --version

    

The output is similar to:

    

        
        5.2.10

        
    

What you’ve accomplished and what’s next

In this section, you installed:

  • Google Cloud CLI for GCP service management
  • Python 3.11 with a virtual environment
  • Django and Gunicorn for web application development

Next, you’ll verify Django is working by creating a basic project and running the development server.

Back
Next