Instalar Django Framework en Linux Ubuntu
Sistema operativo Linux Ubuntu.
Usaremos apt package manager para instalar Django Framework, pero es necesario instalar unos paquetes que son dependencias.
Instala el administrador de paquetes Python llamado pip:
$ sudo apt install python3-pip
Verifica el paquete pip instalado:
$ python3 -m pip --version
Su salida en termnal dice:
pip XX.X from /usr/lib/python3/dist-packages/pip (python 3.12)
Instala el paquete venv para crear entornos de desarrollo aislados para Python:
$ sudo apt install python3-venv
Verífica que el paquete venv se ha instalado:
python3 -m venv --help
La salida en terminal de la verificación del paquete venv instalado es este:
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
[--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
ENV_DIR [ENV_DIR ...]
Creates virtual Python environments in one or more target directories.
positional arguments:
ENV_DIR A directory to create the environment in.
options:
-h, --help show this help message and exit
--system-site-packages
Give the virtual environment access to the system
site-packages dir.
--symlinks Try to use symlinks rather than copies, when symlinks
are not the default for the platform.
--copies Try to use copies rather than symlinks, even when
symlinks are the default for the platform.
--clear Delete the contents of the environment directory if it
already exists, before environment creation.
--upgrade Upgrade the environment directory to use this version
of Python, assuming Python has been upgraded in-place.
--without-pip Skips installing or upgrading pip in the virtual
environment (pip is bootstrapped by default)
--prompt PROMPT Provides an alternative prompt prefix for this
environment.
--upgrade-deps Upgrade core dependencies (pip) to the latest version
in PyPI
Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.
Crea una carpeta llamada environments:
mkdir environments
Entra a la carpeta environments
cd environments
Piensa en un nombre para tu carpeta de entorno virtual, por ejemplo django51:
$ python3 -m venv django51
No hay salida en terminal por ejecutar el comando anterior, sin embargo, usa el comando tree para ver lo que se generó:
$ tree -L 3
.
├── bin
│ ├── activate
│ ├── activate.csh
│ ├── activate.fish
│ ├── Activate.ps1
│ ├── pip
│ ├── pip3
│ ├── pip3.12
│ ├── python -> python3
│ ├── python3 -> /usr/bin/python3
│ └── python3.12 -> python3
├── include
│ └── python3.12
├── lib
│ └── python3.12
├── lib64 -> lib
└── pyvenv.cfg
7 directories, 11 files
Activa el entorno de desarrollo:
$ source django51/bin/activate
(django51) ~/environtments $
Instala Django Framework:
python3 -m pip install django
La salida en terminal del comando anterior se ve así:
Collecting django
Downloading Django-5.1.5-py3-none-any.whl.metadata (4.2 kB)
Collecting asgiref<4,>=3.8.1 (from django)
Downloading asgiref-3.8.1-py3-none-any.whl.metadata (9.3 kB)
Collecting sqlparse>=0.3.1 (from django)
Downloading sqlparse-0.5.3-py3-none-any.whl.metadata (3.9 kB)
Downloading Django-5.1.5-py3-none-any.whl (8.3 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.3/8.3 MB 258.0 kB/s eta 0:00:00
Downloading asgiref-3.8.1-py3-none-any.whl (23 kB)
Downloading sqlparse-0.5.3-py3-none-any.whl (44 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 44.4/44.4 kB 362.1 kB/s eta 0:00:00
Installing collected packages: sqlparse, asgiref, django
Successfully installed asgiref-3.8.1 django-5.1.5 sqlparse-0.5.3
Verifica que el módulo Python, Django Framework este instalado:
$ python3 -m django --version
5.1.5