technical:recipes:tensorflow-in-virtualenv

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
technical:recipes:tensorflow-in-virtualenv [2025-10-28 15:45] – [Create TensorFlow Virtualenv] thuachentechnical:recipes:tensorflow-in-virtualenv [2025-11-06 15:30] (current) – [Create TensorFlow Virtualenv] thuachen
Line 24: Line 24:
 </code> </code>
  
-The ''conda search tensorflow'' command can be used to locate the specific version you wish to install.  The example shows a search for TensorFlow release at least 2.17.0.+The ''conda search tensorflow'' command can be used to locate the specific version you wish to install.  The example shows a search for TensorFlow CPU release at least 2.17.0.
  
 <code bash> <code bash>
Line 33: Line 33:
 tensorflow                    2.17.0 cpu_py310h42475c5_1  conda-forge tensorflow                    2.17.0 cpu_py310h42475c5_1  conda-forge
 tensorflow                    2.17.0 cpu_py310h42475c5_2  conda-forge tensorflow                    2.17.0 cpu_py310h42475c5_2  conda-forge
-tensorflow                    2.17.0 cpu_py310h42475c5_3  conda-forge +
-tensorflow                    2.17.0 cpu_py311h6ac8430_0  conda-forge +
-tensorflow                    2.17.0 cpu_py311h6ac8430_1  conda-forge+
 ... ...
  
- +tensorflow                    2.19.0 cpu_py312h69ecde4_3  conda-forge 
-All versions of the TensorFlow virtual environment will be stored in the directory ''$WORKDIR/sw/tensorflow''; each virtual environment must have a unique name that will become the VALET version of TensorFlow. In this tutorial, we will install the Tensorflow version 2.19.0 with and without the CUDA support. An appropriate version for the former would be ''2.19.0:cpu'' and the latter ''2.19.0:cuda'' Those versions can be translated to VALET-friendly directory names:+tensorflow                    2.19.0 cpu_py312h69ecde4_52  conda-forge 
 +tensorflow                    2.19.0 cpu_py312h69ecde4_53  conda-forge 
 +</code> 
 +All versions of the TensorFlow virtual environment will be stored in the directory ''$WORKDIR/sw/tensorflow''; each virtual environment must have a unique name that will become the VALET version of TensorFlow. In this tutorial, we will install the Tensorflow version 2.17.0 with the CPU support and with CUDA support. An appropriate version for the former would be ''2.17.0:cpu'' and the latter ''2.17.0:cuda'' Those versions can be translated to VALET-friendly directory names:
  
 <code bash> <code bash>
-[(my_workgroup:user)@login01 ~]$ vpkg_id2path --version-id=2.19.0:cpu +[(my_workgroup:user)@login01 ~]$ vpkg_id2path --version-id=2.17.0:cpu 
-2.19.0-cpu +2.17.0-cpu 
-[(my_workgroup:user)@login01 ~]$ mkdir --mode=3750 ${WORKDIR}/sw/tensorflow/2.19.0-cpu+[(my_workgroup:user)@login01 ~]$ mkdir --mode=3750 ${WORKDIR}/sw/tensorflow/2.17.0-cpu
  
-[(my_workgroup:user)@login01 ~]$ vpkg_id2path --version-id=2.19.0:cuda +[(my_workgroup:user)@login01 ~]$ vpkg_id2path --version-id=2.17.0:cuda 
-2.19.0-cuda +2.17.0-cuda 
-[(my_workgroup:user)@login01 ~]$ mkdir --mode=3750 ${WORKDIR}/sw/tensorflow/2.19.0-cuda+[(my_workgroup:user)@login01 ~]$ mkdir --mode=3750 ${WORKDIR}/sw/tensorflow/2.17.0-cuda
 </code> </code>
  
Line 54: Line 55:
  
 <code bash> <code bash>
-[(my_workgroup:user)@login01 ~]$ conda create --prefix=${WORKDIR}/sw/tensorflow/2.19.0-cpu 'tensorflow[version=2.19.0,build=cpu_py312h69ecde4_52]' +[(my_workgroup:user)@login01 ~]$ conda create --prefix=${WORKDIR}/sw/tensorflow/2.17.0-cpu 'tensorflow[version=2.17.0,build=cpu_py310h42475c5_0]' 
-WARNING: A directory already exists at the target location '/work/workgroup/sw/tensorflow/2.19.0-cpu'+WARNING: A directory already exists at the target location '/work/workgroup/sw/tensorflow/2.17.0-cpu'
 but it is not a conda environment. but it is not a conda environment.
 Continue creating environment (y/[n])? y Continue creating environment (y/[n])? y
Line 67: Line 68:
 # To activate this environment, use # To activate this environment, use
 # #
-#     $ conda activate /work/workgroup/sw/tensorflow/2.19.0-cpu+#     $ conda activate /work/workgroup/sw/tensorflow/2.17.0-cpu
 # #
 # To deactivate an active environment, use # To deactivate an active environment, use
Line 77: Line 78:
  
 <code bash> <code bash>
-[(my_workgroup:user)@login01 ~]$ conda create --prefix=${WORKDIR}/sw/tensorflow/2.19.0-cuda 'tensorflow[version=2.19.0,build=cuda128py312hae5ec6b_202,channel=conda-forge]' +[(my_workgroup:user)@login01 ~]$ conda create --prefix=${WORKDIR}/sw/tensorflow/2.17.0-cuda 'python==3.10' -c conda-forge 
-WARNING: A directory already exists at the target location '/work/workgroup/sw/tensorflow/2.19.0-cuda'+WARNING: A directory already exists at the target location '/work/workgroup/sw/tensorflow/2.17.0-cuda'
 but it is not a conda environment. but it is not a conda environment.
 Continue creating environment (y/[n])? y Continue creating environment (y/[n])? y
Line 90: Line 91:
 # To activate this environment, use # To activate this environment, use
 # #
-#     $ conda activate /work/workgroup/sw/tensorflow/2.3.0-intel-python3.8+#     $ conda activate /work/workgroup/sw/tensorflow/2.17.0-cuda
 # #
 # To deactivate an active environment, use # To deactivate an active environment, use
Line 96: Line 97:
 #     $ conda deactivate #     $ conda deactivate
 </code> </code>
- +We will need to run the ''conda activate'' command and then install the Tensorflow with cuda: 
-Ignore that ''conda activate'' command as well. Roll back the environment changes before proceeding:+<code bash> 
 +[(my_workgroup:user)@login01 ~]$ conda activate /work/workgroup/sw/tensorflow/2.17.0-cuda 
 +(/work/workgroup/sw/tensorflow/2.17.0-cuda)[(my_workgroup:user)@login01 ~]$ pip install "tensorflow[and-cuda]==2.17.0" 
 +</code> 
 +Use ''conda deactivate'' command to exit the virtual environment. Roll back the environment changes before proceeding:
  
 <code bash> <code bash>
-[(my_workgroup:user)@login01 ~]$ vpkg_rollback +(/work/workgroup/sw/tensorflow/2.17.0-cuda)[(my_workgroup:user)@login01 ~]$ conda deactivate 
-[(my_workgroup:user)@login01 ~]$ +[(my_workgroup:user)@login01 ~]$ vpkg_rollback all
 </code> </code>
  
Line 122: Line 127:
           success: 0           success: 0
     versions:     versions:
-        "2.19.0:cpu": +        "2.17.0:cpu": 
-            description: 2.19.0 with CPU support+            description: 2.17.0 with CPU support
             dependencies:             dependencies:
                 - miniconda/25.1.1.2                 - miniconda/25.1.1.2
-        "2.19.0:cuda": +        "2.17.0:cuda": 
-            description: 2.19.0 with CUDA support+            description: 2.17.0 with CUDA support
             dependencies:             dependencies:
                 - miniconda/25.1.1.2                 - miniconda/25.1.1.2
Line 147: Line 152:
           success: 0           success: 0
     versions:     versions:
-        "2.19.0:cpu": +        "2.17.0:cpu": 
-            description: 2.19.0 with CPU support+            description: 2.17.0 with CPU support
             dependencies:             dependencies:
                 - miniconda/25.1.1.2                 - miniconda/25.1.1.2
-        "2.19.0:cuda": +        "2.17.0:cuda": 
-            description: 2.19.0 with CUDA support+            description: 2.17.0 with CUDA support
             dependencies:             dependencies:
                 - miniconda/25.1.1.2                 - miniconda/25.1.1.2
Line 174: Line 179:
 [/work/my_workgroup/sw/valet/tensorflow.vpkg_yaml] [/work/my_workgroup/sw/valet/tensorflow.vpkg_yaml]
 tensorflow               TensorFlow Python environments tensorflow               TensorFlow Python environments
-* 2.19.0:cpu              2.19.0 with GPU support +* 2.17.0:cpu              2.17.0 with GPU support 
-  2.19.0:cuda             2.19.0 with CUDA support+  2.17.0:cuda             2.17.0 with CUDA support
      
      :      :
Line 188: Line 193:
 # Setup TensorFlow virtualenv: # Setup TensorFlow virtualenv:
 # #
-vpkg_require tensorflow/2.19.0:cpu+vpkg_require tensorflow/2.17.0:cpu
  
 # #
  • technical/recipes/tensorflow-in-virtualenv.1761680728.txt.gz
  • Last modified: 2025-10-28 15:45
  • by thuachen