[英]How do you change environment of Python Interactive on Vscode?
I recently migrated from Spyder
to VScode
. 我最近从Spyder
迁移到了VScode
。 I created a new conda environment and used setting.json to change the environment in VScode, "python.pythonPath": "/Users/dcai/anaconda3/envs/alphalens/bin/python"
我创建了一个新的conda环境并使用setting.json来改变VScode中的环境, "python.pythonPath": "/Users/dcai/anaconda3/envs/alphalens/bin/python"
However when I tried to run the code in Python Interactive, a different environment was loaded. 但是,当我尝试在Python Interactive中运行代码时,加载了不同的环境。
Is there a way for me to change the Python Interactive environment and match it to my terminal environment? 有没有办法让我改变Python Interactive环境并将其与我的终端环境相匹配?
The Python Interactive window should be starting up using the Python version selected in the lower left corner of the VS Code IDE. Python Interactive窗口应该使用在VS Code IDE左下角选择的Python版本启动。 This is the same environment that you can also pick via the Python: Select Interpreter command palette option. 这是您可以通过Python选择的相同环境:选择Interpreter命令选项板选项。 However the Python Interactive window does do one thing differently here. 但是,Python Interactive窗口在这里做了一件不同的事情。 If the currently selected environment does not have jupyter installed it will look in the other environments for one that does and launch it, you should see a warning message in this case that a different environment was used. 如果当前选择的环境没有安装jupyter,它将在其他环境中查找执行和启动jupyter的环境,在这种情况下您应该看到一条警告消息,表明使用了不同的环境。
Did this help answer your question? 这有助于回答您的问题吗? I'm a developer on this feature so I can help you debug if you are still seeing the wrong env launched. 我是这个功能的开发人员,所以如果你仍然看到错误的env启动,我可以帮你调试。
I had the same situation as the OP. 我有与OP相同的情况。 After reviewing @IanHuff's answer, that if desired (target) environment does not have Jupyter installed, the Python Interactive window will use another where it is found. 在查看@ IanHuff的答案后,如果需要(目标)环境没有安装Jupyter,Python Interactive窗口将使用另一个找到它的地方。 I considered installing Jupyter in my target environment, but it would have installed a lot of packages. 我考虑在我的目标环境中安装Jupyter,但它会安装很多软件包。 Having to do that for each virtual environment would be unnecessarily burdensome. 必须为每个虚拟环境做到这一点将是不必要的负担。 So instead of the entire Jupyter package, I installed just the ipython_kernel in the target environment as follows and it worked: 因此,我在目标环境中只安装了ipython_kernel ,而不是整个Jupyter包,它的工作方式如下:
$ ipython kernel install --user --name=<target_environment_name>
Hope this helps others trying to use Visual Studio Code with Jupyter Notebooks. 希望这有助于其他人尝试将Visual Studio Code与Jupyter笔记本一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.