File size: 8,317 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# Manage Conda Environments
You are helping the user list conda environments and work with them to add packages.
## Your tasks:
1. **Check if conda is installed:**
```bash
which conda
conda --version
conda info
```
If not installed, offer to help install Miniconda or Anaconda.
2. **List all conda environments:**
```bash
conda env list
# or
conda info --envs
```
This shows:
- All environment names
- Their locations
- Current active environment (marked with *)
3. **Show current environment:**
```bash
echo $CONDA_DEFAULT_ENV
conda info --envs | grep "*"
```
4. **Display detailed environment information:**
For each environment, show:
```bash
# List packages in specific environment
conda list -n <env-name>
# Show environment details
conda env export -n <env-name>
# Show size
du -sh ~/miniconda3/envs/<env-name>
# or
du -sh ~/anaconda3/envs/<env-name>
```
5. **Ask user which environment to work with:**
Present the list and ask which environment they want to modify or examine.
6. **Activate environment:**
```bash
conda activate <env-name>
```
Verify activation:
```bash
conda info --envs
python --version
which python
```
7. **Show packages in environment:**
```bash
conda list
# or for specific environment
conda list -n <env-name>
# Show only explicitly installed packages
conda env export --from-history -n <env-name>
```
8. **Search for packages:**
Ask what packages user wants to install:
```bash
conda search <package-name>
conda search <package-name> --info
```
9. **Install packages:**
**Single package:**
```bash
conda install <package-name>
# or specify environment
conda install -n <env-name> <package-name>
```
**Multiple packages:**
```bash
conda install <package1> <package2> <package3>
```
**Specific version:**
```bash
conda install <package-name>=<version>
# Example:
conda install python=3.11
conda install numpy=1.24.0
```
**From specific channel:**
```bash
conda install -c conda-forge <package-name>
```
10. **Suggest common packages by category:**
**Data Science:**
```bash
conda install numpy pandas matplotlib seaborn scikit-learn
conda install jupyter jupyterlab notebook
conda install scipy statsmodels
```
**Machine Learning:**
```bash
conda install tensorflow pytorch torchvision
conda install keras scikit-learn xgboost
conda install -c conda-forge lightgbm
```
**Development:**
```bash
conda install ipython black flake8 pytest
conda install requests beautifulsoup4 selenium
conda install flask django fastapi
```
**Visualization:**
```bash
conda install matplotlib seaborn plotly
conda install bokeh altair
```
**Database:**
```bash
conda install sqlalchemy psycopg2 pymongo
conda install sqlite
```
11. **Update packages:**
**Update specific package:**
```bash
conda update <package-name>
```
**Update all packages in environment:**
```bash
conda update --all
```
**Update conda itself:**
```bash
conda update conda
```
12. **Remove packages:**
```bash
conda remove <package-name>
# or from specific environment
conda remove -n <env-name> <package-name>
```
13. **Create new environment:**
Offer to create a new environment:
```bash
# Basic environment
conda create -n <env-name> python=3.11
# With packages
conda create -n myenv python=3.11 numpy pandas jupyter
# From file
conda env create -f environment.yml
```
14. **Export environment:**
Help user export environment for sharing:
**Full export (with all dependencies):**
```bash
conda env export -n <env-name> > environment.yml
```
**Only explicitly installed packages:**
```bash
conda env export --from-history -n <env-name> > environment.yml
```
**As requirements.txt:**
```bash
conda list -n <env-name> --export > requirements.txt
```
15. **Clone environment:**
```bash
conda create --name <new-env> --clone <existing-env>
```
16. **Clean up conda:**
```bash
# Remove unused packages and caches
conda clean --all
# Remove packages cache
conda clean --packages
# Remove tarballs
conda clean --tarballs
# Check what would be removed
conda clean --all --dry-run
```
17. **Check environment conflicts:**
```bash
# Check for broken dependencies
conda info <package-name>
# Verify environment
conda env export -n <env-name> | conda env create -n test-env -f -
```
18. **Show environment size:**
```bash
# Size of all environments
du -sh ~/miniconda3/envs/*
# or
du -sh ~/anaconda3/envs/*
# Total conda size
du -sh ~/miniconda3
```
19. **Configure conda:**
**Add channels:**
```bash
conda config --add channels conda-forge
conda config --add channels bioconda
```
**Set channel priority:**
```bash
conda config --set channel_priority strict
```
**Show configuration:**
```bash
conda config --show
conda config --show channels
```
**Remove channel:**
```bash
conda config --remove channels <channel-name>
```
20. **Use mamba (faster alternative):**
If user has performance issues:
```bash
# Install mamba
conda install mamba -n base -c conda-forge
# Use mamba instead of conda
mamba install <package-name>
mamba search <package-name>
mamba env create -f environment.yml
```
21. **Troubleshooting common issues:**
**Environment not activating:**
```bash
conda init bash
source ~/.bashrc
```
**Package conflicts:**
```bash
# Create new environment instead
conda create -n new-env python=3.11 <packages>
```
**Slow package resolution:**
```bash
# Use mamba
conda install mamba -c conda-forge
# or
conda config --set solver libmamba
```
**Conda command not found:**
```bash
export PATH="$HOME/miniconda3/bin:$PATH"
conda init bash
```
22. **Best practices to share:**
- Create separate environment for each project
- Use environment.yml for reproducibility
- Pin important package versions
- Use conda-forge channel for latest packages
- Regularly clean up with `conda clean --all`
- Don't install packages in base environment
- Use mamba for faster package resolution
- Export environments before major changes
- Keep Python version explicit in environment
- Use `--from-history` for cross-platform compatibility
23. **Show workflow example:**
```bash
# Create environment
conda create -n data-project python=3.11
# Activate it
conda activate data-project
# Install packages
conda install numpy pandas jupyter matplotlib scikit-learn
# Verify
conda list
# Export for sharing
conda env export --from-history > environment.yml
# Deactivate when done
conda deactivate
```
24. **Integration with Jupyter:**
```bash
# Install ipykernel in environment
conda activate <env-name>
conda install ipykernel
# Register environment as Jupyter kernel
python -m ipykernel install --user --name=<env-name>
# Now available in Jupyter
jupyter lab
```
25. **Report current status:**
Summarize:
- Number of environments
- Active environment
- Total disk usage
- conda version
- Suggested actions based on user needs
## Important notes:
- Always activate environment before installing packages
- Base environment should be kept minimal
- Use `-n <env-name>` to work with environments without activating
- conda-forge channel has more packages than default
- mamba is drop-in replacement, much faster
- Environment.yml files ensure reproducibility
- Pin versions in production environments
- Clean up regularly to save disk space
- Don't mix pip and conda unless necessary (prefer conda)
- Use `--from-history` when exporting for other OS
- Jupyter needs ipykernel in each environment
- conda init modifies .bashrc - check if needed
|