File size: 1,234 Bytes
292d92c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
Set up and manage Python virtual environments.
Your task:
1. Determine best approach for the project:
- **venv** (built-in, lightweight)
- **virtualenv** (more features)
- **conda** (data science, complex dependencies)
- **poetry** (modern dependency management)
- **pipenv** (Pipfile-based)
2. Create virtual environment:
```bash
# Using venv
python3 -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows
# Using conda
conda create -n myenv python=3.11
conda activate myenv
```
3. Manage dependencies:
```bash
# Install packages
pip install -r requirements.txt
# Generate requirements
pip freeze > requirements.txt
# For conda
conda env export > environment.yml
```
4. Best practices:
- Never install packages globally
- Use requirements.txt or environment.yml
- Pin versions for reproducibility
- Separate dev and production dependencies
- Add venv/ to .gitignore
5. Project setup guidance:
- Create virtual environment
- Install dependencies
- Configure IDE to use environment
- Document setup process in README
Help users establish proper Python environment isolation and dependency management.
|