使用conda报错:from conda.cli import main ModuleNotFoundError: No module named conda

使用conda报错:from conda.cli import main ModuleNotFoundError: No module named 'conda'

文章目录:

1 错误出现原因

出现ModuleNotFoundError: No module named 'conda'错误一般都是由于在使用conda进行环境安装的时候,改变了原先python的版本,从而导致conda工具不能够正常使用

我是由于在安装tensorflow-gpu版本导致python的版本也发生了改变,从python3.6版本变成了python3.7版本,可以通过如下命令进行查看:

dw@estar-cvip:~$ ls
anaconda3  Anaconda3-5.1.0-Linux-x86_64.sh  c++  dudu  examples.desktop  ssh
dw@estar-cvip:~$ which conda
/home/dw/anaconda3/bin/conda
dw@estar-cvip:~$ ls -al anaconda3/lib | grep "python"
-rwxrwxr-x  3 dw dw  26831702 58 05:36 libpython3.7m.a
-rw-rw-r--  3 dw dw  24498878 58 05:35 libpython3.7m.nolto.a
lrwxrwxrwx  1 dw dw        20 514 13:09 libpython3.7m.so -> libpython3.7m.so.1.0
-rwxrwxr-x  3 dw dw   3805376 58 05:36 libpython3.7m.so.1.0
-rwxrwxr-x  3 dw dw     15616 58 05:36 libpython3.so
drwxrwxr-x  4 dw dw     12288 514 13:09 python3.6
drwxrwxr-x 35 dw dw     12288 514 13:09 python3.7
dw@estar-cvip:~$ ls -al anaconda3/lib/python3.7/site-packages/ | grep "conda"
dw@estar-cvip:~$ ls -al anaconda3/lib/python3.6/site-packages/ | grep "conda"
drwxrwxr-x   2 dw dw   4096 116 15:21 anaconda_client-1.6.9-py3.6.egg-info
drwxrwxr-x  10 dw dw   4096 116 15:21 anaconda_navigator
drwxrwxr-x   2 dw dw   4096 116 15:21 anaconda_navigator-1.7.0-py3.6.egg-info
drwxrwxr-x   6 dw dw   4096 116 15:21 anaconda_project
drwxrwxr-x   2 dw dw   4096 116 15:21 anaconda_project-0.8.2-py3.6.egg-info
drwxrwxr-x  10 dw dw   4096 116 15:21 conda
-rw-rw-r--   2 dw dw   9222 210  2018 conda-4.4.10-py3.6.egg-info
drwxrwxr-x   7 dw dw   4096 116 15:21 conda_build
drwxrwxr-x   2 dw dw   4096 116 15:21 conda_build-3.4.1-py3.6.egg-info
drwxrwxr-x   7 dw dw   4096 116 15:21 conda_env
drwxrwxr-x   3 dw dw   4096 116 15:20 conda_verify
-rw-rw-r--   2 dw dw   5337 918  2017 conda_verify-2.0.0-py3.6.egg-info
dw@estar-cvip:~$ ls -al anaconda3/bin/ | grep "python"
-rwxrwxr-x  1 dw dw      241 116 15:21 ipython
-rwxrwxr-x  1 dw dw      241 116 15:21 ipython3
lrwxrwxrwx  1 dw dw        9 514 13:09 python -> python3.7
lrwxrwxrwx  1 dw dw        9 514 13:09 python3 -> python3.7
-rwxrwxr-x  1 dw dw 12765984 514 13:09 python3.7
lrwxrwxrwx  1 dw dw       17 514 13:09 python3.7-config -> python3.7m-config
lrwxrwxrwx  1 dw dw        9 514 13:09 python3.7m -> python3.7
-rwxrwxr-x  1 dw dw     3293 514 13:09 python3.7m-config
lrwxrwxrwx  1 dw dw       17 514 13:09 python3-config -> python3.7m-config
dw@estar-cvip:~$ python
Python 3.7.7 (default, May  7 2020, 21:25:33)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

2 解决方法

重新安装原先版本的Anaconda,但是为了保留我们用Anaconda建的虚拟环境,即Anaconda/envs下的所有文件,这样我们就不用重新搭建之前的虚拟环境。只要在安装的时候使用参数:-u 即可:

bash Anaconda3-5.2.0-Linux-x86_64.sh -u

Anaconda3-5.2.0-Linux-x86_64.sh对应的python版本是3.6.5

参考1:https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/ajBhRlnz_Zg
参考2:https://blog.csdn.net/qq_28256625/article/details/105250394

已标记关键词 清除标记
相关推荐
<div> <p><strong>I'm submitting a...</strong> - [X ] bug report - [ ] feature request</p> <h2>Current Behavior</h2> <p>hi, I've uninstalled, and reinstalled anaconda upwards of 10 times in the last two days - yesterday it stopped working (I tried to install kivy on my regular python install, think if I pip'd it over there I would be able to use it in spyder - figured out that's not a thing, went into spyder, tweaked with the python path menu, thinking I could use the other python as my python path, and the modules installed with it would be rendered (did not work) then all of a sudden ipython couldn't connect to kernel, I told it to reset all settings to default, then it crashed, wouldn't relaunch spyder - then I couldn't relaunch the anaconda navigator or command line - so uninstall number 1 happened, I tried reinstalling (Thinking everything would be fine) and it didn't even give me this much (Told me activate.bat was not a valid command when I tried to run anaconda prompt, and when I tried to run the navigator bupkiss) Uninstalled, and tried all the variations of install settings, this time I tried manually replacing the files it said it was missing, and this is as far as I've gotten because I cannot find a conda.cli file, and don't know where to put it based on the code in referenced file (Assume in scripts) </p> <p>I am very new at all of this.</p> <p>Traceback (most recent call last): File "C:\ProgramData\Anaconda3\Scripts\conda-script.py", line 6, in from conda.cli import main ModuleNotFoundError: No module named 'conda'</p> <p>C:\Users\Utility>import conda 'import' is not recognized as an internal or external command, operable program or batch file.</p> <p>C:\Users\Utility>conda.<strong>version</strong> 'conda.<strong>version</strong>' is not recognized as an internal or external command, operable program or batch file.</p> <p>C:\Users\Utility>conda Traceback (most recent call last): File "C:\ProgramData\Anaconda3\Scripts\conda-script.py", line 6, in from conda.cli import main ModuleNotFoundError: No module named 'conda'</p> <p>C:\Users\Utility>pydoc conda No Python documentation found for 'conda'. Use help() to get the interactive help utility. Use help(str) for help on the str class.</p> <p>C:\Users\Utility>help(conda) This command is not supported by the help utility. Try "(conda) /?".</p> <p>C:\Users\Utility>conda /? Traceback (most recent call last): File "C:\ProgramData\Anaconda3\Scripts\conda-script.py", line 6, in from conda.cli import main ModuleNotFoundError: No module named 'conda'</p> <h3>Steps to Reproduce</h3> <p>See above.</p> <pre><code> </code></pre> <h2>Expected Behavior</h2> <p>that I would be able to install and use anaconda</p> <h2>Environment Information</h2> <code>`conda info`</code><p> Windows 10? </p> <code>`conda config --show-sources`</code><p> </p><pre><code> </code></pre> <code>`conda list --show-channel-urls`</code><p> </p><pre><code> </code></pre> <p>该提问来源于开源项目:conda/conda</p></div>
<div> <h2>Current Behavior</h2> <p>After we did <code>conda install -c conda-forge imbalanced-learn</code> it updated some packages and seems to have made conda command disabled so now we always get <code>ModuleNotFoundError: No module named 'conda'</code> when trying to execute conda commands, My PATH also has <code>/opt/conda/bin:</code> and even doing <code>/opt/conda/bin/conda</code> directly fails:</p> <pre><code> root:# conda Traceback (most recent call last): File "/opt/conda/bin/conda", line 7, in <module> from conda.cli import main ModuleNotFoundError: No module named 'conda' </module></code></pre> <p>I installed conda with miniconda and the python executable still loads, python updated itself while installing imbalanced-learn so maybe that did something to the conda executable? I also get a ModuleNotFoundError: for every package I try to import into Python that is currently a conda package. As you can see from the conda-meta/history log below, that shows the update that damaged conda, the version is 4.5.11</p> <pre><code> ==> 2020-02-08 14:44:22 <== # cmd: /opt/conda/bin/conda install -c conda-forge imbalanced-learn # conda version: 4.5.11 -conda-forge::ca-certificates-2019.3.9-hecc5488_0 -conda-forge::certifi-2018.8.24-py35_1001 -conda-forge::openssl-1.0.2r-h14c3975_0 -conda-forge::setuptools-40.4.3-py35_0 -defaults::blas-1.0-mkl -defaults::libgcc-ng-8.2.0-hdf63c60_1 -defaults::libstdcxx-ng-7.2.0-h7a57d05_2 -defaults::numpy-1.13.3-py35hdbf6ddf_4 -defaults::pip-8.1.2-py35_0 -defaults::python-3.5.2-0 -defaults::scikit-learn-0.19.1-py35hbf1f462_0 -defaults::scipy-1.1.0-py35hfc37229_0 -defaults::wheel-0.29.0-py35_0 +conda-forge::_libgcc_mutex-0.1-conda_forge +conda-forge::_openmp_mutex-4.5-0_gnu +conda-forge::blas-2.11-openblas +conda-forge::ca-certificates-2019.11.28-hecc5488_0 +conda-forge::certifi-2019.11.28-py36_0 +conda-forge::imbalanced-learn-0.6.1-py_0 +conda-forge::joblib-0.14.1-py_0 +conda-forge::libblas-3.8.0-11_openblas +conda-forge::libcblas-3.8.0-11_openblas +conda-forge::libgcc-ng-9.2.0-h24d8f2e_2 +conda-forge::libgomp-9.2.0-h24d8f2e_2 +conda-forge::liblapack-3.8.0-11_openblas +conda-forge::liblapacke-3.8.0-11_openblas +conda-forge::libstdcxx-ng-9.2.0-hdf63c60_2 +conda-forge::ncurses-5.9-10 +conda-forge::numpy-1.18.1-py36h95a1406_0 +conda-forge::openssl-1.0.2u-h516909a_0 +conda-forge::pip-20.0.2-py_2 +conda-forge::python-3.6.3-0 +conda-forge::scikit-learn-0.22.1-py36hcdab131_1 +conda-forge::scipy-1.4.1-py36h921218d_0 +conda-forge::setuptools-45.1.0-py36_0 +conda-forge::wheel-0.34.2-py_1 +defaults::libopenblas-0.3.6-h5a2b251_2 # update specs: ['imbalanced-learn'] </code></pre><p>该提问来源于开源项目:conda/conda</p></div>
©️2020 CSDN 皮肤主题: 猿与汪的秘密 设计师:白松林 返回首页