VS Code启动<conda active base>错误信息

问题描述 投票:0回答:2

我刚开始在 Visual Studio Code 上学习 Anaconda。以前,我只使用 Python 作为解释器。下载 Anaconda 并打开 VS Code 后,我总是遇到以下错误消息。

PS C:\Users\user\Documents\PythonLearn> conda activate base
conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the 
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ conda activate base
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (conda:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

我已经尝试安装并重新安装 anaconda 并通过设置环境变量,但错误消息仍然存在。我使用的步骤如下。

我的安装过程

  1. 下载蟒蛇

    • 选择一:只有我(推荐)

    • 选择2(高级): Registered Anaconda3 for the system Python 3.9

  2. 将anaconda加入环境变量

    • 以管理员身份运行“Anaconda Prompt (anaconda3)”

    • 奔跑

      where conda

    • 将目录添加到环境变量

    where conda result

  3. 将解释器路径添加到 VS 代码中

    Adding the interpreter path into the VS code

  4. 通过 .py 文件进行测试

    • 测试#1 - 蟒蛇:

      print("Hello, world")

    Hello world test#1 result

    • 测试#2 - 图书馆:
    import matplotlib.pyplot as plt
    import matplotlib as mpl
    import numpy as np
    x = np.linspace(0, 20, 100)
    plt.plot(x, np.sin(x))
    plt.show()
    

    对于测试#2,终端产生如下错误信息

    PS C:\Users\user\Documents\PythonLearn> & C:/Users/user/anaconda3/python.exe c:/Users/user/Documents/PythonLearn/pytest.py
    C:\Users\user\anaconda3\lib\site-packages\numpy\__init__.py:148: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
      from . import _distributor_init
    Traceback (most recent call last):
      File "C:\Users\user\anaconda3\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
        from . import multiarray
      File "C:\Users\user\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>       
        from . import overrides
      File "C:\Users\user\anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
        from numpy.core._multiarray_umath import (
    ImportError: DLL load failed while importing _multiarray_umath: The specified module could not be found.
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "c:\Users\user\Documents\PythonLearn\pytest.py", line 3, in <module>
        import matplotlib.pyplot as plt
      File "C:\Users\user\anaconda3\lib\site-packages\matplotlib\__init__.py", line 104, in <module>
        import numpy
      File "C:\Users\user\anaconda3\lib\site-packages\numpy\__init__.py", line 150, in <module>
        from . import core
      File "C:\Users\user\anaconda3\lib\site-packages\numpy\core\__init__.py", line 48, in <module>
        raise ImportError(msg)
    ImportError:
    
    IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
    
    Importing the numpy C-extensions failed. This error can happen for
    many reasons, often due to issues with your setup or how NumPy was
    installed.
    
    We have compiled some common reasons and troubleshooting tips at:
    
        https://numpy.org/devdocs/user/troubleshooting-importerror.html
    
    Please note and check the following:
    
      * The Python version is: Python3.9 from "C:\Users\user\anaconda3\python.exe"
      * The NumPy version is: "1.21.5"
    
    and make sure that they are the versions you expect.
    Please carefully study the documentation linked above for further help.
    
    Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.
    
    PS C:\Users\user\Documents\PythonLearn>
    

调试尝试

  1. 以前的可能解决方案:更新环境变量

    我重新安装并更新了新路径。命令提示符仍然无法识别系统中的 conda。然而,系统检测到 Python。

    CMP_Version_Response

  2. 测试 Anaconda 是否正常工作

    我测试了安装的Anaconda文件是否可以在Anaconda所在的目录中检测到版本。系统确实检测到Anaconda的安装版本。

    Anaconda Exist


结尾说明/更新

有没有人遇到这个错误的类似问题?您推荐的解决方案是什么?

提前感谢您的回复。如果我找到解决方案,我会及时通知您。

更新#1: 重启,重新打开,重新选择路径,更新 我已经通过 Anaconda 终端中的

conda update conda
conda update anaconda
更新了 Anaconda。同时重新启动计算机并重新打开终端。尽管如此,每当我打开 VS 代码时,错误代码仍然存在(下面的错误代码)。

. : File C:\Users\user\Documents\WindowsPowerShell\profile.ps1 cannot be loaded because running scripts is disabled on this system. For more        
information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:3
+ . 'C:\Users\user\Documents\WindowsPowerShell\profile.ps1'
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
PS C:\Users\user\Documents\PythonLearn> conda activate base
conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or 
if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ conda activate base
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (conda:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
PS C:\Users\user\Documents\PythonLearn> 

       
python anaconda data-science
2个回答
0
投票

你是否在 VS Code 仍然打开时安装了 conda?

VS Code 终端不更新它的 PATH,PATH 的初始化在终端启动时进行,CMD 也一样。

我唯一的解决方案是重新打开 VS Code 或在导航栏的终端部分启动一个新终端,因为您已经在 Windows 上安装了 conda 并且 CMD 确认了它

解释器路径定期更新。


0
投票

解决方案: 完全卸载,使用高级选择重新安装

大声呼唤 Gren Man 的解决方案。步骤如下

  1. 干净卸载anaconda

    • 'conda 安装 anaconda-clean' --> 运行 'anaconda-clean --yes'
    • 然后进入“添加或删除程序”-->卸载Anaconda3-->重启电脑
  2. 重新安装

  3. 测试和验证

    • 运行 print("Hello, world") --> 检查 Python [通过]
    • 运行库测试(见上文)--> Checking Library [Passed]

附加说明

选择“Add PATH”选项,将如下路径添加到系统中。 VS Code 可以发现它们。 添加的路径与调用

where conda
不同,自己手动添加到环境变量中。

© www.soinside.com 2019 - 2024. All rights reserved.