首页 > 解决方案 > Anaconda Sudo PIP 权限问题

问题描述

我正在学习 Python 并安装了 Anaconda,我正在尝试让自己熟悉让Eye-Color Detection 项目正常工作的过程。阅读自述文件后,我遇到了以下错误:

Eye-Color-Detection git:(master) ✗ sudo pip install -r requirements.txt

WARNING: The directory '/Users/{user}/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 may want sudo's -H flag.

尝试更新时:

(tweet) ➜ Eye-Color-Detection git:(master) ✗ conda update --all

[Errno 13] Permission denied: '/Users/{user}/opt/anaconda3/envs/tweet/lib/python3.8/site-packages/wrapt/__init__.py' -> '/Users/{user}/opt/anaconda3/envs/tweet/lib/python3.8/site-packages/wrapt/__init__.py.c~'

问:我如何才能在同一个 Conda 环境中正确执行此操作?

标签: pythonanaconda

解决方案


大多数时候,asudo pip install几乎从来都不是你真正想要的。虽然在某些情况下,它可能会“看起来”起作用并解决您的直接问题。通常,您只是在不知情的情况下破坏了系统 python。

在那个 repo 的上下文中,我会忽略 repo 的 README 并这样做。

$ git clone https://github.com/ghimiredhikura/Eye-Color-Detection
$ cd Eye-Color-Detection

创建一个virtualenv环境,随心所欲地改变yourenvname

$ conda create -n yourenvname python=3.x
$ conda activate yourenvname

安装依赖并运行代码

$ pip install -r requirements.txt
$ python3 eye-color.py --input_path=sample/2.jpg --input_type=ima

由于修复您的 conda 环境可能难以调试,具体取决于您sudo尝试解决问题的其他方法。如果你碰巧熟悉使用 python 的内置虚拟环境工具创建的“常规”virtualenv,那么你也可以试试这个来帮助你。

$ python3 -m venv .venv --copies
$ source .venv/bin/active

$ pip install -r requirements.txt

$ python3 eye-color.py --input_path=sample/2.jpg --input_type=image

推荐阅读