Lando is a development environment tool that makes it easier to set up and manage local development environments for web applications. To use Python within a Lando-based development environment, you can follow these general steps:
Create a Lando Configuration File
Make sure you have a Lando configuration file (e.g., .lando.yml) in your project's root directory. If you don't have one, you can create it. Here's a basic example:
name: py-ai
recipe: drupal10
config:
webroot: web
php: '8.2'
xdebug: false
composer: []
composer_version: '2.5.2'
python: '3.11.6'
services:
phpmyadmin:
type: phpmyadmin
hosts:
- database
database:
portforward: 3334
creds:
user: dr10
password: dr10
database: dr10
solr:
type: solr
python:
type: python:3.11.6
port: 80
ssl: true
command: tail -f /dev/null
extras:
- "apt-get update -y"
- "apt-get install build-essential"
build:
- pip install -r requirements.txt
In this example, we specify a python service and use the requirements.txt file to install Python dependencies.
Create a requirements.txt File
Create a requirements.txt file in your project directory (the same directory as the .lando.yml file). This file should contain the Python packages you need for your project. You can list the packages and their versions like this:
package1==version1
package2==version2
Replace package1, package2, version1, and version2 with the actual Python packages and versions you need.
Start Lando
Open a terminal, navigate to your project directory, and start Lando by running the following command:
lando start
Access Python
You can access Python within your Lando environment using the lando command:
lando ssh -s appserver
As noted above, the service in use is python, therefore the lando command is
lando ssh -s python
This will open a shell inside the python service container. You can run Python scripts and manage your Python environment from there.
A breakdown of the command:
lando: This is the main command or executable that you are running. Lando is a development tool that helps with local development environments for web projects. It simplifies the setup and management of development environments, particularly for web applications.
ssh: This is a command used to establish a secure shell (SSH) connection to a remote server or container. SSH is a protocol for securely connecting to and managing remote systems.
-s python: This part of the command is specifying a service or container to connect to within the Lando environment. It's instructing Lando to SSH into a service named "python."
The command lando ssh -s python is telling Lando to create an SSH connection to a service or container named "python" within your Lando development environment.
Install Additional Python Tools
If you need additional Python tools or packages that are not listed in your requirements.txt, you can install them inside the Lando container using pip.
pip install package3
Use Python in Your Project
You can now use Python in your project within the Lando environment. You can run Python scripts, interact with Python packages, and integrate Python functionality into your web application.