前提
はじめまして。PC初心者です。ターミナルでの言語や基本的な操作がわかっていないので、コマンドを調べながら操作している状態です。普段はanacondaを使用しているのですがvenvの仮想環境を作ってみたいと思い、
sudo pip3 install virtualenv
でvirtualenvの20.16.6をインストールいたしました。
このvirtualenvを削除しようと
pip3 uninstall virtualenv
を入力し
Found existing installation: virtualenv 20.16.6
と表示されました。
Would remove: /Library/Python/3.9/site-packages/virtualenv-20.16.6.dist-info/* /Library/Python/3.9/site-packages/virtualenv/* /usr/local/bin/virtualenv Proceed (Y/n)? y
でyを押したところ、以下のようなエラーが発生し削除することができませんでした。
実現したいこと
以下のエラーを解消し、virtualenvをアンインストールする
発生している問題・エラーメッセージ
以下のようなエラーが表示されてしまいました。
ERROR: Exception: Traceback (most recent call last): File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/shutil.py", line 806, in move os.rename(src, real_dst) PermissionError: [Errno 13] Permission denied: '/Library/Python/3.9/site-packages/virtualenv-20.16.6.dist-info/' -> '/private/var/folders/m2/zczpxzpj2msfwzly99jl5lnc0000gn/T/pip-uninstall-51rh_qb2' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 173, in _main status = self.run(options, args) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages/pip/_internal/commands/uninstall.py", line 93, in run uninstall_pathset = req.uninstall( File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages/pip/_internal/req/req_install.py", line 633, in uninstall uninstalled_pathset.remove(auto_confirm, verbose) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages/pip/_internal/req/req_uninstall.py", line 384, in remove moved.stash(path) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages/pip/_internal/req/req_uninstall.py", line 281, in stash renames(path, new_path) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages/pip/_internal/utils/misc.py", line 331, in renames shutil.move(old, new) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/shutil.py", line 819, in move raise PermissionError("Cannot move the non-empty directory " PermissionError: Cannot move the non-empty directory '/Library/Python/3.9/site-packages/virtualenv-20.16.6.dist-info/': Lacking write permission to '/Library/Python/3.9/site-packages/virtualenv-20.16.6.dist-info/'.
試したこと
conda uninstall virtualenv
では
Collecting package metadata (repodata.json): done Solving environment: failed PackagesNotFoundError: The following packages are missing from the target environment: - virtualenv
となりました。
sudo pip3 uninstall virtualenv
では、こちらのような警告文が表示され削除できませんでした。
WARNING: The directory '/Users/******/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag. WARNING: Skipping virtualenv as it is not installed. WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
上記エラー文で下の方に表示されている、以下の部分が問題なのではないかと考えたのですが、この部分に対しどのような対応をすればよろしいでしょうか。(アンインストールでいない原因に関係がないようでしたらすみません、無視してください。)
https://qiita.com/darianus/items/c30f755e6f51e79a3a01
こちら参考にさせていただいたのですが、初心者で削除等の操作に対して自信がないので対応する際に使用するコードについても併せて教えていただけると非常にありがたいです。
PermissionError: Cannot move the non-empty directory '/Library/Python/3.9/site-packages/virtualenv-20.16.6.dist-info/': Lacking write permission to '/Library/Python/3.9/site-packages/virtualenv-20.16.6.dist-info/'.
追記:
which virtualenv
では、
/usr/local/bin/virtualenv
と表示されました。
補足情報(FW/ツールのバージョンなど)
macOS Montereyのバージョン12.6を使用しております。
ターミナルで確認したバージョンはPython 3.7.3です。

回答1件
あなたの回答
tips
プレビュー