Python Environments
Python Environments
This article details the configuration and management of Python environments on our MediaWiki servers. Proper environment management is crucial for maintaining application stability, avoiding dependency conflicts, and facilitating reproducible builds. This guide is intended for system administrators and developers working with Python-based extensions or tools within the MediaWiki ecosystem.
Understanding Python Environments
A Python environment is a self-contained directory that contains a specific Python interpreter and a set of installed packages. This isolation prevents conflicts between different projects that might require different versions of the same package. We primarily utilize virtual environments to achieve this isolation. Without environments, installing packages globally can lead to versioning issues and break existing functionality. See Manual:Configuration for general configuration guidelines.
Tools for Environment Management
We employ several tools for creating and managing Python environments:
- venv: The standard Python package for creating lightweight virtual environments. This is our preferred method for most projects.
- virtualenv: An older, but still useful, tool for creating isolated Python environments. It supports older Python versions that `venv` may not.
- pip: The package installer for Python. Used within environments to install and manage dependencies. See Help:Search for more on pip usage.
- Poetry: A dependency management and packaging tool. While not universally adopted, it’s becoming increasingly popular for larger projects. Consult Help:Contents for broader MediaWiki help.
Creating and Activating Environments
The following outlines the steps for creating and activating environments using `venv`. These instructions assume you have Python 3 installed. Refer to Manual:Upgrading PHP for platform specifics.
Using venv
1. Create the environment:
```bash python3 -m venv /path/to/your/environment ```
Replace `/path/to/your/environment` with the desired location for the environment directory.
2. Activate the environment:
* On Linux/macOS:
```bash source /path/to/your/environment/bin/activate ```
* On Windows:
```bash /path/to/your/environment/Scripts/activate ```
Once activated, your shell prompt will typically be prefixed with the environment name (e.g., `(your_environment) $`).
3. Deactivate the environment:
```bash deactivate ```
Example Environment Specifications
The following tables detail the specifications for several common Python environments used on our servers. These environments are regularly audited for security vulnerabilities. See Help:System messages for error reporting.
Environment Name | Python Version | Purpose | Location |
---|---|---|---|
MediaWiki Extensions Dev | 3.9 | Development of new MediaWiki extensions | /opt/environments/mediawiki-extensions-dev/ |
Data Analysis | 3.10 | Data analysis and reporting tasks | /opt/environments/data-analysis/ |
Monitoring Scripts | 3.8 | Running system monitoring scripts | /opt/environments/monitoring-scripts/ |
Managing Dependencies with Pip
Once an environment is activated, you can use `pip` to install packages:
```bash pip install <package_name> ```
It's best practice to create a `requirements.txt` file to track the dependencies for your project.
```bash pip freeze > requirements.txt ```
To install dependencies from a `requirements.txt` file:
```bash pip install -r requirements.txt ```
See Help:API for information on extending MediaWiki with Python.
Environment Security Considerations
- Regular Updates: Keep Python and all installed packages up-to-date to address security vulnerabilities.
- Limited Permissions: Restrict access to environment directories to authorized users only.
- Dependency Auditing: Regularly audit dependencies for known vulnerabilities using tools like `pip-audit`.
- Avoid Global Installations: Never install packages globally unless absolutely necessary. Always use virtual environments. Review Manual:Pywikibot for a related topic.
Advanced Configuration: Poetry
For more complex projects, consider using Poetry. It simplifies dependency management and packaging.
Command | Description |
---|---|
`poetry new <project_name>` | Creates a new Poetry project. |
`poetry add <package_name>` | Adds a dependency to the project. |
`poetry install` | Installs the project's dependencies. |
`poetry update` | Updates dependencies to the latest compatible versions. |
`poetry build` | Builds a package for distribution. |
Poetry uses a `pyproject.toml` file to manage project metadata and dependencies. Refer to Help:Editing pages for editing configuration files.
Troubleshooting Common Issues
Problem | Possible Solution |
---|---|
Environment not activating | Double-check the path to the `activate` script. Ensure the script has execute permissions. |
Package installation fails | Verify your internet connection. Check for spelling errors in the package name. Try upgrading pip (`pip install --upgrade pip`). |
Dependency conflicts | Use `pip freeze` to identify conflicting packages. Consider creating a new environment with specific versions of the required packages. |
Conclusion
Effective Python environment management is essential for maintaining a stable and secure MediaWiki infrastructure. By following the guidelines outlined in this article, you can ensure that your Python-based projects are isolated, reproducible, and free from dependency conflicts. For further assistance, consult the Help:Contents or contact the server administration team.
Intel-Based Server Configurations
Configuration | Specifications | Benchmark |
---|---|---|
Core i7-6700K/7700 Server | 64 GB DDR4, NVMe SSD 2 x 512 GB | CPU Benchmark: 8046 |
Core i7-8700 Server | 64 GB DDR4, NVMe SSD 2x1 TB | CPU Benchmark: 13124 |
Core i9-9900K Server | 128 GB DDR4, NVMe SSD 2 x 1 TB | CPU Benchmark: 49969 |
Core i9-13900 Server (64GB) | 64 GB RAM, 2x2 TB NVMe SSD | |
Core i9-13900 Server (128GB) | 128 GB RAM, 2x2 TB NVMe SSD | |
Core i5-13500 Server (64GB) | 64 GB RAM, 2x500 GB NVMe SSD | |
Core i5-13500 Server (128GB) | 128 GB RAM, 2x500 GB NVMe SSD | |
Core i5-13500 Workstation | 64 GB DDR5 RAM, 2 NVMe SSD, NVIDIA RTX 4000 |
AMD-Based Server Configurations
Configuration | Specifications | Benchmark |
---|---|---|
Ryzen 5 3600 Server | 64 GB RAM, 2x480 GB NVMe | CPU Benchmark: 17849 |
Ryzen 7 7700 Server | 64 GB DDR5 RAM, 2x1 TB NVMe | CPU Benchmark: 35224 |
Ryzen 9 5950X Server | 128 GB RAM, 2x4 TB NVMe | CPU Benchmark: 46045 |
Ryzen 9 7950X Server | 128 GB DDR5 ECC, 2x2 TB NVMe | CPU Benchmark: 63561 |
EPYC 7502P Server (128GB/1TB) | 128 GB RAM, 1 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (128GB/2TB) | 128 GB RAM, 2 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (128GB/4TB) | 128 GB RAM, 2x2 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (256GB/1TB) | 256 GB RAM, 1 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (256GB/4TB) | 256 GB RAM, 2x2 TB NVMe | CPU Benchmark: 48021 |
EPYC 9454P Server | 256 GB RAM, 2x2 TB NVMe |
Order Your Dedicated Server
Configure and order your ideal server configuration
Need Assistance?
- Telegram: @powervps Servers at a discounted price
⚠️ *Note: All benchmark scores are approximate and may vary based on configuration. Server availability subject to stock.* ⚠️