简体   繁体   中英

How do you change environment of Python Interactive on Vscode?

I recently migrated from Spyder to 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"

However when I tried to run the code in Python Interactive, a different environment was loaded.

Is there a way for me to change the Python Interactive environment and match it to my terminal environment?

在此输入图像描述

在此输入图像描述

The Python Interactive window should be starting up using the Python version selected in the lower left corner of the VS Code IDE. This is the same environment that you can also pick via the Python: Select Interpreter command palette option. However the Python Interactive window does do one thing differently here. 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.

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.

I had the same situation as the 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. I considered installing Jupyter in my target environment, but it would have installed a lot of packages. 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 install --user --name=<target_environment_name>

Hope this helps others trying to use Visual Studio Code with Jupyter Notebooks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM