首页 > 解决方案 > 如何解决 conda 不可写路径的问题?

问题描述

为什么我在使用 conda 时会看到以下错误(通常是在安装软件包或制作新环境时)以及如何修复它:

Verifying transaction: | WARNING conda.core.path_actions:verify(963): Unable to create environments file. Path not writable.
  environment location: /Users/brandomiranda/.conda/environments.txt

或者

Preparing transaction: done
Verifying transaction: - WARNING conda.core.path_actions:verify(963): Unable to create environments file. Path not writable.
  environment location: /Users/brandomiranda/.conda/environments.txt

done
Executing transaction: - WARNING conda.core.envs_manager:register_env(52): Unable to register environment. Path not writable or missing.
  environment location: /Users/brandomiranda/miniconda3/envs/myenv
  registry file: /Users/brandomiranda/.conda/environments.txt
done

可以在以下 gitissue 上找到我所做工作的详细概述:

https://github.com/conda/conda/issues/7267

除了从头开始重新安装 conda 并运行以下命令之外,这真的没什么太花哨的:

bash Miniconda3-latest-MacOSX-x86_64.sh

它安装了这个版本的conda:

❯ conda -V
conda 4.7.12

导致我警告的命令示例:

conda create -n myenv python=3.6

使用 conda 安装软件包时出现更多错误:

Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Users/brandomiranda/miniconda3/envs/automl

  added / updated specs:
    - jupyterlab


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    jupyter_client-5.3.4       |           py37_0         131 KB  conda-forge
    ------------------------------------------------------------
                                           Total:         131 KB

The following NEW packages will be INSTALLED:

  appnope            conda-forge/osx-64::appnope-0.1.0-py37_1000
  attrs              conda-forge/noarch::attrs-19.3.0-py_0
  backcall           conda-forge/noarch::backcall-0.1.0-py_0
  bleach             conda-forge/noarch::bleach-3.1.0-py_0
  decorator          conda-forge/noarch::decorator-4.4.1-py_0
  defusedxml         conda-forge/noarch::defusedxml-0.6.0-py_0
  entrypoints        conda-forge/osx-64::entrypoints-0.3-py37_1000
  importlib_metadata conda-forge/osx-64::importlib_metadata-1.3.0-py37_0
  ipykernel          conda-forge/osx-64::ipykernel-5.1.3-py37h5ca1d4c_0
  ipython            conda-forge/osx-64::ipython-7.11.1-py37h5ca1d4c_0
  ipython_genutils   conda-forge/noarch::ipython_genutils-0.2.0-py_1
  jedi               conda-forge/osx-64::jedi-0.15.2-py37_0
  jinja2             conda-forge/noarch::jinja2-2.10.3-py_0
  json5              conda-forge/noarch::json5-0.8.5-py_0
  jsonschema         conda-forge/osx-64::jsonschema-3.2.0-py37_0
  jupyter_client     conda-forge/osx-64::jupyter_client-5.3.4-py37_0
  jupyter_core       conda-forge/osx-64::jupyter_core-4.6.1-py37_0
  jupyterlab         conda-forge/noarch::jupyterlab-1.2.4-py_0
  jupyterlab_server  conda-forge/noarch::jupyterlab_server-1.0.6-py_0
  libsodium          conda-forge/osx-64::libsodium-1.0.17-h01d97ff_0
  markupsafe         conda-forge/osx-64::markupsafe-1.1.1-py37h0b31af3_0
  mistune            conda-forge/osx-64::mistune-0.8.4-py37h0b31af3_1000
  more-itertools     conda-forge/noarch::more-itertools-8.0.2-py_0
  nbconvert          conda-forge/osx-64::nbconvert-5.6.1-py37_0
  nbformat           conda-forge/noarch::nbformat-5.0.3-py_0
  notebook           conda-forge/osx-64::notebook-6.0.1-py37_0
  pandoc             conda-forge/osx-64::pandoc-2.9.1.1-0
  pandocfilters      conda-forge/noarch::pandocfilters-1.4.2-py_1
  parso              conda-forge/noarch::parso-0.5.2-py_0
  pexpect            conda-forge/osx-64::pexpect-4.7.0-py37_0
  pickleshare        conda-forge/osx-64::pickleshare-0.7.5-py37_1000
  prometheus_client  conda-forge/noarch::prometheus_client-0.7.1-py_0
  prompt_toolkit     conda-forge/noarch::prompt_toolkit-3.0.2-py_0
  ptyprocess         conda-forge/noarch::ptyprocess-0.6.0-py_1001
  pygments           conda-forge/noarch::pygments-2.5.2-py_0
  pyrsistent         conda-forge/osx-64::pyrsistent-0.15.7-py37h0b31af3_0
  python-dateutil    conda-forge/noarch::python-dateutil-2.8.1-py_0
  pyzmq              pkgs/main/osx-64::pyzmq-18.1.0-py37h0a44026_0
  send2trash         conda-forge/noarch::send2trash-1.5.0-py_0
  terminado          conda-forge/osx-64::terminado-0.8.3-py37_0
  testpath           conda-forge/noarch::testpath-0.4.4-py_0
  tornado            conda-forge/osx-64::tornado-6.0.3-py37h0b31af3_0
  traitlets          conda-forge/osx-64::traitlets-4.3.3-py37_0
  wcwidth            conda-forge/noarch::wcwidth-0.1.8-py_0
  webencodings       conda-forge/noarch::webencodings-0.5.1-py_1
  zeromq             conda-forge/osx-64::zeromq-4.3.2-h6de7cb9_2
  zipp               conda-forge/noarch::zipp-0.6.0-py_0

The following packages will be UPDATED:

  ca-certificates    pkgs/main::ca-certificates-2019.11.27~ --> conda-forge::ca-certificates-2019.11.28-hecc5488_0

The following packages will be SUPERSEDED by a higher-priority channel:

  certifi                                         pkgs/main --> conda-forge
  openssl              pkgs/main::openssl-1.1.1d-h1de35cc_3 --> conda-forge::openssl-1.1.1d-h0b31af3_0



Proceed ([y]/n)? y


Downloading and Extracting Packages
jupyter_client-5.3.4 | 131 KB    | ################################################################################################################################################################# | 100%
Preparing transaction: done
Verifying transaction: | WARNING conda.core.path_actions:verify(963): Unable to create environments file. Path not writable.
  environment location: /Users/brandomiranda/.conda/environments.txt

done
Executing transaction: - WARNING conda.core.envs_manager:register_env(52): Unable to register environment. Path not writable or missing.
  environment location: /Users/brandomiranda/miniconda3/envs/automl
  registry file: /Users/brandomiranda/.conda/environments.txt
done

我运行的命令:

(automl) brandomiranda~/automl-meta-learning ❯ conda install -c conda-forge jupyterlab

我尝试根据建议的答案更改权限,但似乎没有 sudo 它将无法工作。在这里做 sudo 真的安全吗?为什么它不能写给正确的用户集?

(automl) brandomiranda~/.conda ❯ if [ -w "/Users/brandomiranda/.conda" ]; then echo "WRITABLE"; else echo "NOT WRITABLE"; fi
NOT WRITABLE
(automl) brandomiranda~/.conda ❯ chmod 775 /Users/brandomiranda/.conda
chmod: Unable to change file mode on /Users/brandomiranda/.conda: Operation not permitted

运行建议的答案后更新

我已经在 sudo 中运行了 chmod 命令。我检查了该文件的权限,得到以下信息:

(automl-meta-learning) brandomiranda~/automl-meta-learning/automl/automl ❯ ls -lha /Users/brandomiranda/.conda                                                        
total 8
drwxrwxr-x    3 root           staff    96B Jan  5 16:57 .
drwxr-xr-x+ 117 brandomiranda  staff   3.7K Jan 19 17:25 ..
-rw-r--r--    1 root           staff    32B Jan  5 16:57 environments.txt

我检查了这一点,因为我尝试conda-build使用conda install conda-build命令安装,但最后出现错误:

Preparing transaction: done
Verifying transaction: \ WARNING conda.core.path_actions:verify(963): Unable to create environments file. Path not writable.
  environment location: /Users/brandomiranda/.conda/environments.txt
                                                                                                                                                                                                                                                                       done
Executing transaction: \ WARNING conda.core.envs_manager:register_env(52): Unable to register environment. Path not writable or missing.
  environment location: /Users/brandomiranda/miniconda3/envs/automl-meta-learning
  registry file: /Users/brandomiranda/.conda/environments.txt                                                                                                                                                                                                          done

这看起来很奇怪,当我注意到environment.txt没有与其他文件/目录相同的权限时。我也很想对那个文件进行 chmod,但所有这些业务似乎都在给这个问题贴上绷带。我觉得这首先不应该发生,所以我会问:

现在我将运行:

sudo chmod 775 /Users/brandomiranda/.conda/environments.txt

sudo虽然,我不得不为与 conda 相关的东西而奔波,这让我感到不安。任何人都知道如何在不需要 sudo 的情况下执行此操作,或者应该需要 sudo 吗?

作为旁注,我很高兴我从未尝试使用 sudo 从 conda 安装任何东西,并且只更改了几个文件夹/文件的权限。这似乎比允许 conda 在 sudo 中运行任意代码更安全(而不是在这里它可以将其内容运行到特定位置而不在 sudo 中运行,所以我猜更改文件夹权限不是那么糟糕?)。

标签: pythonanacondaconda

解决方案


参考:至https://gist.github.com/zoka123/f2b03f19924258d28441fe2d88750145

检查路径是否可写:

if [ -w "./.conda" ]; then echo "WRITABLE"; else echo "NOT WRITABLE"; fi

如果它不可写,请将可写性更改为任何人:

chmod 775 ./.conda

如果您对现有的文件权限感到好奇:

ls -lha输出当前位置的访问权限集合,这里d指的是当前目录。例如drwxr-xr-x

每个数字分别代表用户、组和全局的权限。对于上面的例子, rwx表示当前用户可以读、写和执行;r-x对于组和全局,这意味着它们只能读取和执行。

chmod与 3 位指令一起使用,每个位指的是read, write, execute对上述三种身份的访问的一种组合。

755表示rwx当前用户、r-x组和全局。

您可以参考https://www.linode.com/docs/tools-reference/tools/modify-file-permissions-with-chmod/以供参考。


推荐阅读