This document provides a step-by-step guide to setting up and using a Python virtual environment on the IBM i, specifically tailored for FormaServe projects.
Virtual environments are a crucial part of Python development, allowing you to create isolated spaces for your projects. This is particularly important when working with multiple projects that may have conflicting dependencies or require different versions of the same package.
Ensure Python is installed on your system. You can check by running:
python3 --versionIf Python is not installed, you may need to install it using the yum package manager.
A virtual environment is a self-contained directory that contains a Python installation for a particular version of Python, along with additional packages. It allows you to manage dependencies for different projects separately, avoiding version conflicts.
- Dependency Isolation: Each project can have its own dependencies, regardless of what dependencies every other project has.
- Version Control: You can specify which versions of packages your project requires, ensuring consistency across different environments.
- Easy Management: You can easily create, activate, and deactivate environments as needed.
- Portability: You can share your project dependencies by providing a
requirements.txtfile, rather than including the virtual environment itself in version control.
Most modern Python versions come with the venv module by default. You can verify its availability by running:
python3 -m venv --helpIf the command is unavailable, install it using:
yum install python3-venvFor consistency, FormaServe always uses .venv as the name for the virtual environment.
Navigate to your project directory and run:
python3 -m venv .venvReplace .venv with your preferred environment name.
Run the following command to activate your environment:
- On the IFS:
source .venv/bin/activate
Once activated, your terminal prompt should change, indicating you're in the virtual environment.
Use pip inside the virtual environment to install packages:
pip install package_nameCheck installed packages with:
pip listExit the virtual environment by running:
deactivateSimply delete the virtual environment folder:
rm -rf .venvVirtual environments are essential for managing dependencies in Python projects. Always activate the relevant environment when working on a project to ensure dependency isolation.
- FormaServe Systems Ltd - All work - FormaServe
All Rights Reserved. This software is proprietary and confidential.
Unauthorised copying, modification, distribution, or creation of derivative works of this code is strictly prohibited without the express written consent of FormaServe Systems Ltd.
- Andy Youens - FormaServe Systems Ltd 1990 - All rights reserved.
- Nick Youens - FormaServe Systems Ltd 1990 - All rights reserved.
- Jane Youens - FormaServe Systems Ltd 1990 - All rights reserved.
