简体   繁体   English

你如何在Vscode上改变Python Interactive的环境?

[英]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.

相关问题 Python:如何更改 vscode 中的脚本执行位置? - Python: How do you change a scripts location of execution in vscode? 您如何在VSCode中查看活动的Conda环境? - How do you view the active Conda environment in VSCode? 摆脱 VSCode 交互式 Python 环境中的 unicode 字符 - Get rid of unicode characters in VSCode Interactive Python Environment 删除由 VSCode 在 Jupyter 中创建的“Python Interactive”环境? - Delete 'Python Interactive' environment created by VSCode inside Jupyter? vscode Python交互中的交互模式 - Interactive mode in vscode Python interactive 您如何查看交互式 Python 中的整个命令历史记录? - How do you see the entire command history in interactive Python? vscode python interactive window timed out on running python script on other conda environment 除了基础环境 - Vscode python interactive window timed out on running python script on other conda environment apart from base environment VSCode 中的 Python:如何运行之前的命令? - Python in VSCode: How do you run a previous command? 如何在 vscode 中的 python 中获得用户输入? - How do you get a user input in python in vscode? Python 解释器(VScode)“激活”一个 conda 环境,但环境没有改变 - Python interpreter (VScode) "activates" a conda environment, but the environment doesn't change
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM