{"id":24880705,"url":"https://github.com/camilomartinezm/install-tensorflow","last_synced_at":"2026-05-02T09:32:44.714Z","repository":{"id":272141428,"uuid":"915449631","full_name":"CamiloMartinezM/install-tensorflow","owner":"CamiloMartinezM","description":"A correct installation of tensorflow once and for all.","archived":false,"fork":false,"pushed_at":"2025-03-02T07:38:48.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T06:16:16.580Z","etag":null,"topics":["tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CamiloMartinezM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-11T21:47:09.000Z","updated_at":"2025-03-02T07:38:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"c6d64846-3717-4335-8553-086b7767fc6f","html_url":"https://github.com/CamiloMartinezM/install-tensorflow","commit_stats":null,"previous_names":["camilomartinezm/install-tensorflow"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CamiloMartinezM%2Finstall-tensorflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CamiloMartinezM%2Finstall-tensorflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CamiloMartinezM%2Finstall-tensorflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CamiloMartinezM%2Finstall-tensorflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CamiloMartinezM","download_url":"https://codeload.github.com/CamiloMartinezM/install-tensorflow/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245791958,"owners_count":20672671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["tensorflow"],"created_at":"2025-02-01T11:19:14.106Z","updated_at":"2026-05-02T09:32:44.704Z","avatar_url":"https://github.com/CamiloMartinezM.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# install-tensorflow\n\n- [install-tensorflow](#install-tensorflow)\n  - [Automated Setup](#automated-setup)\n  - [Minimal Setup](#minimal-setup)\n  - [Installation](#installation)\n    - [Fixes](#fixes)\n    - [Explanation](#explanation)\n    - [Manual Setup](#manual-setup)\n  - [Additional Notes](#additional-notes)\n    - [Installation of `cuda-toolkit`](#installation-of-cuda-toolkit)\n  - [References](#references)\n\n## Automated Setup \n\nFor Python `3.12` and `tensorflow-2.16`, we can run the following commands:\n\n```\nconda create --name tf-2.16 python=3.12\nconda activate tf-2.16\nconda install nvidia/label/cuda-12.3.0::cuda-toolkit -c nvidia/label/cuda-12.3.0\nconda install -c nvidia cudnn=8.9 cuda-version=12.3\npip install \"tensorflow[and-cuda]==2.16.1\"\n\nexport NVIDIA_DIR=$(dirname $(dirname $(python -c \"import nvidia.cudnn;print(nvidia.cudnn.__file__)\")))\nexport LD_LIBRARY_PATH_ADDITIONS=$(echo ${NVIDIA_DIR}/*/lib/ | sed -r 's/\\s+/:/g')${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}\n\nconda env config vars set LD_LIBRARY_PATH=$CONDA_PREFIX/lib:$LD_LIBRARY_PATH_ADDITIONS\nconda env config vars set XLA_FLAGS=--xla_gpu_cuda_data_dir=$CONDA_PREFIX\n\nconda deactivate \nconda activate tf-2.16\n\npip install nvidia-tensorrt\n```\n\nAfter that, we need to create the symlinks as explained in the [Installation](#installation) section.\n\nTo automate this, I created the script [`setup_environment.sh`](setup_environment.sh) which can be run with arguments to create a conda environment with specific `python`, `tensorflow`, `cudnn` and `CUDA` versions like this:\n\n```\n./setup_environment.sh \\\n    --env-name tf-2.16 \\\n    --python-version 3.12 \\\n    --cuda-version 12.3.0 \\\n    --cudnn-version 8.9 \\\n    --tf-version 2.16.1\n```\n\nIt can also be run by itself, as it has the default arguments to create a conda environment named `tf-2.16` and install `tensorflow-2.16` with `python-3.12`, and the corresponding compatible versions of `CUDA` and `cudnn`. \n\nThat same command is in [`setup_environment_tf-2.16.sh`](setup_environment_tf-2.16.sh) for convenience. The scripts [`setup_environment_tf-2.17.sh`](setup_environment_tf-2.17.sh) and [`setup_environment_tf-2.18.sh`](setup_environment_tf-2.18.sh) were created for the same purpose.\n\n## Minimal Setup\nAccording to [this thread](https://github.com/tensorflow/tensorflow/issues/63109#issuecomment-2543966974):\n\n```\nconda create --name tensorflow python=3.12\nconda activate tensorflow\n\nconda install cuda -c nvidia/label/cuda-12.3.0\nconda env config vars set LD_LIBRARY_PATH=$CONDA_PREFIX/lib\nconda env config vars set XLA_FLAGS=--xla_gpu_cuda_data_dir=$CONDA_PREFIX\n\nconda deactivate\nconda activate tensorflow\n\nconda install cudnn=8.9\n```\nYou can check the `CUDA` and `cudnn` package versions compatible with each tensorflow version [here](https://www.tensorflow.org/install/source?hl=en#gpu).\n\nAfter this, we would need to install `tensorflow` and `nvidia-tensorrt` as explained in the [Installation](#installation) section.\n\n**Note:** Eventhough this setup works and allows for GPU usage, it gets the following warnings:\n\n```\nE external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\nE external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\nE external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n```\n\n## Installation\nAccording to [this thread](https://github.com/tensorflow/tensorflow/issues/61986#issuecomment-1811284728), as of the tensorflow release `2.15`, it will successfully install using:\n```\npython -m pip install \"tensorflow[and-cuda]==2.15\" --extra-index-url https://pypi.nvidia.com\n```\nOr for `2.16`:\n```\npython -m pip install \"tensorflow[and-cuda]==2.16\" --extra-index-url https://pypi.nvidia.com\n```\n### Fixes\nAfter that, we can install `nvidia-tensorrt` if not already installed by running: `pip install nvidia-tensorrt`. \n\nThen, we can run:\n\n```\n./setup_envars.sh\npython create_symlinks.py\n```\nWhere:\n* `setup_envars.sh` sets the environment variables `$LD_LIBRARY_PATH` and `$PATH` to include the necessary paths for `tensorrt_libs`, `CUDA` and `cudnn`.\n* `create_symlinks.py` creates the necessary symlinks for the `tensorrt_libs` folder.\n\nFinally, we can test whether `tensorflow` is correctly installed and can access the GPU as well as `tensorrt` by running the following command:\n\n```\npython3 -c \"import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))\"\n```\n*\u003csub\u003eThis command is included in [`test_gpu.sh`](test_gpu.sh).\u003c/sub\u003e*\n\nThe correct output should be something like:\n\n```\n2025-01-12 13:17:52.565350: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n2025-01-12 13:17:52.604063: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\nTo enable the following instructions: AVX2 AVX512F AVX512_VNNI AVX512_BF16 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]\n```\n\n### Explanation\nAfter installing `tensorflow`, it will probably print something like the following after running `import tensorflow`:\n\n```\n2024-04-21 08:00:13.414353: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n2024-04-21 08:00:13.552935: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\nTo enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n2024-04-21 08:00:14.655097: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n2024-04-21 08:00:16.735268: I external/local_xla/xla/stream_executor/cuda/cuda_executor.cc:984] could not open file to read NUMA node: /sys/bus/pci/devices/0000:17:00.0/numa_node\nYour kernel may have been built without NUMA support.\n2024-04-21 08:00:16.828498: W tensorflow/core/common_runtime/gpu/gpu_device.cc:2251] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.\n```\n\nFrom there, the most important warning is: `TF-TRT Warning: Could not find TensorRT`, which can be `strace`'d to check which files is `tensorrt` looking for, by running this command (from [this thread](https://github.com/tensorflow/tensorflow/issues/61468#issuecomment-2027387370)):\n\n```\nstrace -e open,openat python -c \"import tensorflow as tf\" 2\u003e\u00261 | grep \"libnvinfer\\|TF-TRT\"\n```\n*\u003csub\u003eThis command is included in [`strace_tensorrt.sh`](strace_tensorrt.sh).\u003c/sub\u003e*\n\nThis will print something like the following:\n\n```\nopenat(AT_FDCWD, \"miniconda3/envs/tf-2.16/lib/libnvinfer.so.8.6.1\", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No existe el fichero o el directorio)\nopenat(AT_FDCWD, \"miniconda3/envs/tf-2.16/lib/python3.10/site-packages/tensorflow/compiler/tf2tensorrt/../../../_solib_local/_Utensorflow/glibc-hwcaps/x86-64-v4/libnvinfer.so.8.6.1\", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No existe el fichero o el directorio)\nopenat(AT_FDCWD, \"miniconda3/envs/tf-2.16/lib/python3.10/site-packages/tensorflow/compiler/tf2tensorrt/../../../_solib_local/_Utensorflow/glibc-hwcaps/x86-64-v3/libnvinfer.so.8.6.1\", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No existe el fichero o el directorio)\n```\n\nFrom that stacktrace, we can check that the two important files \"missing\" are `libnvinfer.so.8.6.1` and `libnvinfer_plugin.so.8.6.1`. To fix that, we need to install `nvidia-tensorrt` if not already installed, by running: \n\n```\npip install nvidia-tensorrt\n```\nThis will install the packages: `tensorrt_cu12`, `tensorrt`, `nvidia-tensorrt`. After that, we need to add the `tensorrt_libs` folder created in our environment to the `LD_LIBRARY_PATH` environment variable, doing something like the following (suggested in [this thread](https://github.com/tensorflow/tensorflow/issues/61986#issuecomment-1815315673)):\n\n```\nTENSORRT_LIBS_PATH=$(dirname $(python -c \"import tensorrt_libs;print(tensorrt_libs.__file__)\"))\nLD_LIBRARY_PATH=$TENSORRT_LIBS_PATH:$CONDA_PREFIX/lib/:$LD_LIBRARY_PATH\n```\n**Note:** It's also recommended to add the location of `CUDA` in our system, as well as `nvidia/cudnn` (which should have been installed to the current environment's `site-packages` by the previous commands) to `$LD_LIBRARY_PATH`.\n\nAfter that, running the `strace` command again sometimes still gives `-1` errors, meaning it could not find the files. For that, we need to symlink the wanted files to the corresponding files in `tensorrt_libs`. For example, sometimes the wanted files are `libnvinfer.so.8.6.1` and `libnvinfer_plugin.so.8.6.1`, but in `tensorrt_libs` only `libnvinfer.so.8` and `libnvinfer_plugin.so.8.6.1` exist. Thus, we need to create the symlinks such that:\n\n```\n/miniconda3/envs/tf-2.16/lib/python3.10/site-packages/tensorrt_libs/libnvinfer.so.8.6.1 -\u003e /home/camilo/miniconda3/envs/tf-2.16/lib/python3.10/site-packages/tensorrt_libs/libnvinfer.so.8\n/miniconda3/envs/tf-2.16/lib/python3.10/site-packages/tensorrt_libs/libnvinfer_plugin.so.8.6.1 -\u003e /home/camilo/miniconda3/envs/tf-2.16/lib/python3.10/site-packages/tensorrt_libs/libnvinfer_plugin.so.8\n```\n\n### Manual Setup\nIf you are still getting a similar error to the following, after executing `import tensorflow`:\n\n```\n2025-06-16 16:25:17.192168: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 AVX512F AVX512_VNNI AVX512_BF16 FMA\nTo enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.\n2025-06-16 16:25:17.270001: I tensorflow/core/util/util.cc:169] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n2025-06-16 16:25:17.293116: E tensorflow/stream_executor/cuda/cuda_blas.cc:2981] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n2025-06-16 16:25:17.644286: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: $ENV_PATH/lib:$ENV_PATH/lib/python3.10/site-packages/tensorrt_libs:/usr/local/cuda/lib64\n2025-06-16 16:25:17.644343: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: $ENV_PATH/lib:$ENV_PATH/lib/python3.10/site-packages/tensorrt_libs:/usr/local/cuda/lib64\n2025-06-16 16:25:17.644352: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.\n```\nYou may try to manually create the symlinks for the missing files, that is, go to the `tensorrt_libs` folder in your environment (e.g., `$ENV_PATH/lib:$ENV_PATH/lib/python3.10/site-packages/tensorrt_libs`), and find the files you do have. For example, if you are missing `libnvinfer.so.7` and `libnvinfer_plugin.so.7`, like in the previous error, but when you go to that folder, you find there exist `libnvinfer.so.10` and `libnvinfer_plugin.so.10`, you can run:\n\n```bash\nln -s libnvinfer.so.10 libnvinfer.so.7\nln -s libnvinfer_plugin.so.10 libnvinfer_plugin.so.7\n```\n\n## Additional Notes\n\n### Installation of `cuda-toolkit`\nThanks to [this answer](https://stackoverflow.com/questions/78484090/conda-cuda12-incompatibility), to install a specific version of `cuda-toolkit` in a `conda` environment, we can run the following command e.g. for `cuda-12.3.0`:\n\n```\nconda install nvidia/label/cuda-12.3.0::cuda-toolkit -c nvidia/label/cuda-12.3.0\n```\n\n## References\n* StackOverflow. [Cuda 12 + `tf-nightly 2.12`: Could not find cuda drivers on your machine, GPU will not be used, while every checking is fine and in torch it works](https://stackoverflow.com/questions/75614728/cuda-12-tf-nightly-2-12-could-not-find-cuda-drivers-on-your-machine-gpu-will).\n* Tensorflow Issue Thread. [TF-TRT Warning: Could not find TensorRT #61468](https://github.com/tensorflow/tensorflow/issues/61468)\n* Tensorflow Issue Thread. [TensorFlow `2.10.0` not compatible with TensorRT `8.4.3` #57679](https://github.com/tensorflow/tensorflow/issues/57679)\n* Tensorflow Issue Thread. [`tensorrt==8.5.3.1` from `[and-cuda]` not available in Python `3.11` #61986](https://github.com/tensorflow/tensorflow/issues/61986)\n* Tensorflow Issue Thread. [WSL2 - TensorFlow Install Issue Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered](https://github.com/tensorflow/tensorflow/issues/63109)\n* Tensorflow Issue Thread. [TF 2.17.0 RC0 Fails to work with GPUs (and TF 2.16 too) #63362](https://github.com/tensorflow/tensorflow/issues/63362#issuecomment-2016019354)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcamilomartinezm%2Finstall-tensorflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcamilomartinezm%2Finstall-tensorflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcamilomartinezm%2Finstall-tensorflow/lists"}