python - 如何解决 conda 不可写路径的问题?

标签 python anaconda 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-buildconda 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,但所有这些业务似乎都在给这个问题贴上绷带。我觉得这首先不应该发生,所以我会问:
  • 我们如何正确解决这个问题?
  • 假设如何安装 conda(在新的 Catalina OS for Mac 中使用 zsh)?
  • 无论如何,/Users/brandomiranda/.conda 的权限是什么? conda 文件夹应该是并且所有文件夹/文件都应该具有相同的权限吗?

  • 现在我将运行:
    sudo chmod 775 /Users/brandomiranda/.conda/environments.txt
    
    不过,我不得不运行 sudo 让我感到不安对于 conda 相关的东西。任何人都知道如何在不需要 sudo 的情况下执行此操作,或者应该需要 sudo 吗?
    作为旁注,我很高兴我从未尝试使用 sudo 从 conda 安装任何东西,并且只更改了几个文件夹/文件的权限。这似乎比允许 conda 在 sudo 中运行任意代码更安全(相反,它可以将其内容运行到特定位置而不在 sudo 中运行,所以我猜更改文件夹权限不是那么糟糕?)。

    最佳答案

    作为替代解决方案,我更改了 业主 ~/.conda给我自己:

    $ chown -R $USER ~/.conda
    

    我认为问题的根本原因(至少在我的情况下)是 ~/.condaroot 所有由于某些原因。其他解决方案建议将其访问权限设置为更宽松(向组甚至所有人开放写入)作为一种解决方法。虽然从技术上讲这应该可行,但我认为更改所有者(并保留现有权限)是一种更安全的方法。

    关于python - 如何解决 conda 不可写路径的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59619442/

    相关文章:

    python - 为什么不能用另一个函数替换 Python 对象的 __str__ 方法?

    php - 如何在php-fpm shell_exec中激活anaconda环境?

    python - 在 conda 环境(运行 Python 3.8)中安装 rpy2 3.3.2 的最佳方法是什么?

    python - 在新的 conda 环境中使用 requirements.txt 从 conda channel 和 pip 自动安装包

    python - 通过 ENTRYPOINT 在 Docker 中采购 .bashrc

    配置:错误:找不到 CGAL 库

    python - 在 Mac 上安装 PyDrive

    python - wxpython:我将如何配置一个 box sizer 以便它有一个中心列在调整大小时移动,但不会改变尺寸(里面的图片解释)

    python - DisabledFunctionError : cv2. imshow() 在 Colab 中被禁用,因为它会导致 Jupyter session 崩溃

    python - 我可以在 Mac OS X 上的哪里保存 Python 开发的 GUI 应用程序的 sqlite 数据库?