Automatic Python environment manager for students and developers
Project description
What is safeenv?
safeenv is a beginner-friendly Python CLI tool that automatically sets up, fixes, and diagnoses Python project environments.
Students and new developers often struggle with:
- Creating and activating virtual environments
- Generating
requirements.txtfiles - Getting a cloned project to run
- Mysterious
ModuleNotFoundErrormessages - Missing or broken dependencies
safeenv makes these problems disappear with simple, memorable commands.
Features
| Command | What it does |
|---|---|
safeenv init |
Create a .venv virtual environment in the current directory |
safeenv freeze |
Scan all .py files and generate requirements.txt |
safeenv setup |
Create .venv + install all dependencies (great after cloning) |
safeenv doctor |
Diagnose missing venv, packages, or bad Python versions |
safeenv fix |
Repair the environment automatically |
Installation
pip install safeenv
Or install in editable/development mode from source:
git clone https://github.com/safeenv/safeenv.git
cd safeenv
pip install -e ".[dev]"
After installation, the safeenv command will be available globally.
Quick Start
1. Start a new project
mkdir my-project && cd my-project
safeenv init
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
SafeEnv Initialization
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Python version detected: 3.11
โ Virtual environment created: .venv
Your environment is ready.
To activate:
Mac / Linux:
source .venv/bin/activate
Windows:
.venv\Scripts\activate
2. Scan your project and generate requirements.txt
safeenv freeze
Scanning project for imports...
โ Flask
โ numpy
โ pandas
โ requests
โ requirements.txt generated with 4 packages.
safeenv freeze uses Python AST parsing โ it reads your source files without
executing them, so it is completely safe.
3. Get a cloned project running in one command
git clone https://github.com/someone/awesome-project.git
cd awesome-project
safeenv setup
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Project Setup
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Checking environment...
โ Python version compatible: 3.11
โ Virtual environment created: .venv
Installing dependencies...
โ Flask installed
โ numpy installed
โ pandas installed
Project setup complete.
4. Check project health
safeenv doctor
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Project Health Report
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Python version : 3.11
Virtual environment : detected
requirements.txt : found
Issues found:
โ Missing dependency: torch
โ Missing dependency: fastapi
Recommendation:
Run: safeenv fix
5. Fix problems automatically
safeenv fix
Repairing environment...
โ Virtual environment: OK
Missing package detected: torch
Installing torch...
โ torch installed
Missing package detected: fastapi
Installing fastapi...
โ fastapi installed
โ Environment repaired successfully.
Command Reference
safeenv init
Creates a .venv virtual environment in the current directory using the
active Python interpreter.
safeenv init # current directory
safeenv init --dir /path/to/project
- Safe to run multiple times โ will never overwrite an existing
.venv - Displays platform-specific activation instructions
safeenv freeze
Scans all .py files in the project using Python AST parsing and writes
a requirements.txt.
safeenv freeze # writes requirements.txt
safeenv freeze --output deps.txt # custom output file
safeenv freeze --dir /path/to/project # specific directory
How it works:
- Recursively walks all
.pyfiles (ignores.venv,__pycache__, etc.) - Parses each file with
ast.parse()โ no code is executed - Collects all
importandfrom ... importstatements - Filters out Python standard-library modules
- Maps import names to correct PyPI names (e.g.
cv2โopencv-python) - Writes a sorted
requirements.txt
safeenv setup
The single command to run after cloning a project. Combines init + dependency installation.
safeenv setup
safeenv setup --dir /path/to/project
Steps performed:
- Checks Python version compatibility
- Creates
.venvif not present - Reads
requirements.txt - Installs each package into
.venv
safeenv doctor
Performs a read-only health check and lists all issues. Never modifies anything.
safeenv doctor
safeenv doctor --dir /path/to/project
Checks:
- Python version (minimum: 3.7)
.venvdirectory presencerequirements.txtpresence- Packages listed in
requirements.txtthat are not installed
safeenv fix
Automatically resolves issues reported by safeenv doctor.
safeenv fix
safeenv fix --dir /path/to/project
Actions:
- Creates
.venvif missing - Installs any missing packages from
requirements.txt
Import Name Mapping
safeenv freeze automatically translates common import names to their correct
PyPI package names:
| Import name | PyPI package |
|---|---|
cv2 |
opencv-python |
PIL |
Pillow |
sklearn |
scikit-learn |
bs4 |
beautifulsoup4 |
yaml |
PyYAML |
dotenv |
python-dotenv |
dateutil |
python-dateutil |
serial |
pyserial |
jwt |
PyJWT |
git |
GitPython |
(and many more โ see dependency_scanner.py for the full list)
Requirements
- Python 3.8 or newer
- Works on Windows, macOS, and Linux
- Runtime dependencies:
typerandrich(both installed automatically)
Development Setup
git clone https://github.com/safeenv/safeenv.git
cd safeenv
pip install -e ".[dev]"
Run tests
pytest
Run tests with coverage
pytest --cov=safeenv --cov-report=term-missing
Project Structure
safeenv/
โ
โโโ safeenv/
โ โโโ __init__.py # Package metadata and version
โ โโโ cli.py # Typer CLI commands (init, freeze, setup, doctor, fix)
โ โโโ env_manager.py # Virtual environment creation and detection
โ โโโ dependency_scanner.py # AST-based import scanning and requirements generation
โ โโโ installer.py # pip-based package installation helpers
โ โโโ doctor.py # Project health diagnostics
โ โโโ utils.py # Shared Rich console and styled print utilities
โ
โโโ tests/
โ โโโ conftest.py # Shared pytest fixtures
โ โโโ test_env_manager.py # Tests for virtual environment logic
โ โโโ test_dependency_scanner.py # Tests for AST scanning
โ โโโ test_cli.py # Integration tests for CLI commands
โ
โโโ README.md
โโโ LICENSE
โโโ pyproject.toml
Contributing
Contributions are welcome! Here is how to get started:
- Fork the repository on GitHub
- Clone your fork locally:
git clone https://github.com/your-username/safeenv.git cd safeenv pip install -e ".[dev]"
- Create a branch for your change:
git checkout -b feature/my-improvement
- Make your changes โ follow the existing code style
- Run the tests to make sure everything still works:
pytest
- Open a Pull Request with a clear description of what you changed and why
Guidelines
- Keep the tool lightweight and beginner-friendly
- Add tests for any new functionality
- Write clear docstrings for new functions
- Use type hints throughout
- Prefer simple, readable code over clever one-liners
License
This project is licensed under the MIT License โ see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file safeenv_tool-0.1.0.tar.gz.
File metadata
- Download URL: safeenv_tool-0.1.0.tar.gz
- Upload date:
- Size: 24.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d000e5dbf1c94c0b9c9571474cf2896d3f7bf455c9b99086d7f7d8c2b94dadd
|
|
| MD5 |
1fb3d4000a3936770fd0c7d071b445c9
|
|
| BLAKE2b-256 |
a82de07cddeb20380d5255af3894b7fe4dca5c578177c0c490f79ccbb7f79eff
|
File details
Details for the file safeenv_tool-0.1.0-py3-none-any.whl.
File metadata
- Download URL: safeenv_tool-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24d403ef0a90c4747fd543202d5903b28e3d262270fef5fc22ef74c229ef40b5
|
|
| MD5 |
e34da8427f73c32360b99ce8b8ed3b62
|
|
| BLAKE2b-256 |
c9dad87c1acbac8591e71a815b85f3740a643822f9494e349a9a7d73a862bb5f
|