错误 13 权限被拒绝.已经在虚拟环境中

问题描述:

我正在尝试在操作系统更新后安装 tensorflow.我收到 [Errno 13] 权限被拒绝.我检查过的所有论坛帖子都建议使用虚拟环境解决这个问题.问题是我已经在虚拟环境中工作了.

I'm trying to install tensorflow after an OS update. I'm getting an [Errno 13] Permission denied. All the forum posts I've checked recommend solving this using a virtual environment. Problem is I'm already working in a virtual environment.

这是我使用的命令:

user@Computer:~$ cd /tensorflow
user@Computer:/tensorflow$ virtualenv --system-site-packages -p python3 venv
user@Computer:/tensorflow$ source /tensorflow/venv/bin/activate
(venv) user@Computer:/tensorflow$ pip install -U tensorflow-GPU

这是我得到的输出:

(venv) user@Computer:/tensorflow$ pip install -U tensorflow-GPU
Using cached https://files.pythonhosted.org/packages/64/ca/830b7cedb073ae264d215d51bd18d7cff7a2a47e39d79f6fa23edae17bb2/tensorflow_gpu-1.10.0-cp36-cp36m-manylinux1_x86_64.whl
Collecting gast>=0.2.0 (from tensorflow-GPU)
Collecting tensorboard<1.11.0,>=1.10.0 (from tensorflow-GPU)
  Using cached https://files.pythonhosted.org/packages/c6/17/ecd918a004f297955c30b4fffbea100b1606c225dbf0443264012773c3ff/tensorboard-1.10.0-py3-none-any.whl
Collecting grpcio>=1.8.6 (from tensorflow-GPU)
  Using cached https://files.pythonhosted.org/packages/31/17/0f79ff2f56018aa0e12ffb1cc8086df6bd6cfc71efea0df64fe78d569f71/grpcio-1.14.1-cp36-cp36m-manylinux1_x86_64.whl
Requirement already satisfied, skipping upgrade: six>=1.10.0 in /usr/lib/python3/dist-packages (from tensorflow-GPU) (1.11.0)
Collecting astor>=0.6.0 (from tensorflow-GPU)
  Using cached https://files.pythonhosted.org/packages/35/6b/11530768cac581a12952a2aad00e1526b89d242d0b9f59534ef6e6a1752f/astor-0.7.1-py2.py3-none-any.whl
Collecting protobuf>=3.6.0 (from tensorflow-GPU)
  Using cached https://files.pythonhosted.org/packages/fc/f0/db040681187496d10ac50ad167a8fd5f953d115b16a7085e19193a6abfd2/protobuf-3.6.0-cp36-cp36m-manylinux1_x86_64.whl
Requirement already satisfied, skipping upgrade: wheel>=0.26 in ./venv/lib/python3.6/site-packages (from tensorflow-GPU) (0.31.1)
Collecting absl-py>=0.1.6 (from tensorflow-GPU)
Collecting termcolor>=1.1.0 (from tensorflow-GPU)
Collecting setuptools<=39.1.0 (from tensorflow-GPU)
  Using cached https://files.pythonhosted.org/packages/8c/10/79282747f9169f21c053c562a0baa21815a8c7879be97abd930dbcf862e8/setuptools-39.1.0-py2.py3-none-any.whl
Collecting numpy<=1.14.5,>=1.13.3 (from tensorflow-GPU)
  Using cached https://files.pythonhosted.org/packages/68/1e/116ad560de97694e2d0c1843a7a0075cc9f49e922454d32f49a80eb6f1f2/numpy-1.14.5-cp36-cp36m-manylinux1_x86_64.whl
Collecting markdown>=2.6.8 (from tensorboard<1.11.0,>=1.10.0->tensorflow-GPU)
  Using cached https://files.pythonhosted.org/packages/6d/7d/488b90f470b96531a3f5788cf12a93332f543dbab13c423a5e7ce96a0493/Markdown-2.6.11-py2.py3-none-any.whl
Collecting werkzeug>=0.11.10 (from tensorboard<1.11.0,>=1.10.0->tensorflow-GPU)
  Using cached https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl
Installing collected packages: gast, numpy, markdown, setuptools, protobuf, werkzeug, tensorboard, grpcio, astor, absl-py, termcolor, tensorflow-GPU
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/tensorflow/venv/lib/python3.6/site-packages/gast'
Consider using the `--user` option or check the permissions.

包含 '--user' 选项会产生以下结果

Including the '--user' option gives the following result

(venv) user@Computer:/tensorflow$ pip install --user tensorflow-GPU
Collecting tensorflow-GPU
  Using cached https://files.pythonhosted.org/packages/64/ca/830b7cedb073ae264d215d51bd18d7cff7a2a47e39d79f6fa23edae17bb2/tensorflow_gpu-1.10.0-cp36-cp36m-manylinux1_x86_64.whl
Collecting absl-py>=0.1.6 (from tensorflow-GPU)
Collecting astor>=0.6.0 (from tensorflow-GPU)
  Using cached https://files.pythonhosted.org/packages/35/6b/11530768cac581a12952a2aad00e1526b89d242d0b9f59534ef6e6a1752f/astor-0.7.1-py2.py3-none-any.whl
Collecting gast>=0.2.0 (from tensorflow-GPU)
Collecting tensorboard<1.11.0,>=1.10.0 (from tensorflow-GPU)
  Using cached https://files.pythonhosted.org/packages/c6/17/ecd918a004f297955c30b4fffbea100b1606c225dbf0443264012773c3ff/tensorboard-1.10.0-py3-none-any.whl
Collecting termcolor>=1.1.0 (from tensorflow-GPU)
Collecting numpy<=1.14.5,>=1.13.3 (from tensorflow-GPU)
  Using cached https://files.pythonhosted.org/packages/68/1e/116ad560de97694e2d0c1843a7a0075cc9f49e922454d32f49a80eb6f1f2/numpy-1.14.5-cp36-cp36m-manylinux1_x86_64.whl
Will not install to the user site because it will lack sys.path precedence to setuptools in /tensorflow/venv/lib/python3.6/site-packages

我做了更多的挖掘.

显然 virtualenv 是使用 sudo 创建的,所以我需要更改权限.

Apparently the virtualenv was created using sudo so I needed to alter permissions.

详情请见:如何避免权限被拒绝"使用 pip 和 virtualenv 时

具体来说是

sudo chown -R your_username:your_username path/to/virtuaelenv/