Christopher Juckins

SysAdmin Tips, Tricks and other Software Tools

User Tools

Site Tools


python_virtual_environments

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
python_virtual_environments [2023/04/28 15:43] juckinspython_virtual_environments [2023/08/10 11:34] juckins
Line 16: Line 16:
  
   * (Accept license agreement and all the suggested default choices)   * (Accept license agreement and all the suggested default choices)
 +  * Note that if you do not want conda's base environment to be activated upon startup, run the following:
  
-  ~/miniconda3/bin/conda create -n testenv -c conda-forge time numpy requests pygrib netCDF4 scipy+  conda config --set auto_activate_base false 
 + 
 +Now try creating a test conda environment: 
 + 
 +  cd ~/miniconda3/envs 
 +  ~/miniconda3/bin/conda create -n testenv2 python=3.11.4 -c conda-forge time numpy requests pygrib netCDF4 scipy
   ~/miniconda3/bin/conda init bash   ~/miniconda3/bin/conda init bash
  
Line 29: Line 35:
   conda deactivate   conda deactivate
      
-Other useful commmands: +Other useful commmands (see https://www.python.org/downloads/ for specific python versions) 
-  conda create -n testenv2 python=3.11.3 (with specific version of python)+  conda create -n testenv2 python=3.11.3
   conda activate testenv2   conda activate testenv2
      
Line 44: Line 50:
   conda remove --name myenv --all (remove a conda environment)   conda remove --name myenv --all (remove a conda environment)
  
-__Running a cron under conda__+__Running a cron under conda (is this correct?)__
   21 15 * * * conda activate testenv2; /path/to/script.py > /tmp/output.txt (just call the correct version of python in first line of the script)   21 15 * * * conda activate testenv2; /path/to/script.py > /tmp/output.txt (just call the correct version of python in first line of the script)
  
Line 52: Line 58:
     * Update the first line to point to the correct version of python     * Update the first line to point to the correct version of python
   * Run cron under conda   * Run cron under conda
-    * As long as you update the first line in the script to point to the desired version of python, then you don'need to activate the conda env (?)+    * If you update the first line in the script to point to desired conda version of python, then no need to activate the conda env (?)
  
 __Using venv to set up a python virtual environment__ __Using venv to set up a python virtual environment__
python_virtual_environments.txt · Last modified: 2023/08/10 11:35 by juckins