我有一个shell脚本env.sh
,其中包含像export ENV_VAR1 = 1
这样的语句。在Linux终端上,我可以使用. env.sh
或source env.sh
来设置环境变量。
如何通过env.sh
在Visual Studio Code(VSCode)中设置环境变量?
我尝试了多种方法:
1)在获取脚本源代码后,我启动(VSCode -/usr/share/code/code
),如下所示. env.sh /usr/share/code/code
2)我使用扩展“AutoRunCommand”在工作区加载时调用. env.sh
。
例如,在使用Jupyter扩展时,我在import matplotlib
中得到错误,即使当我在上面的Linux终端中使用Python解释器时导入工作。
3条答案
按热度按时间toiithl61#
您可以尝试使用环境变量定义文件。
eyh26e7m2#
对于bash,您可以创建一个shell/source脚本,并将其作为工作区根目录中终端
settings.json
的参数。参考文献:
qoefvg9y3#
您还可以为特定工作区的集成终端创建配置文件。例如zsh:
.vscode/设置.json:
.vscode/init.sh:
这样,您就可以用这个配置文件启动一个新的终端,它将自动运行初始化脚本。