文系男子が日和るIT開発~IT知識なしで飛び込んだIT企業

文系男子だからIT企業に就職するなんて考えてもみませんでしたが、日和ながら日々くらいついています。

Python ... ERROR: Could not install packages due to an EnvironmentError: [WinError 5] アクセスが拒否されました

Pythonでpipのアップグレードを行った際に、アクセス権限がないことによりインストールできない旨のエラーが発生しました。
エラーメッセージは以下。

ERROR: Could not install packages due to an EnvironmentError: [WinError 5] アクセスが拒否されました。: 'c:\\python39\\Lib\\site-packages\\pip\\__init__.py'
Consider using the `--user` option or check the permissions.

WARNING: You are using pip version 20.3.3; however, version 22.3.1 is available.
You should consider upgrading via the 'c:\python39\python.exe -m pip install --upgrade pip' command.

対処法ですが、
「--user」を付けることにより回避できるようです。
c:\python39\python.exe -m pip install --upgrade pip --user

実行結果は以下の通りで、「--user」を付加して実行することで無事エラー回避でき、pipのアップグレードが成功しました。

C:\Users\xxxxx\python_work>c:\python39\python.exe -m pip install --upgrade pip --user
Requirement already satisfied: pip in c:\users\xxxxx\appdata\roaming\python\python39\site-packages (20.3.3)
Collecting pip
Using cached pip-22.3.1-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.3.3
Uninstalling pip-20.3.3:
Successfully uninstalled pip-20.3.3
WARNING: The scripts pip.exe, pip3.10.exe, pip3.9.exe and pip3.exe are installed in 'C:\Users\xxxxx\AppData\Roaming\Python\Python39\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-22.3.1