8

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?

enter image description here

enter image description here

2
  • I hope this helps : code.visualstudio.com/docs/python/environments Commented Jun 6, 2019 at 21:49
  • 2
    If Ian or SanV solved your problem then select the best answer (checkmark and award point or points). Commented Jun 27, 2019 at 7:58

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hey, thanks for replying here. I have the same problem and it doesn't seem to be working for me the way as you say. Interactive keeps selecting a different environment (not the one from lower left corner) even though I have Jupyter installed in my main environment. Would happily debug if you feel like it
@Corvin. These issues can be hard to debug over the internet, but I'd love to try unblocking you on this. A few questions to narrow it down. 1. You are using the main Python extension and not the extension insiders build, right? We've changed things around startup quite a bit in the insiders build. 2. From the env in the lower left corner can you open up a terminal (or cmd) window with the environment active and run "python -m jupyter notebook --version". That's the command we run to check if jupyter is installed into an env.
3

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.

2 Comments

That did not work for me. By experimentation, I found I merely had to venv/bin/pip install ipykernel which automatically pulled in the minimal ipython, jupter-client, jupyter-core, etc required.
@bulletmark thanks for posting what worked for you. the newer versions of VSCode has Jupyter extension which, I believe, takes care of necessary installs and integration. Also, VSCode Insiders edition has additional beta features, such as ability to merge and split cells.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.