English 中文(简体)
视觉演进室 Conda环境
原标题:Visual Studio Code terminal doesn t activate Conda environment

我读到,在类似问题上,Stack Overflow Post,但建议似乎并未奏效。 我在我的视窗机器上安装了视频演播室法,并添加了“灰尘”推广。 然后,我将Khuraya路改为C:Usersusername.condaenvs ompython.exe。 The .vscode/ establishings.json has this in:

{
    "python.pythonPath": "C:\Users\username\.conda\envs\tom\python.exe"
}

《演播室法》中的地位栏还显示:

Enter image description here

但是,当我做conda env list时,甚至在我做过工作之后,在终端I就取得了以下成果:

# conda environments:
#
base                  *  C:ProgramDataAnaconda3
tom                      C:Usersusername.condaenvs	om

而不是:

# conda environments:
#
base                     C:ProgramDataAnaconda3
tom                   *  C:Usersusername.condaenvs	om

在我尝试<代码>python app.py时,没有在基地安装的包裹也没有进口。 我应该做些什么?

<代码>,python,但并未给出任何产出。

Also,

import os
import sys
os.path.dirname(sys.executable)

专 员

 C:\Python38 
最佳回答

第一,开放Anaconda即时() • 如何进入Windows 10(64-bit)的Anaconda指挥系统;

conda activate tom

2. 启动您的虚拟环境。

然后在这种活跃的环境中开放视觉演播室。

code

它应当发挥作用。

问题回答

我长期面临同样的问题,似乎没有任何工作。 在任何地方,《联邦法典》在一份通知中建议我:

We noticed you re using a conda environment. If you are experiencing issues with this environment in the integrated terminal, we recommend that you let the Python extension change "terminal.integrated.inheritEnv" to false in your user settings.

我点击了<代码>yes,并做了工作。 你们也可以在你们的环境下以人工的方式确定这一点。 json, 如下:

  1. Press Shift + Command + P to open command palette.
  2. Type settings.json and select `Preferences: Open Settings (JSON)
  3. In the JSON file, add the key-value pair "terminal.integrated.inheritEnv": false
  4. Save the JSON file
  1. In Vscode hit ctrl+` to open your terminal.
  2. Then within the terminal type: conda init.
  3. Close and reopen the terminal.
  4. Use Conda normally.

“entergraph

I was helped by switching the terminal from powershell to cmd

我已经尝试了解决这一问题的多数解决办法。 然而,这些没有工作。 在以下步骤之后:Sabito 錆兎,我在回答时最后解决了这一问题。

解决办法1:

  1. <代码>终止:选定缺损简介>

  2. Choose Command Prompt

    “Image

  3. 打开一个新的终点站,你可以 use忙做这样的事。

改变违约终点站的另一个办法是(如果你忘记指挥):

  1. On the right top of the terminal panel, click + (Launch Profiles)
  2. Select default Profile
  3. Choose which you want in this way, you can also open configure terminal settings

解决办法2:

  1. http://stackoverflow.com/users/11573842/sabito-%e9%8c%86%e5% 858e”

  2. <代码>Python:选择性口译

  3. Choose which env in conda you need. You can also select on the bottom panel.

  4. 不必要的步骤:在<代码>vscode- establishings.json中,确保如果存在这一条线,那么论点是真实的:

    "python.terminal.activateEnvironment": true,
    

    Now, vscode will automatically change your env in your terminal according to your choice, like this:

    CMD

    当我选择<代码>底线:conda时,我打开了一个新终点站。 在青少年中,它显示:

    F:GitHub	>E:/Anaconda/Install/Scripts/activate 
    (base) F:GitHub	>conda activate base 
    (base) F:GitHub	>
    

    当我选择<代码>python3.8:conda

    F:GitHub	>E:/Anaconda/Install/Scripts/activate 
    (base) F:GitHub	>conda activate python3.8 
    (python3.8) F:GitHub	>
    

    PowerShell

    当我选择<代码>python3.8:conda。 缩略语

    (base) PS F:GitHub	> conda activate python3.8 
    (python3.8) PS F:GitHub	>
    

    当我选择<条码>基准:conda时,它就显示:

    (base) PS F:GitHub	> conda activate base  
    (base) PS  F:GitHub	>
    

1. 启动代谢库虚拟环境

  1. Go to the menu bar and click on Terminal.
  2. Type: conda init
  3. Close this terminal and open a new one
  4. In the new terminal window, Type conda info --envs
    (Your conda virtual env should be there in the list)
  5. Type conda activate name_of_venv
  1. Type: conda init
  2. switch to cmd terminal, because the shell terminal has problems
  3. enjoy

它为我打字。

This seems to be because the Anaconda installation recommends not changing the windows PATH to reference anaconda, as it can clash with other installations, I had no problems when my PATH variable was modified. It seems like vs code (or most likely the Python extension) is still not activating anaconda correctly itself.

虚拟环境可以在VSCode终端中启动,但Adhury版本没有改变。

解决办法是在VSCode选择“bash”,一切都属实。

If conda init fails, it might not just be a problem of conda missing in the search path. In my case it was because PowerShell did not have the rights to load the profile.ps1, see The term conda is not recognized as the name of a cmdlet.

在此情况下,如果你尚未安装PowerShell 7,则与PowerShell 5并填写C:UsersUSERDocuments PowerShellprofile.ps1。 注

#region conda initialize
# !! Contents within this block are managed by  conda init  !!
(& "C:UsersUSERanaconda3Scriptsconda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion

“entergraph

然后,将新的PowerShell 7终端添加到代码上,见,How在代码上添加Aaconda Powerhell?

终端菜单:

“在此处的影像描述”/</a

And conda init and the activation of the chosen Python interpreter s environment that you see in the status bar of VSCode will run automatically any time you open PowerShell 7.

评注:您可能需要conda init更新Shell 7

PythonPath is no longer used by the default Python plugin now (as of 2021). Instead, you can add the interpreter path using the following:

  1. In a terminal, run the following to get the path to your env:
conda activate <name of your env> && which python
  1. Then set the VSCode JSON setting (either user or workspace):
{
    "python.defaultInterpreterPath": "<Path to your env>",
}
  1. Restart VSCode completely to see your env in the terminal, as it seems that VSCode sometimes caches the terminal window.

(All this assumes that there are no other messed up settings in your vscode. If there are, look at other answers to this question).

在我的案件中:

  1. installed Python and set it to the Windows PATH
  2. refused to add Anaconda to PATHs as default Python interpreter during installation
  3. vs code finds the conda, but not conda cmdlet

<>Solution:

请允许我援引代码,在你运行时,把星座作为Windows PATH的第一个搜索途径。 这既适用于整个法典,也可以用于特定的工作空间。

Entire vs code:

  1. Ctrl + Shift + P
  2. Preferences: Open User Settings (JSON)
  3. add the path to the location of your conda.exe, in my case it s C:UsersUSERNAMEAppDataLocalanaconda3Scripts
 "terminal.integrated.env.windows": {
        "PATH": "C:\Users\USERNAME\AppData\Local\anaconda3\Scripts\;${env:PATH}"
    }

Specific workspace:

  1. Ctrl + Shift + P
  2. Preferences: Open Workspace Settings (JSON)
    "settings":
    {
        "terminal.integrated.env.windows": {
            "PATH": "C:\Users\USERNAME\AppData\Local\anaconda3\Scripts\;${env:PATH}"
        }
    }

非常感谢。 我确实是作为辅导员工作,而且管理着。

我已经尝试了解决这一问题的多数解决办法。 然而,这些没有工作。 在Sabito 在其答复中提到的步骤之后,我最终解决了这一问题。

解决办法1:

ctrl+

类型终端:选定缺省情况

Choose Front Prompt.

非常感谢

在我的案件中,只是选择了“共同选择”而不是“Poweshell”作为VS-code码头。 我不敢肯定的是,由于我并不是一个重型窗户使用者,因此在使用指挥方面是否有任何不利之处。 至少不用于 p方案。 如果我发现一些事情的话,我将更多地探讨,稍后还会补充。

The focus of this answer is to get the conda python environments to work with the Python Environments extension in vs code. There are many ways to do this, each has different effects and implications on how you want to interact with Python in vs code.

我的环境:Windows 10, Conda 23.7.4, Conda 安装在C:apps &我使用PowerShell 7而不是窗户PowerShell。

  1. Opening vs-code via Anaconda navigator or type code in conda prompt. This loads Conda environments in to Python Environments window. Includes nice ui conponents. This also removes conda from the powershell terminal. So you can write "activate myenv".
  2. If you want to open vs code directly, add to settings:
"python.condaPath": "C:\apps\Anaconda3\Scripts\",
"python.venvPath": "C:\apps\Anaconda3\envs",
"terminal.integrated.defaultProfile.windows": "Command Prompt",

这种方法将环境推向全球,并对Venv而言具有另一个倍数。

  1. The following will run base conda in all powershell terminals: in conda prompt run conda init & add to settings:
"python.condaPath": "C:\apps\Anaconda3\Scripts\",
"python.venvPath": "C:\apps\Anaconda3\envs",

注:

  • It can sometimes take a while to detect the conda environments
  • there is a difference between loading via conda prompt code and navigator
  • sometimes some methods work with some environments and not others.

将终点站从权力分配到水泥箱,或由我指挥。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签