CUDA対応のtensorflowインストールがわかりにくい件

AlmaLinux 9環境でNVIDIA GPUでCUDAが動く環境を作ったときに、とりあえず動作テストとしてtensorflowでも動かすか、と試してみたら、ドキュメントに騙された件についてメモ

まず、最初に参照したドキュメントは TensorFlow 2 をインストールする

CPU と GPUのどちらも「pip install tensorflow」でインストールできる、と書いてある

では、インストール

[testuser@vgpu ~]$ pip list
Package         Version
--------------- --------
dbus-python     1.2.18
distlib         0.3.2
distro          1.5.0
filelock        3.7.1
gpg             1.15.1
libcomps        0.1.18
nftables        0.1
packaging       20.9
pip             21.3.1
platformdirs    2.5.4
pycairo         1.20.1
PyGObject       3.40.1
pyparsing       2.4.7
python-dateutil 2.8.1
PyYAML          5.4.1
rpm             4.16.1.3
selinux         3.6
sepolicy        3.6
setools         4.4.4
setuptools      53.0.0
six             1.15.0
systemd-python  234
virtualenv      20.21.1
[testuser@vgpu ~]$ pip install tensorflow
Defaulting to user installation because normal site-packages is not writeable
Collecting tensorflow
  Downloading tensorflow-2.19.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (644.8 MB)
     |████████████████████████████████| 644.8 MB 18 kB/s
Collecting h5py>=3.11.0
  Downloading h5py-3.13.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.6 MB)
     |████████████████████████████████| 4.6 MB 92.7 MB/s
Collecting absl-py>=1.0.0
  Downloading absl_py-2.2.2-py3-none-any.whl (135 kB)
     |████████████████████████████████| 135 kB 85.3 MB/s
Collecting typing-extensions>=3.6.6
  Downloading typing_extensions-4.13.2-py3-none-any.whl (45 kB)
     |████████████████████████████████| 45 kB 9.4 MB/s
Collecting grpcio<2.0,>=1.24.3
  Downloading grpcio-1.71.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.9 MB)
     |████████████████████████████████| 5.9 MB 87.9 MB/s
Collecting tensorflow-io-gcs-filesystem>=0.23.1
  Downloading tensorflow_io_gcs_filesystem-0.37.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.1 MB)
     |████████████████████████████████| 5.1 MB 89.6 MB/s
Collecting google-pasta>=0.1.1
  Downloading google_pasta-0.2.0-py3-none-any.whl (57 kB)
     |████████████████████████████████| 57 kB 27.5 MB/s
Requirement already satisfied: packaging in /usr/lib/python3.9/site-packages (from tensorflow) (20.9)
Collecting wrapt>=1.11.0
  Downloading wrapt-1.17.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (82 kB)
     |████████████████████████████████| 82 kB 5.8 MB/s
Collecting astunparse>=1.6.0
  Downloading astunparse-1.6.3-py2.py3-none-any.whl (12 kB)
Collecting flatbuffers>=24.3.25
  Downloading flatbuffers-25.2.10-py2.py3-none-any.whl (30 kB)
Requirement already satisfied: six>=1.12.0 in /usr/lib/python3.9/site-packages (from tensorflow) (1.15.0)
Collecting requests<3,>=2.21.0
  Downloading requests-2.32.3-py3-none-any.whl (64 kB)
     |████████████████████████████████| 64 kB 21.4 MB/s
Collecting termcolor>=1.1.0
  Downloading termcolor-3.1.0-py3-none-any.whl (7.7 kB)
Collecting ml-dtypes<1.0.0,>=0.5.1
  Downloading ml_dtypes-0.5.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.7 MB)
     |████████████████████████████████| 4.7 MB 98 kB/s
Collecting keras>=3.5.0
  Downloading keras-3.9.2-py3-none-any.whl (1.3 MB)
     |████████████████████████████████| 1.3 MB 62.7 MB/s
Requirement already satisfied: setuptools in /usr/lib/python3.9/site-packages (from tensorflow) (53.0.0)
Collecting numpy<2.2.0,>=1.26.0
  Downloading numpy-2.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.5 MB)
     |████████████████████████████████| 19.5 MB 53 kB/s
Collecting protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0dev,>=3.20.3
  Downloading protobuf-5.29.4-cp38-abi3-manylinux2014_x86_64.whl (319 kB)
     |████████████████████████████████| 319 kB 80.5 MB/s
Collecting opt-einsum>=2.3.2
  Downloading opt_einsum-3.4.0-py3-none-any.whl (71 kB)
     |████████████████████████████████| 71 kB 2.0 MB/s
Collecting tensorboard~=2.19.0
  Downloading tensorboard-2.19.0-py3-none-any.whl (5.5 MB)
     |████████████████████████████████| 5.5 MB 88.3 MB/s
Collecting gast!=0.5.0,!=0.5.1,!=0.5.2,>=0.2.1
  Downloading gast-0.6.0-py3-none-any.whl (21 kB)
Collecting libclang>=13.0.0
  Downloading libclang-18.1.1-py2.py3-none-manylinux2010_x86_64.whl (24.5 MB)
     |████████████████████████████████| 24.5 MB 55 kB/s
Collecting wheel<1.0,>=0.23.0
  Downloading wheel-0.45.1-py3-none-any.whl (72 kB)
     |████████████████████████████████| 72 kB 5.3 MB/s
Collecting optree
  Downloading optree-0.15.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (397 kB)
     |████████████████████████████████| 397 kB 74.3 MB/s
Collecting namex
  Downloading namex-0.0.9-py3-none-any.whl (5.8 kB)
Collecting rich
  Downloading rich-14.0.0-py3-none-any.whl (243 kB)
     |████████████████████████████████| 243 kB 78.5 MB/s
Collecting charset-normalizer<4,>=2
  Downloading charset_normalizer-3.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (149 kB)
     |████████████████████████████████| 149 kB 79.2 MB/s
Collecting urllib3<3,>=1.21.1
  Downloading urllib3-2.4.0-py3-none-any.whl (128 kB)
     |████████████████████████████████| 128 kB 74.9 MB/s
Collecting idna<4,>=2.5
  Downloading idna-3.10-py3-none-any.whl (70 kB)
     |████████████████████████████████| 70 kB 33.1 MB/s
Collecting certifi>=2017.4.17
  Downloading certifi-2025.4.26-py3-none-any.whl (159 kB)
     |████████████████████████████████| 159 kB 78.6 MB/s
Collecting werkzeug>=1.0.1
  Downloading werkzeug-3.1.3-py3-none-any.whl (224 kB)
     |████████████████████████████████| 224 kB 67.2 MB/s
Collecting markdown>=2.6.8
  Downloading markdown-3.8-py3-none-any.whl (106 kB)
     |████████████████████████████████| 106 kB 55.2 MB/s
Collecting tensorboard-data-server<0.8.0,>=0.7.0
  Downloading tensorboard_data_server-0.7.2-py3-none-manylinux_2_31_x86_64.whl (6.6 MB)
     |████████████████████████████████| 6.6 MB 61.3 MB/s
Requirement already satisfied: pyparsing>=2.0.2 in /usr/lib/python3.9/site-packages (from packaging->tensorflow) (2.4.7)
Collecting importlib-metadata>=4.4
  Downloading importlib_metadata-8.7.0-py3-none-any.whl (27 kB)
Collecting MarkupSafe>=2.1.1
  Downloading MarkupSafe-3.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (20 kB)
Collecting markdown-it-py>=2.2.0
  Downloading markdown_it_py-3.0.0-py3-none-any.whl (87 kB)
     |████████████████████████████████| 87 kB 29.4 MB/s
Collecting pygments<3.0.0,>=2.13.0
  Downloading pygments-2.19.1-py3-none-any.whl (1.2 MB)
     |████████████████████████████████| 1.2 MB 77.3 MB/s
Collecting zipp>=3.20
  Downloading zipp-3.21.0-py3-none-any.whl (9.6 kB)
Collecting mdurl~=0.1
  Downloading mdurl-0.1.2-py3-none-any.whl (10.0 kB)
Installing collected packages: zipp, mdurl, typing-extensions, pygments, numpy, MarkupSafe, markdown-it-py, importlib-metadata, wheel, werkzeug, urllib3, tensorboard-data-server, rich, protobuf, optree, namex, ml-dtypes, markdown, idna, h5py, grpcio, charset-normalizer, certifi, absl-py, wrapt, termcolor, tensorflow-io-gcs-filesystem, tensorboard, requests, opt-einsum, libclang, keras, google-pasta, gast, flatbuffers, astunparse, tensorflow
Successfully installed MarkupSafe-3.0.2 absl-py-2.2.2 astunparse-1.6.3 certifi-2025.4.26 charset-normalizer-3.4.2 flatbuffers-25.2.10 gast-0.6.0 google-pasta-0.2.0 grpcio-1.71.0 h5py-3.13.0 idna-3.10 importlib-metadata-8.7.0 keras-3.9.2 libclang-18.1.1 markdown-3.8 markdown-it-py-3.0.0 mdurl-0.1.2 ml-dtypes-0.5.1 namex-0.0.9 numpy-2.0.2 opt-einsum-3.4.0 optree-0.15.0 protobuf-5.29.4 pygments-2.19.1 requests-2.32.3 rich-14.0.0 tensorboard-2.19.0 tensorboard-data-server-0.7.2 tensorflow-2.19.0 tensorflow-io-gcs-filesystem-0.37.1 termcolor-3.1.0 typing-extensions-4.13.2 urllib3-2.4.0 werkzeug-3.1.3 wheel-0.45.1 wrapt-1.17.2 zipp-3.21.0
[testuser@vgpu ~]$

そして、テストとして「python3 -c “import tensorflow as tf; print(tf.config.list_physical_devices(‘GPU’))”」を実行

[testuser@vgpu ~]$ python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
2025-05-15 11:35:31.898614: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:467] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
E0000 00:00:1747276531.922384    2049 cuda_dnn.cc:8579] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
E0000 00:00:1747276531.929813    2049 cuda_blas.cc:1407] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
W0000 00:00:1747276531.948919    2049 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
W0000 00:00:1747276531.948946    2049 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
W0000 00:00:1747276531.948951    2049 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
W0000 00:00:1747276531.948954    2049 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
2025-05-15 11:35:31.954990: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
W0000 00:00:1747276535.245548    2049 gpu_device.cc:2341] 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.
Skipping registering GPU devices...
[]
[testuser@vgpu ~]$

GPU対応については https://www.tensorflow.org/install/gpu を見ろ、とある・・・

こちらでは「pip install ‘tensorflow[and-cuda]’」でインストールしろ、とある


[testuser@vgpu ~]$ pip list
Package                      Version
---------------------------- ---------
absl-py                      2.2.2
astunparse                   1.6.3
certifi                      2025.4.26
charset-normalizer           3.4.2
dbus-python                  1.2.18
distlib                      0.3.2
distro                       1.5.0
filelock                     3.7.1
flatbuffers                  25.2.10
gast                         0.6.0
google-pasta                 0.2.0
gpg                          1.15.1
grpcio                       1.71.0
h5py                         3.13.0
idna                         3.10
importlib_metadata           8.7.0
keras                        3.9.2
libclang                     18.1.1
libcomps                     0.1.18
Markdown                     3.8
markdown-it-py               3.0.0
MarkupSafe                   3.0.2
mdurl                        0.1.2
ml_dtypes                    0.5.1
namex                        0.0.9
nftables                     0.1
numpy                        2.0.2
opt_einsum                   3.4.0
optree                       0.15.0
packaging                    20.9
pip                          21.3.1
platformdirs                 2.5.4
protobuf                     5.29.4
pycairo                      1.20.1
Pygments                     2.19.1
PyGObject                    3.40.1
pyparsing                    2.4.7
python-dateutil              2.8.1
PyYAML                       5.4.1
requests                     2.32.3
rich                         14.0.0
rpm                          4.16.1.3
selinux                      3.6
sepolicy                     3.6
setools                      4.4.4
setuptools                   53.0.0
six                          1.15.0
systemd-python               234
tensorboard                  2.19.0
tensorboard-data-server      0.7.2
tensorflow                   2.19.0
tensorflow-io-gcs-filesystem 0.37.1
termcolor                    3.1.0
typing_extensions            4.13.2
urllib3                      2.4.0
virtualenv                   20.21.1
Werkzeug                     3.1.3
wheel                        0.45.1
wrapt                        1.17.2
zipp                         3.21.0
[testuser@vgpu ~]$ pip install 'tensorflow[and-cuda]'
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: tensorflow[and-cuda] in ./.local/lib/python3.9/site-packages (2.19.0)
Requirement already satisfied: flatbuffers>=24.3.25 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (25.2.10)
Requirement already satisfied: google-pasta>=0.1.1 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (0.2.0)
Requirement already satisfied: gast!=0.5.0,!=0.5.1,!=0.5.2,>=0.2.1 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (0.6.0)
Requirement already satisfied: termcolor>=1.1.0 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (3.1.0)
Requirement already satisfied: wrapt>=1.11.0 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (1.17.2)
Requirement already satisfied: opt-einsum>=2.3.2 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (3.4.0)
Requirement already satisfied: setuptools in /usr/lib/python3.9/site-packages (from tensorflow[and-cuda]) (53.0.0)
Requirement already satisfied: typing-extensions>=3.6.6 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (4.13.2)
Requirement already satisfied: six>=1.12.0 in /usr/lib/python3.9/site-packages (from tensorflow[and-cuda]) (1.15.0)
Requirement already satisfied: numpy<2.2.0,>=1.26.0 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (2.0.2)
Requirement already satisfied: absl-py>=1.0.0 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (2.2.2)
Requirement already satisfied: protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0dev,>=3.20.3 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (5.29.4)
Requirement already satisfied: requests<3,>=2.21.0 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (2.32.3)
Requirement already satisfied: keras>=3.5.0 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (3.9.2)
Requirement already satisfied: h5py>=3.11.0 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (3.13.0)
Requirement already satisfied: astunparse>=1.6.0 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (1.6.3)
Requirement already satisfied: ml-dtypes<1.0.0,>=0.5.1 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (0.5.1)
Requirement already satisfied: tensorboard~=2.19.0 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (2.19.0)
Requirement already satisfied: libclang>=13.0.0 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (18.1.1)
Requirement already satisfied: grpcio<2.0,>=1.24.3 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (1.71.0)
Requirement already satisfied: packaging in /usr/lib/python3.9/site-packages (from tensorflow[and-cuda]) (20.9)
Requirement already satisfied: tensorflow-io-gcs-filesystem>=0.23.1 in ./.local/lib/python3.9/site-packages (from tensorflow[and-cuda]) (0.37.1)
Collecting nvidia-cufft-cu12==11.2.3.61
  Downloading nvidia_cufft_cu12-11.2.3.61-py3-none-manylinux2014_x86_64.whl (192.5 MB)
     |████████████████████████████████| 192.5 MB 52 kB/s
Collecting nvidia-cublas-cu12==12.5.3.2
  Downloading nvidia_cublas_cu12-12.5.3.2-py3-none-manylinux2014_x86_64.whl (363.3 MB)
     |████████████████████████████████| 363.3 MB 50 kB/s
Collecting nvidia-cudnn-cu12==9.3.0.75
  Downloading nvidia_cudnn_cu12-9.3.0.75-py3-none-manylinux2014_x86_64.whl (577.2 MB)
     |████████████████████████████████| 577.2 MB 65 kB/s
Collecting nvidia-nvjitlink-cu12==12.5.82
  Downloading nvidia_nvjitlink_cu12-12.5.82-py3-none-manylinux2014_x86_64.whl (21.3 MB)
     |████████████████████████████████| 21.3 MB 67 kB/s
Collecting nvidia-cuda-runtime-cu12==12.5.82
  Downloading nvidia_cuda_runtime_cu12-12.5.82-py3-none-manylinux2014_x86_64.whl (895 kB)
     |████████████████████████████████| 895 kB 38.5 MB/s
Collecting nvidia-nccl-cu12==2.23.4
  Downloading nvidia_nccl_cu12-2.23.4-py3-none-manylinux2014_x86_64.whl (199.0 MB)
     |████████████████████████████████| 199.0 MB 53 kB/s
Collecting nvidia-cusparse-cu12==12.5.1.3
  Downloading nvidia_cusparse_cu12-12.5.1.3-py3-none-manylinux2014_x86_64.whl (217.6 MB)
     |████████████████████████████████| 217.6 MB 51 kB/s
Collecting nvidia-cuda-nvcc-cu12==12.5.82
  Downloading nvidia_cuda_nvcc_cu12-12.5.82-py3-none-manylinux2014_x86_64.whl (22.5 MB)
     |████████████████████████████████| 22.5 MB 56 kB/s
Collecting nvidia-cuda-cupti-cu12==12.5.82
  Downloading nvidia_cuda_cupti_cu12-12.5.82-py3-none-manylinux2014_x86_64.whl (13.8 MB)
     |████████████████████████████████| 13.8 MB 47 kB/s
Collecting nvidia-cuda-nvrtc-cu12==12.5.82
  Downloading nvidia_cuda_nvrtc_cu12-12.5.82-py3-none-manylinux2014_x86_64.whl (24.9 MB)
     |████████████████████████████████| 24.9 MB 52 kB/s
Collecting nvidia-curand-cu12==10.3.6.82
  Downloading nvidia_curand_cu12-10.3.6.82-py3-none-manylinux2014_x86_64.whl (56.3 MB)
     |████████████████████████████████| 56.3 MB 49 kB/s
Collecting nvidia-cusolver-cu12==11.6.3.83
  Downloading nvidia_cusolver_cu12-11.6.3.83-py3-none-manylinux2014_x86_64.whl (130.3 MB)
     |████████████████████████████████| 130.3 MB 51 kB/s
Requirement already satisfied: wheel<1.0,>=0.23.0 in ./.local/lib/python3.9/site-packages (from astunparse>=1.6.0->tensorflow[and-cuda]) (0.45.1)
Requirement already satisfied: rich in ./.local/lib/python3.9/site-packages (from keras>=3.5.0->tensorflow[and-cuda]) (14.0.0)
Requirement already satisfied: namex in ./.local/lib/python3.9/site-packages (from keras>=3.5.0->tensorflow[and-cuda]) (0.0.9)
Requirement already satisfied: optree in ./.local/lib/python3.9/site-packages (from keras>=3.5.0->tensorflow[and-cuda]) (0.15.0)
Requirement already satisfied: certifi>=2017.4.17 in ./.local/lib/python3.9/site-packages (from requests<3,>=2.21.0->tensorflow[and-cuda]) (2025.4.26)
Requirement already satisfied: idna<4,>=2.5 in ./.local/lib/python3.9/site-packages (from requests<3,>=2.21.0->tensorflow[and-cuda]) (3.10)
Requirement already satisfied: urllib3<3,>=1.21.1 in ./.local/lib/python3.9/site-packages (from requests<3,>=2.21.0->tensorflow[and-cuda]) (2.4.0)
Requirement already satisfied: charset-normalizer<4,>=2 in ./.local/lib/python3.9/site-packages (from requests<3,>=2.21.0->tensorflow[and-cuda]) (3.4.2)
Requirement already satisfied: tensorboard-data-server<0.8.0,>=0.7.0 in ./.local/lib/python3.9/site-packages (from tensorboard~=2.19.0->tensorflow[and-cuda]) (0.7.2)
Requirement already satisfied: werkzeug>=1.0.1 in ./.local/lib/python3.9/site-packages (from tensorboard~=2.19.0->tensorflow[and-cuda]) (3.1.3)
Requirement already satisfied: markdown>=2.6.8 in ./.local/lib/python3.9/site-packages (from tensorboard~=2.19.0->tensorflow[and-cuda]) (3.8)
Requirement already satisfied: pyparsing>=2.0.2 in /usr/lib/python3.9/site-packages (from packaging->tensorflow[and-cuda]) (2.4.7)
Requirement already satisfied: importlib-metadata>=4.4 in ./.local/lib/python3.9/site-packages (from markdown>=2.6.8->tensorboard~=2.19.0->tensorflow[and-cuda]) (8.7.0)
Requirement already satisfied: MarkupSafe>=2.1.1 in ./.local/lib/python3.9/site-packages (from werkzeug>=1.0.1->tensorboard~=2.19.0->tensorflow[and-cuda]) (3.0.2)
Requirement already satisfied: pygments<3.0.0,>=2.13.0 in ./.local/lib/python3.9/site-packages (from rich->keras>=3.5.0->tensorflow[and-cuda]) (2.19.1)
Requirement already satisfied: markdown-it-py>=2.2.0 in ./.local/lib/python3.9/site-packages (from rich->keras>=3.5.0->tensorflow[and-cuda]) (3.0.0)
Requirement already satisfied: zipp>=3.20 in ./.local/lib/python3.9/site-packages (from importlib-metadata>=4.4->markdown>=2.6.8->tensorboard~=2.19.0->tensorflow[and-cuda]) (3.21.0)
Requirement already satisfied: mdurl~=0.1 in ./.local/lib/python3.9/site-packages (from markdown-it-py>=2.2.0->rich->keras>=3.5.0->tensorflow[and-cuda]) (0.1.2)
Installing collected packages: nvidia-nvjitlink-cu12, nvidia-cusparse-cu12, nvidia-cublas-cu12, nvidia-nccl-cu12, nvidia-cusolver-cu12, nvidia-curand-cu12, nvidia-cufft-cu12, nvidia-cudnn-cu12, nvidia-cuda-runtime-cu12, nvidia-cuda-nvrtc-cu12, nvidia-cuda-nvcc-cu12, nvidia-cuda-cupti-cu12
Successfully installed nvidia-cublas-cu12-12.5.3.2 nvidia-cuda-cupti-cu12-12.5.82 nvidia-cuda-nvcc-cu12-12.5.82 nvidia-cuda-nvrtc-cu12-12.5.82 nvidia-cuda-runtime-cu12-12.5.82 nvidia-cudnn-cu12-9.3.0.75 nvidia-cufft-cu12-11.2.3.61 nvidia-curand-cu12-10.3.6.82 nvidia-cusolver-cu12-11.6.3.83 nvidia-cusparse-cu12-12.5.1.3 nvidia-nccl-cu12-2.23.4 nvidia-nvjitlink-cu12-12.5.82
[testuser@vgpu ~]$
[testuser@vgpu ~]$ pip list
Package                      Version
---------------------------- ---------
absl-py                      2.2.2
astunparse                   1.6.3
certifi                      2025.4.26
charset-normalizer           3.4.2
dbus-python                  1.2.18
distlib                      0.3.2
distro                       1.5.0
filelock                     3.7.1
flatbuffers                  25.2.10
gast                         0.6.0
google-pasta                 0.2.0
gpg                          1.15.1
grpcio                       1.71.0
h5py                         3.13.0
idna                         3.10
importlib_metadata           8.7.0
keras                        3.9.2
libclang                     18.1.1
libcomps                     0.1.18
Markdown                     3.8
markdown-it-py               3.0.0
MarkupSafe                   3.0.2
mdurl                        0.1.2
ml_dtypes                    0.5.1
namex                        0.0.9
nftables                     0.1
numpy                        2.0.2
nvidia-cublas-cu12           12.5.3.2
nvidia-cuda-cupti-cu12       12.5.82
nvidia-cuda-nvcc-cu12        12.5.82
nvidia-cuda-nvrtc-cu12       12.5.82
nvidia-cuda-runtime-cu12     12.5.82
nvidia-cudnn-cu12            9.3.0.75
nvidia-cufft-cu12            11.2.3.61
nvidia-curand-cu12           10.3.6.82
nvidia-cusolver-cu12         11.6.3.83
nvidia-cusparse-cu12         12.5.1.3
nvidia-nccl-cu12             2.23.4
nvidia-nvjitlink-cu12        12.5.82
opt_einsum                   3.4.0
optree                       0.15.0
packaging                    20.9
pip                          21.3.1
platformdirs                 2.5.4
protobuf                     5.29.4
pycairo                      1.20.1
Pygments                     2.19.1
PyGObject                    3.40.1
pyparsing                    2.4.7
python-dateutil              2.8.1
PyYAML                       5.4.1
requests                     2.32.3
rich                         14.0.0
rpm                          4.16.1.3
selinux                      3.6
sepolicy                     3.6
setools                      4.4.4
setuptools                   53.0.0
six                          1.15.0
systemd-python               234
tensorboard                  2.19.0
tensorboard-data-server      0.7.2
tensorflow                   2.19.0
tensorflow-io-gcs-filesystem 0.37.1
termcolor                    3.1.0
typing_extensions            4.13.2
urllib3                      2.4.0
virtualenv                   20.21.1
Werkzeug                     3.1.3
wheel                        0.45.1
wrapt                        1.17.2
zipp                         3.21.0
[testuser@vgpu ~]$

だいぶ差分があった

そして実行


[testuser@vgpu ~]$ python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
2025-05-15 11:45:19.350181: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:467] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
E0000 00:00:1747277119.373769    2108 cuda_dnn.cc:8579] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
E0000 00:00:1747277119.381364    2108 cuda_blas.cc:1407] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
W0000 00:00:1747277119.400331    2108 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
W0000 00:00:1747277119.400358    2108 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
W0000 00:00:1747277119.400362    2108 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
W0000 00:00:1747277119.400365    2108 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
2025-05-15 11:45:19.406358: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
[testuser@vgpu ~]$

というわけで、tensorflowをnvidia GPU環境でインストールするときは 「pip install ‘tensorflow[and-cuda]’」でやる必要がある、という話でした

PowerShellでファイルの詳細情報をとる

excelやwordファイルのプロパティを見ると「詳細」タブにいろいろ情報が入っている。

これをPowerShellでファイル情報を収集する際に載せれるように調査した。

面倒なのがPowerShellの標準機能では収集できず、Shell.Application を使って収集するのだが、ストレートに各ファイルの情報をとるのではなく、そのファイルが置いてあるフォルダ情報のなかから取得する、という手法をとる必要がある。

$shell = New-Object -COMObject Shell.Application
$Getfolder = $shell.Namespace("フォルダパス")
$Getfile = $Getfolder.ParseName("調査したいファイル名")

...で、 $Getfile.ExtendedProperty('名前') でいろいろ取れる

ExtendedPropertyで取れる項目についていい感じでまとまってる資料は発見できず

詳細プロパティ取得するときに指定するもの
タイトル$Getfile.ExtendedProperty(‘System.Title’)
件名$Getfile.ExtendedProperty(‘System.Subject’)
作成者[string]$Getfile.ExtendedProperty(‘System.Author’)
前回保存者$Getfile.ExtendedProperty(‘System.Document.LastAuthor’)
コンテンツの作成日時$Getfile.ExtendedProperty(‘System.Document.DateCreated’)
前回保存日時$Getfile.ExtendedProperty(‘System.Document.DateSaved’)
前回印刷日$Getfile.ExtendedProperty(‘System.Document.DatePrinted’)
ファイル所有者$Getfile.ExtendedProperty(‘System.FileOwner’)
ファイル作成日時$Getfile.ExtendedProperty(‘System.DateCreated’)
ファイル更新日時$Getfile.ExtendedProperty(‘System.DateModified’)
ファイルアクセス日時$Getfile.ExtendedProperty(‘System.DateAccessed’)

実際に取得したものからドキュメントを調べてみるとWindows Property System に関するもの、ということが判明

System.Titleなどの最上位階層についてのSystem.Coreに関するドキュメント
System.Documentに関するドキュメント

今回使わなかった値については、上記のドキュメント群を調べればわかる


前回作った「PowerShellを使ってドロップしたフォルダ内にあるファイル一覧をテキストファイルに保存する」を修正したものがこちら

# ドラッグされたフォルダの中にあるファイル一覧をつくるやつ
#
# 使い方
#  1. このファイルを保存する
#  2. このファイルのショートカットを作成する
#  3. ショートカットのプロパティを開き"リンク先"の項目の先頭に「powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -File 」をつけて保存
#  4. 作成されたショートカットの上に、フォルダをドロップすると、ウィンドウが開いて確認される
#  5. 作成するファイルリストの保存ファイル名を指定する
#  6. 出力される
#
$Args | foreach{
    echo $_.GetType()
    $searchdir = Get-Item -LiteralPath $_
}

Write-Host $searchdir.FullName "のファイル一覧を作成します"
pause

$shell = New-Object -COMObject Shell.Application

# https://pg-note.com/archives/1144 より
# 必要なアセンブリを読み込む
Add-Type -AssemblyName System.Windows.Forms 
$dialog = New-Object Windows.Forms.SaveFileDialog 

$dialog.Title = "CSVファイルの保存" 
$dialog.Filter = "テキストファイル(*.txt)|*.txt|csvファイル(*.csv)|*.csv|全てのファイル|*.*" 
$dialog.InitialDirectory = [Environment]::GetFolderPath("MyDocuments")
$dialog.FileName = $searchdir.Name

$ret = $dialog.ShowDialog() 
$outputfile=$dialog.FileName

# CSV出力向けの処理
$results=@()
$linecount=0
#


if ($ret -eq "OK"){
    Write-Host ("保存するファイル名、" + $outputfile) 

    # ディレクトリの検索 start
    Get-ChildItem -Recurse $searchdir -Attributes Hidden,System,Archive,ReadOnly,Normal,Compressed,SparseFile| ForEach-Object {
    $filename=$_.FullName
    $fileobject=$_

        if( !$_.PSIsContainer ){
            Write-Host $filename
            
            # CSV向け処理 start
            $output = New-Object -TypeName PSObject
            $output | Add-Member -MemberType NoteProperty -Name "ファイル名" -Value $filename
            $output | Add-Member -MemberType NoteProperty -Name "作成日" -Value ($fileobject.CreationTime|Get-Date -Format "yyyy-MM-dd HH:mm:ss")  # $fileobject.CreationTimeUtc
            $output | Add-Member -MemberType NoteProperty -Name "サイズ" -Value $fileobject.Length
            $output | Add-Member -MemberType NoteProperty -Name "ハッシュ(sha256)" -Value (Get-FileHash -LiteralPath $filename -Algorithm SHA256).Hash

            $Getfolder = $shell.Namespace($fileobject.DirectoryName)
            $Getfile = $Getfolder.ParseName($fileobject.Name)
            $output | Add-Member -MemberType NoteProperty -Name "タイトル" -Value $Getfile.ExtendedProperty('System.Title')
            $output | Add-Member -MemberType NoteProperty -Name "件名" -Value $Getfile.ExtendedProperty('System.Subject')
            #$output | Add-Member -MemberType NoteProperty -Name "作成者" -Value ([string]$Getfile.ExtendedProperty('System.Author'))
            #  なぜか直接出力すると System.strings になるので、 string に変換
            $tmps=[string]$Getfile.ExtendedProperty('System.Author')
            $output | Add-Member -MemberType NoteProperty -Name "作成者" -Value $tmps
            $output | Add-Member -MemberType NoteProperty -Name "前回保存者" -Value $Getfile.ExtendedProperty('System.Document.LastAuthor')
            $output | Add-Member -MemberType NoteProperty -Name "コンテンツの作成日時" -Value $Getfile.ExtendedProperty('System.Document.DateCreated')
            $output | Add-Member -MemberType NoteProperty -Name "前回保存日時" -Value $Getfile.ExtendedProperty('System.Document.DateSaved')
            $output | Add-Member -MemberType NoteProperty -Name "前回印刷日" -Value $Getfile.ExtendedProperty('System.Document.DatePrinted')
            #$output | Add-Member -MemberType NoteProperty -Name "ファイル所有者" -Value $Getfile.ExtendedProperty('System.FileOwner')
            #$output | Add-Member -MemberType NoteProperty -Name "ファイル作成日時" -Value $Getfile.ExtendedProperty('System.DateCreated')
            #$output | Add-Member -MemberType NoteProperty -Name "ファイル更新日時" -Value $Getfile.ExtendedProperty('System.DateModified')
            #$output | Add-Member -MemberType NoteProperty -Name "ファイルアクセス日時" -Value $Getfile.ExtendedProperty('System.DateAccessed')

            $results+=$output
            $linecount++
            # CSV向け処理 end

            if(($linecount % 1000) -eq 0 ){
                $results | Export-Csv $outputfile -Encoding UTF8 -NoTypeInformation -Append -NoClobber
                $results = @()
            }
        }
    }
    # ディレクトリの検索 end

    $results | Export-Csv $outputfile -Encoding UTF8 -NoTypeInformation -Append -NoClobber
} else {
    Write-Host ("キャンセル") 
}


pause

PowerShellを使ってドロップしたフォルダ内にあるファイル一覧をテキストファイルに保存する

指定したフォルダ内にあるファイルリストを作りたい、という相談を受けた

引数で渡す処理にしてもよかったんだが、簡単に使えるようにするには、ドラック&ドロップ処理でリストが取れるようにした方がいいだろうな、ということで実装した。

また、作成したファイルリストは保存先とファイル名を容易に指定できるようにダイアログを出すようにした。参考にしたのは プログラム★ノートの「PowerShell ファイル保存ダイアログを使用する方法

保存先は基本的にマイドキュメント以下として、ファイル名はドロップしたフォルダ名を使うようにした。

また、作成したPowerShellファイル(ps1)ファイルに直接ドロップしてもうまくいかないので、ショートカットを作成して、リンク先を修正して使用するようにしている。

なお、今回は使用している内容の都合上、Windows OS上でのみ動作することになってるはず。

# ドラッグされたフォルダの中にあるファイル一覧をつくるやつ
#
# 使い方
#  1. このファイルを保存する
#  2. このファイルのショートカットを作成する
#  3. ショートカットのプロパティを開き"リンク先"の項目の先頭に「powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -File 」をつけて保存
#  4. 作成されたショートカットの上に、フォルダをドロップすると、ウィンドウが開いて確認される
#  5. 作成するファイルリストの保存ファイル名を指定する
#  6. 出力される
#
$Args | foreach{
    echo $_.GetType()
    $searchdir = Get-Item -LiteralPath $_
}

Write-Host $searchdir.FullName "のファイル一覧を作成します"
pause

# https://pg-note.com/archives/1144 より
# 必要なアセンブリを読み込む
Add-Type -AssemblyName System.Windows.Forms 
$dialog = New-Object Windows.Forms.SaveFileDialog 

$dialog.Title = "ファイルの保存" 
$dialog.Filter = "テキストファイル(*.txt)|*.txt|csvファイル(*.csv)|*.csv|全てのファイル|*.*" 
$dialog.InitialDirectory = [Environment]::GetFolderPath("MyDocuments")
$dialog.FileName = $searchdir.Name

$ret = $dialog.ShowDialog() 

if ($ret -eq "OK"){
    Write-Host ("保存するファイル名、" + $dialog.FileName) 

    # ディレクトリの検索 start
    Get-ChildItem -Recurse $searchdir | ForEach-Object {
    $filename=$_.FullName
    
        if( !$_.PSIsContainer ){
            Write-Host $filename
            $filename|Out-File -FilePath $dialog.FileName -Append
        }
    }
    # ディレクトリの検索 end
} else {
    Write-Host ("キャンセル") 
}

pause

指定したディレクトリ内にあるexcelファイルに特定の文字列を含むセルがあるかを検索するPowershellスクリプト

たくさんあるexcelファイルのどれに必要な情報が含まれているのかわからないときに、WindowsのPowerShellとExcelアプリを連携させて各セルの中身を検索するスクリプトを作成した。

単純な処理にした場合、excelが保護されている(パスワードあり)ものがあると、スクリプト上でそのexcelファイルを開こうとしたところで、パスワード入力が出てそこで止まってしまう。

そのため、保護されているexcelファイルを効率よく除外する手法はないものか、というのを探したのだが、どうやらPowerShell/Excel連携の機能には、該当するファイルに保護がかかっているかどうかを判定する機能はない模様。

stackoverflowの「Powershell Test for Excel Password Protection」にて解決方法を発見

保護されているexcelファイルというのは、暗号化されたzipファイルで、ヘッダが特定文字列で始まるので、その文字列があれば暗号化されている、と判断して処理を飛ばす、ということが書かれていた。

$sig = [Byte[]] (0x50,0x4b,0x03,0x04)
$bytes = get-content $_.fullname -encoding byte -total 4
if (@(compare-object $sig $bytes -sync 0).length -eq 0) {
  # process unencrypted file
}

これを搭載することで、パスワード入力要求を飛ばすことができた。

で、検索した結果をCSVファイルに保存する処理を付けたものがこちら

CSV出力周りの処理がめんどくさくなってるの「PowerShellで巨大なファイルをGet-Contentし、Export-Csvするのを省メモリで行う」によるもの。これをやらないと速度がだいぶ変わるはず

$excel= New-Object -ComObject Excel.Application
$excel.visible= $false

# 検索対象ディレクトリ
$directory="C:\Users\osakanataro\Documents"

# 検索結果のcsv保存先
$outputfile="c:\tmp\output-tmp.csv"

# 検索キーワード
$keywords="ワード1","ワード2","ワード3"


# CSV出力向けの処理
$results=@()
$linecount=0
#


Get-ChildItem -Recurse $directory -Include *.xlsx,*.xls | ForEach-Object {
    $filename=$_.FullName
    Write-Host "file:", $filename

    # 暗号化チェック簡易版用
    $sig=[Byte[]] (0x50,0x4b,0x03,0x04)
    $bytes= Get-Content -Path $filename -Encoding Byte -TotalCount 4
    if( @(Compare-Object $sig $bytes -Sync 0).Length -eq 0){
        # 暗号化されていないファイルの処理 start
        $workbook=$excel.workbooks.open($filename)
        #Write-Host "ファイル:",$workbook.Name

        $workbook.Sheets|ForEach-Object {
            $worksheet = $_
            #write-host "タブ:", $worksheet.name

            $keywords | ForEach-Object {
                $keyword=$_
                $result1=$worksheet.Cells.Find($keyword)
                while($result1 -ne $null){
                    Write-Host "タブ:",$worksheet.Name," 単語:",$keyword," 場所:",$result1.Column, $result1.row, $result1.text
                    # CSV向け処理 start
                    $output = New-Object -TypeName PSObject
                    $output | Add-Member -MemberType NoteProperty -Name "ファイル名" -Value $filename
                    $output | Add-Member -MemberType NoteProperty -Name "タブ" -Value $worksheet.Name
                    $output | Add-Member -MemberType NoteProperty -Name "単語" -Value $keyword
                    $output | Add-Member -MemberType NoteProperty -Name "Column" -Value $result1.Column
                    $output | Add-Member -MemberType NoteProperty -Name "Row" -Value $result1.row
                    $output | Add-Member -MemberType NoteProperty -Name "文面" -Value $result1.text
                    $results+=$output
                    $linecount++
                    # CSV向け処理 end
                    $result2=$result1
                    $result1=$worksheet.Cells.FindNext($result2)
                    if( $result1.row -le $result2.row ) { $result1=$null }
                }
            }
        }
        # 暗号化されていないファイルの処理 end
    }else{
        # 暗号化されているファイルの処理 start
        Write-Host "   暗号化されている"
        $output = New-Object -TypeName PSObject
        $output | Add-Member -MemberType NoteProperty -Name "ファイル名" -Value $filename
        $output | Add-Member -MemberType NoteProperty -Name "タブ" -Value "パスワード保護につき確認できず"
        $output | Add-Member -MemberType NoteProperty -Name "単語" -Value ""
        $output | Add-Member -MemberType NoteProperty -Name "Column" -Value ""
        $output | Add-Member -MemberType NoteProperty -Name "Row" -Value ""
        $output | Add-Member -MemberType NoteProperty -Name "文面" -Value ""
        $results+=$output
        $linecount++

        # 暗号化されているファイルの処理 end
    }
    if(($linecount % 1000) -eq 0 ){
        $results | Export-Csv $outputfile -Encoding UTF8 -NoTypeInformation -Append -NoClobber
        $results = @()
    }

}

$results | Export-Csv $outputfile -Encoding UTF8 -NoTypeInformation -Append -NoClobber

PowerShellでレポジトリ powershellgallaery v2が見つかりません、が出力されるのはPowerShellGetが古いせい(TLS1.2問題ではない)

Windows11環境のPowerShellで「Update-Module」を実行してみたところ、エラーになった。

PS C:\> update-module
PackageManagement\Install-Package : リポジトリ 'https://www.powershellgallery.com/api/v2/' が見つかりません。利用できる
すべてのリポジトリを確認するには、Get-PSRepository を使用してください。
発生場所 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:2089 文字:20
+ ...           $sid = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex
   ception
    + FullyQualifiedErrorId : SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

PS C:\> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2


PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.22621.2506
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.2506
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS C:\>

TLS1.2を使用する設定になってるのかどうかについては、なっていそう

PS C:\> [Net.ServicePointManager]::SecurityProtocol
Tls12
PS C:\>

事例を調べるとPowerShell Gallaryが止まっている場合もあるらしく「PowerShell Gallery Status」にお知らせが出てないか確認する、というのもあったが、現状は稼働中。

PowerShellGet,PackageManagementはアップデートされているか、については、PackageManagementについては更新されている模様

PS C:\> Get-Module PowerShellGet,PackageManagement -ListAvailable


    ディレクトリ: C:\Users\ユーザー名\Documents\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.4.7      PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...


    ディレクトリ: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     1.0.0.1    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}


PS C:\>

次に、詳細エラーを見てみる

PS C:\> Update-Module -Verbose
詳細: モジュール 'Mailozaurr' の更新プログラムを確認しています。
詳細: リポジトリの詳細、Name = 'PSGallery'、Location = 'https://www.powershellgallery.com/api/v2'、IsTrusted =
'False'、IsRegistered = 'True'。
詳細: Using the provider 'PowerShellGet' for searching packages.
詳細: 指定されたリソース名を使用しています: 'PSGallery'。
詳細: PackageManagement プロバイダー 'NuGet' のプロバイダー オブジェクトを取得しています。
詳細: 指定された Location は 'https://www.powershellgallery.com/api/v2'、PackageManagementProvider は 'NuGet' です。
詳細: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='Mailozaurr'' for ''.
詳細: Total package yield:'1' for the specified package 'Mailozaurr'.
詳細: Skipping installed module Mailozaurr 1.0.2.
詳細: モジュール 'PackageManagement' の更新プログラムを確認しています。
PackageManagement\Install-Package : リポジトリ 'https://www.powershellgallery.com/api/v2/' が見つかりません。利用できる
すべてのリポジトリを確認するには、Get-PSRepository を使用してください。
発生場所 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:2089 文字:20
+ ...           $sid = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex
   ception
    + FullyQualifiedErrorId : SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

PS C:\> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2


PS C:\> Get-PSRepository|select *


Name                      : PSGallery
SourceLocation            : https://www.powershellgallery.com/api/v2
Trusted                   : False
Registered                : True
InstallationPolicy        : Untrusted
PackageManagementProvider : NuGet
PublishLocation           : https://www.powershellgallery.com/api/v2/package/
ScriptSourceLocation      : https://www.powershellgallery.com/api/v2/items/psscript
ScriptPublishLocation     : https://www.powershellgallery.com/api/v2/package/
ProviderOptions           : {}



PS C:\>

PSGallaeryレポジトリにアクセスしようとした時点でエラーになっていそうな感じである。

PowerShell Gallary上のPowerShellGetとPackageManagementの最新バージョンは何か確認してみると、PowerShellGetの方は最新ではないことが判明

PS C:\> Find-Module -Repository PSGallery -Verbose -Name PowerShellGet
詳細: リポジトリの詳細、Name = 'PSGallery'、Location = 'https://www.powershellgallery.com/api/v2'、IsTrusted =
'False'、IsRegistered = 'True'。
詳細: Using the provider 'PowerShellGet' for searching packages.
詳細: 指定されたリソース名を使用しています: 'PSGallery'。
詳細: PackageManagement プロバイダー 'NuGet' のプロバイダー オブジェクトを取得しています。
詳細: 指定された Location は 'https://www.powershellgallery.com/api/v2'、PackageManagementProvider は 'NuGet' です。
詳細: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PowerShellGet'' for ''.
詳細: Total package yield:'1' for the specified package 'PowerShellGet'.

Version    Name                                Repository           Description
-------    ----                                ----------           -----------
2.2.5      PowerShellGet                       PSGallery            PowerShell module with commands for discovering,...


PS C:\> Find-Module -Repository PSGallery -Verbose -Name PackageManagement
詳細: リポジトリの詳細、Name = 'PSGallery'、Location = 'https://www.powershellgallery.com/api/v2'、IsTrusted =
'False'、IsRegistered = 'True'。
詳細: Using the provider 'PowerShellGet' for searching packages.
詳細: 指定されたリソース名を使用しています: 'PSGallery'。
詳細: PackageManagement プロバイダー 'NuGet' のプロバイダー オブジェクトを取得しています。
詳細: 指定された Location は 'https://www.powershellgallery.com/api/v2'、PackageManagementProvider は 'NuGet' です。
詳細: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PackageManagement'' for ''.
詳細: Total package yield:'1' for the specified package 'PackageManagement'.

Version    Name                                Repository           Description
-------    ----                                ----------           -----------
1.4.8.1    PackageManagement                   PSGallery            PackageManagement (a.k.a. OneGet) is a new way t...


PS C:\>

最新版のPowerShellGetをインストールする手法については「PowerShellGet と PSResourceGet をインストールする方法」に記載がある「Install-Module PowerShellGet -Force -AllowClobber」を実行した。

PS C:\> Install-Module PowerShellGet -Force -AllowClobber
PS C:\>

(注:上記ログに出ていないが、別表示としてprogress表示があります)

ちなみにallowclobberオプションを付けない場合、下記のようなエラーになった。

PS C:\> Install-Module PowerShellGet -force
PackageManagement\Install-Package : 以下のコマンドは、このシステムで既に使用可能になっています: 'Find-Package,Install-P
ackage,Uninstall-Package'。このモジュール 'PackageManagement' では既存のコマンドが上書きされる可能性があります。このモ
ジュール 'PackageManagement' をインストールする場合は、-AllowClobber パラメーターを使用してください。
発生場所 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 文字:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package]、E
    xception
    + FullyQualifiedErrorId : CommandAlreadyAvailable,Validate-ModuleCommandAlreadyAvailable,Microsoft.PowerShell.Pack
   ageManagement.Cmdlets.InstallPackage

PS C:\>

PowerShellGet更新後は「Update-Module」を実行してもエラーとはならなくなった。

PS C:\> Update-Module
PS C:\>