Loading...
Loading...
Best practices for managing development environments including Python venv and conda. Always check environment status before installations and confirm with user before proceeding.
npx skill4agent add delphine-l/claude_global managing-environments# Check for active venv
echo "Python executable: $(which python)"
echo "Virtual environment: $VIRTUAL_ENV"
# Check for conda environment
echo "Conda environment: $CONDA_DEFAULT_ENV"
conda info --envs 2>/dev/null || echo "Conda not available"Python executable: /path/to/project/.venv/bin/python
Virtual environment: /path/to/project/.venv
Conda environment:Python executable: /path/to/miniconda3/envs/myenv/bin/python
Virtual environment:
Conda environment: myenvPython executable: /usr/bin/python
Virtual environment:
Conda environment:Virtual environment: /path/to/.venv
Conda environment: basewhich pythonI've detected the following environment:
- Environment type: [venv/conda/none]
- Location: [path]
- Python version: [version]
Is this the environment you want me to use for installing [package/tool]?# Activate (if needed)
source .venv/bin/activate # Linux/Mac
# or
.venv\Scripts\activate # Windows
# Install packages
pip install package-name
# Install with specific version
pip install package-name==1.2.3
# Install from requirements
pip install -r requirements.txt
# Install development dependencies
pip install -e ".[dev]"# Activate (if needed)
conda activate environment-name
# Install from conda-forge (preferred for scientific packages)
conda install -c conda-forge package-name
# Install with pip (if not available in conda)
pip install package-name
# Install from environment file
conda env update -f environment.yml
# Install specific version
conda install package-name=1.2.3conda-forgeconda install -c conda-forge packagebiocondaconda install -c bioconda packagepip install packageCondaToSNonInteractiveError: Terms of Service have not been accepted/path/to/envs/ENV_NAME/bin/pip install PACKAGE_NAME# This fails with TOS error
conda install -n curation_paper -c conda-forge jupyterlab -y
# Use pip instead
/Users/delphine/miniconda3/envs/curation_paper/bin/pip install jupyterlab⚠️ WARNING: No Python environment detected!
You're currently using system Python:
- Location: [path to python]
- Version: [version]
Installing packages to system Python can:
- Cause conflicts with system packages
- Require sudo/admin privileges
- Make projects difficult to reproduce
- Break system tools that depend on specific versions
I recommend creating a virtual environment first.Question: What type of project are you working on?
A. Pure Python project (web dev, scripting, etc.)
→ Recommend: Python venv
→ Fast, lightweight, standard Python tool
B. Data science / Scientific computing
→ Ask: Do you need non-Python dependencies? (R, C libraries, etc.)
B1. Yes (or using packages like numpy, scipy, pandas, etc.)
→ Recommend: Conda
→ Better binary dependency management
B2. No, only Python packages
→ Recommend: Python venv
→ Simpler and faster
C. Bioinformatics / Genomics
→ Recommend: Conda (with bioconda channel)
→ Most tools available via bioconda
→ Manages complex dependencies well
D. Galaxy tool development
→ Recommend: Conda
→ Galaxy uses conda for tool dependencies
→ Direct compatibility# Create venv
python -m venv .venv
# Activate
source .venv/bin/activate # Linux/Mac
# Verify
which python# Create conda environment
conda create -n project-name python=3.11
# Activate
conda activate project-name
# Verify
conda info --envs
which pythonpip install pandas1. Check environment status
2. Show user what environment is active
3. Ask: "Is this the environment you want to use?"
4. Wait for confirmation
5. Then: pip install pandas (or conda install as appropriate)Let me first check your environment...
[run environment detection]
I've detected: [environment details]
I need to install:
- pandas
- numpy
- matplotlib
Is this the correct environment? Should I use [pip/conda install -c conda-forge]?⚠️ I've detected you're in a virtual environment at:
/path/to/other-project/.venv
But we're working in directory:
/path/to/current-project
This might be the wrong environment. Options:
1. Deactivate and create/activate the correct environment for this project
2. Continue with current environment (if this is intentional)
3. Cancel installation
Which would you prefer?⚠️ You're currently in the conda 'base' environment.
It's generally better practice to create a separate environment for each project
to avoid dependency conflicts.
Options:
1. Create a new conda environment for this project
2. Continue with base environment (not recommended)
Would you like me to create a project-specific environment?project-a/
├── .venv/ # project-a's environment
├── requirements.txt
└── src/
project-b/
├── .venv/ # project-b's environment
├── requirements.txt
└── src/# Using same environment for multiple projects
# → Version conflicts inevitable# Create requirements.txt
pip freeze > requirements.txt
# Or for development
pip freeze > requirements-dev.txt# Create environment.yml
conda env export > environment.yml
# Or minimal version
conda env export --from-history > environment.yml# Python venv
.venv/
venv/
env/
# Conda
.conda/Python 3.11+ requiredname: myproject
dependencies:
- python=3.11
- pandas
- numpydef fetch_with_caching(item_id, output_dir):
"""Fetch data with local caching to support resume."""
output_file = output_dir / f"{item_id}_data.txt"
# Skip if already downloaded
if output_file.exists():
with open(output_file, 'r') as f:
content = f.read()
return True, "cached", content
# Fetch logic here...
# Save to file on success
return success, status, content
def main():
# Load existing results to skip completed work
existing_csv = base_dir / 'results.csv'
if existing_csv.exists():
df_existing = pd.read_csv(existing_csv)
existing_ids = set(df_existing['id'].tolist())
df_to_process = df_to_process[~df_to_process['id'].isin(existing_ids)]
print(f"Skipping {len(existing_ids)} items with existing data")
# Process remaining items
for item in df_to_process:
success, status, data = fetch_with_caching(item, output_dir)
# Process and accumulate results...
# Merge with existing results
if existing_csv.exists():
df_existing = pd.read_csv(existing_csv)
df_combined = pd.concat([df_existing, df_new], ignore_index=True)
else:
df_combined = df_new
# Save combined results
df_combined.to_csv(output_csv, index=False)try:
from tqdm import tqdm
iterator = tqdm(items, total=len(items), desc="Processing")
except ImportError:
print("(Install tqdm for progress bar: pip install tqdm)")
iterator = itemsimport time
for item in items:
result = fetch_data(item)
if result.success:
time.sleep(0.2) # Be respectful to external servicespython -m ensurepip
python -m pip install --upgrade pipconda activate# Initialize conda for shell
conda init bash # or zsh, fish, etc.
# Restart shell or source
source ~/.bashrc# Specify Python version when creating
python3.11 -m venv .venv# Specify version explicitly
conda create -n myenv python=3.11# Start fresh
rm -rf .venv
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt# Try updating resolver
conda update -n base conda
conda install -c conda-forge mamba # Faster solver
mamba install package-name# Check what's active
which python
echo $VIRTUAL_ENV
echo $CONDA_DEFAULT_ENV
# Python version
python --version
# Installed packages
pip list # for pip
conda list # for conda
# Environment location
pip show package-name # shows where package is installed# venv
source .venv/bin/activate # Linux/Mac
.venv\Scripts\activate # Windows
# conda
conda activate environment-name
# Deactivation
deactivate # venv
conda deactivate # condaLet me check your environment first...
[Checks environment]
I see you're in a Python venv at: /home/user/project/.venv
Python version: 3.11.5
Is this the correct environment for installing requests?pip install requests⚠️ WARNING: No virtual environment detected!
You're using system Python at: /usr/bin/python3
Installing to system Python is not recommended.
This is a data science package. I suggest creating a conda environment:
conda create -n ml-project python=3.11
conda activate ml-project
conda install -c conda-forge scikit-learn
Would you like me to help set this up?I notice you need scientific and bioinformatics packages.
Currently: No environment active
I recommend creating a conda environment because:
- Better binary dependency management for numpy/pandas
- Bioconda channel has biopython
- Manages versions more reliably
Suggested setup:
conda create -n bio-project python=3.11
conda activate bio-project
conda install -c conda-forge pandas numpy
conda install -c bioconda biopython
Would you like to proceed with this?