ModuleNotFoundError:重置基本环境后,没有名为“ conda”的模块

时间:2019-12-09 20:58:24

标签: python anaconda conda environment

我非常喜欢base的conda环境。我不小心在此环境中安装了一堆软件包,因此尝试删除它们:

我按照conda: remove all installed packages from base/root environment的建议运行了以下命令: conda install --revision 0 -n base

但是,当我运行以下脚本来重新安装必备软件时:

conda install -c conda-forge wget rsync pv ipython jupyter jupyterlab pandas numpy biopython r-recommended python=3 -y

conda install -c bioconda pullseq samtools bbmap hmmer ncbi-genome-download -y

它坏了,我什至无法访问我的conda

-bash-4.1$ which conda
/usr/local/devel/ANNOTATION/jespinoz/anaconda3/condabin/conda
-bash-4.1$ conda -h
Traceback (most recent call last):
  File "/usr/local/devel/ANNOTATION/jespinoz/anaconda3/bin/conda", line 12, in <module>
    from conda.cli import main
ModuleNotFoundError: No module named 'conda'

一些帖子建议它与我的PYTHONPATHPYTHONHOME环境变量有关,但是我没有设置这些变量:

-bash-4.1$ echo $PYTHONHOME

-bash-4.1$ echo $PYTHONPATH

我认为这是因为我的默认python版本现在是3.8,而没有安装conda。但是,3.7确实安装了conda。

-bash-4.1$ ls -l /usr/local/devel/ANNOTATION/jespinoz/anaconda3/lib/python3.8/site-packages/  | grep "conda"
-bash-4.1$ ls -l /usr/local/devel/ANNOTATION/jespinoz/anaconda3/lib/python3.7/site-packages/  | grep "conda"
drwxr-xr-x  2 jespinoz tigr     218 Dec  9 14:49 anaconda_client-1.7.2-py3.7.egg-info
drwxr-xr-x 10 jespinoz tigr     253 Jun 25 13:28 anaconda_navigator
drwxr-xr-x  2 jespinoz tigr     158 Jun 25 13:28 anaconda_navigator-1.9.7-py3.7.egg-info
drwxr-xr-x  6 jespinoz tigr     743 Dec  9 14:51 anaconda_project
drwxr-xr-x  2 jespinoz tigr     218 Dec  9 14:49 anaconda_project-0.8.2-py3.7.egg-info
drwxr-xr-x 11 jespinoz tigr     657 Dec  9 14:51 conda
drwxr-xr-x  2 jespinoz tigr     218 Dec  9 14:49 conda-4.6.11-py3.7.egg-info
drwxr-xr-x  7 jespinoz tigr    1012 Dec  9 14:51 conda_build
drwxr-xr-x  2 jespinoz tigr     218 Dec  9 14:49 conda_build-3.17.8-py3.7.egg-info
drwxr-xr-x  6 jespinoz tigr     295 Dec  9 14:51 conda_env
drwxr-xr-x  2 jespinoz tigr       0 Dec  9 14:59 conda_package_handling
drwxr-xr-x  3 jespinoz tigr     281 Dec  9 14:53 conda_verify
drwxr-xr-x  2 jespinoz tigr     188 Dec  9 14:49 conda_verify-3.1.1-py3.7.egg-info

我可以利用它来修复损坏的设置吗?

我几乎可以正常工作:

首先将conda二进制文件从python3.7站点软件包符号链接到3.8

-bash-4.1$ ln -s /usr/local/devel/ANNOTATION/jespinoz/anaconda3/lib/python3.7/site-packages/cond* /usr/local/devel/ANNOTATION/jespinoz/anaconda3/lib/python3.8/site-packages/

当您尝试还原python3.7时不起作用:

-bash-4.1$ conda install python=3.7
Traceback (most recent call last):
  File "/usr/local/devel/ANNOTATION/jespinoz/anaconda3/lib/python3.8/site-packages/conda/common/serialize.py", line 19, in get_yaml
    import ruamel_yaml as yaml
ModuleNotFoundError: No module named 'ruamel_yaml'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/devel/ANNOTATION/jespinoz/anaconda3/lib/python3.8/site-packages/conda/common/serialize.py", line 22, in get_yaml
    import ruamel.yaml as yaml
ModuleNotFoundError: No module named 'ruamel'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/devel/ANNOTATION/jespinoz/anaconda3/lib/python3.8/site-packages/conda/exceptions.py", line 1003, in __call__
    return func(*args, **kwargs)
  File "/usr/local/devel/ANNOTATION/jespinoz/anaconda3/lib/python3.8/site-packages/conda/cli/main.py", line 74, in _main
    from ..base.context import context
  File "/usr/local/devel/ANNOTATION/jespinoz/anaconda3/lib/python3.8/site-packages/conda/base/context.py", line 28, in <module>
    from ..common.configuration import (Configuration, ConfigurationLoadError, MapParameter,
  File "/usr/local/devel/ANNOTATION/jespinoz/anaconda3/lib/python3.8/site-packages/conda/common/configuration.py", line 40, in <module>
    from .serialize import yaml_load
  File "/usr/local/devel/ANNOTATION/jespinoz/anaconda3/lib/python3.8/site-packages/conda/common/serialize.py", line 30, in <module>
    yaml = get_yaml()
  File "/usr/local/devel/ANNOTATION/jespinoz/anaconda3/lib/python3.8/site-packages/conda/_vendor/auxlib/decorators.py", line 59, in _memoized_func
    result = func(*args, **kwargs)
  File "/usr/local/devel/ANNOTATION/jespinoz/anaconda3/lib/python3.8/site-packages/conda/common/serialize.py", line 24, in get_yaml
    raise ImportError("No yaml library available.\n"
ImportError: No yaml library available.
To proceed, conda install ruamel_yaml

当然,您不能真正做conda install ruamel_yaml,因为那太简单了。而是使用pip

-bash-4.1$ pip install ruamel_yaml
Collecting ruamel_yaml
  Downloading https://files.pythonhosted.org/packages/fa/90/ecff85a2e9c497e2fa7142496e10233556b5137db5bd46f3f3b006935ca8/ruamel.yaml-0.16.5-py2.py3-none-any.whl (123kB)
     |████████████████████████████████| 133kB 8.8MB/s
ERROR: conda 4.6.11 requires pycosat>=0.6.3, which is not installed.
ERROR: conda 4.6.11 requires requests>=2.12.4, which is not installed.
ERROR: conda-build 3.17.8 requires beautifulsoup4, which is not installed.
ERROR: conda-build 3.17.8 requires chardet, which is not installed.
ERROR: conda-build 3.17.8 requires filelock, which is not installed.
ERROR: conda-build 3.17.8 requires libarchive-c, which is not installed.
ERROR: conda-build 3.17.8 requires lief, which is not installed.
ERROR: conda-build 3.17.8 requires pkginfo, which is not installed.
ERROR: conda-build 3.17.8 requires psutil, which is not installed.
ERROR: conda-build 3.17.8 requires pyyaml, which is not installed.
ERROR: conda-build 3.17.8 requires requests, which is not installed.
ERROR: conda-build 3.17.8 requires tqdm, which is not installed.
Installing collected packages: ruamel-yaml

然后我尝试了以下操作:

-bash-4.1$ conda install python=3.7 -n base
WARNING: The conda.compat module is deprecated and will be removed in a future release.
Collecting package metadata: done
Solving environment: - WARNING conda.common.logic:get_sat_solver_cls(278): Could not run SAT solver through interface 'pycosat'.
failed

CondaDependencyError: Cannot run solver. No functioning SAT implementations available.

1 个答案:

答案 0 :(得分:0)

我修复了它。我尝试下载最新的安装,然后运行-u进行升级(这花了很多时间),但是没有用。

我最终要做的是使用我的同事安装的conda:

source /path/to/their/conda/activate /path/to/my/anaconda3

然后,我设置了~/.condarc,以便它知道我的pkg和环境应位于何处(主目录中的空间有限,如果不执行此操作,则会崩溃)

(/usr/local/devel/ANNOTATION/jespinoz/anaconda3) -bash-4.1$ cat ~/.condarc
channels:
  - bioconda
  - conda-forge
  - defaults
  - etetoolkit
  - r
channel_priority: true
report_errors: true

envs_dirs:
  - /usr/local/devel/ANNOTATION/jespinoz/anaconda3/envs/

pkgs_dirs:
  - /usr/local/devel/ANNOTATION/jespinoz/anaconda3/pkgs/

之后,我执行了以下操作:

conda install python=3.7 -y

但是,我收到以下错误/警告:

Executing transaction: / Traceback (most recent call last):
  File "/usr/local/devel/ANNOTATION/jespinoz/anaconda3/bin/jupyter-nbextension", line 7, in <module>
    from notebook.nbextensions import main
ModuleNotFoundError: No module named 'notebook'

WARNING conda.core.link:run_script(1098): pre-unlink script failed for package conda-forge::widgetsnbextension-3.5.1-py38_0
consider notifying the package maintainer
| Enabling notebook extension jupyter-js-widgets/extension...
      - Validating: OK

终于可以使用了。

现在,由于所有软件包冲突,我正在运行conda update --all。希望它不会再次破坏我的环境...