我在Windows 10
计算机上安装了VS Code v1.44.2
和Microsoft的^{
根据{
这种功能在某种程度上是有效的:对我来说,只有从版本选择器中选择的Python版本是3.5.2
——微软的ML服务器附带的版本时,这种功能才有效。而且,只有当正在启动的集成终端是cmd
时,它才起作用
当满足这两个狭窄条件时,可以肯定的是,只要启动集成终端,vscode-python
就会运行/path/to/ML Server/Python/executable/activate.bat
,如果在此后的命令提示符下运行python --version
,您就会看到:
Python 3.5.2 :: Anaconda 4.2.0 (64-bit)
不幸的是,环境激活在我安装的其他几个Python版本中不起作用:2.7.x
、3.6.x
、3.7.x
:不在cmd
或gitbash
上,我怀疑在许多其他shell上也不起作用
查看vscode-python
源代码,原因很明显:vscode-python
在与python.pythonPath
相同的文件夹中查找activate
脚本(activate.bat
,activate.sh
,activate
),而这些脚本通常位于python.pythonPath/Lib/venv/scripts
的子文件夹中
来自vscode-python
repo(src/client/common/terminal/environmentActivationProviders/baseActivationProvider.ts
)的相关代码片段复制如下:
protected async findScriptFile(pythonPath: string, scriptFileNames: string[]): Promise<string | undefined> {
const fs = this.serviceContainer.get<IFileSystem>(IFileSystem);
for (const scriptFileName of scriptFileNames) {
// Generate scripts are found in the same directory as the interpreter.
const scriptFile = path.join(path.dirname(pythonPath), scriptFileName);
const found = await fs.fileExists(scriptFile);
if (found) {
return scriptFile;
}
}
}
此方法从src/client/common/terminal/environmentActivationProviders/bash.ts
调用:
public async getActivationCommandsForInterpreter(
pythonPath: string,
targetShell: TerminalShellType
): Promise<string[] | undefined> {
const scriptFile = await this.findScriptFile(pythonPath, this.getScriptsInOrderOfPreference(targetShell));
if (!scriptFile) {
return;
}
return [`source ${scriptFile.fileToCommandArgument()}`];
}
private getScriptsInOrderOfPreference(targetShell: TerminalShellType): string[] {
switch (targetShell) {
case TerminalShellType.wsl:
case TerminalShellType.ksh:
case TerminalShellType.zsh:
case TerminalShellType.gitbash:
case TerminalShellType.bash: {
return ['activate.sh', 'activate'];
}
case TerminalShellType.tcshell:
case TerminalShellType.cshell: {
return ['activate.csh'];
}
case TerminalShellType.fish: {
return ['activate.fish'];
}
default: {
return [];
}
}
}
从这些代码片段可以明显看出,如果集成终端是gitbash
,vscode-python
在python.pythonPath
中查找activate.sh
或activate
,但不在其子目录中
我在网上寻找工作机会的结果并不多。有些答案依赖于.bashrc
或.bash_profile
中的别名或源代码激活,但这并不能解决我的问题
理想情况下,我希望具有以下功能:
activate
文件李>我确信其他vscode-python
用户也遇到了同样的问题,从代码片段来看,解决方案似乎很简单(允许搜索/venv/**/*
);只是想看看是否有不同的方式来实现我的最终目标
没有人回答这个问题? 这里有一个链接,指向您应该使用的设置。 我在windows上运行MiniConda3,但你可以为Mac调整它。 我为数据科学的不同课程构建了几个环境。当我打开VS代码时,终端被设置为我想要的Python版本。命令提示符。此外,Jupyter或terminal窗口也设置了正确的版本
https://medium.com/analytics-vidhya/efficient-way-to-activate-conda-in-vscode-ef21c4c231f2
相关问题 更多 >
编程相关推荐