How do you change environment of Python Interactive on Vscode? - python

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.

Related

How to fix Visual Studio Code Jupyter notebook error?

VScode for python runs perfectly, without any error, problems starts whenever I try to run Jupyter notebook inside VScode.
It starts with Ipython Kernel loading and then it shows Command Failed Error. Any fix for this ? I have no idea what's the problem and I don't know much about the environment and stuffs also.
Thank You.
From your picture, VSCode said Command failed, and it's a very long command. It mainly includes two parts: activate the conda base environment and change the vscode python environment through "Python" extension. And from the top right of the picture, it shows the jupyter server start failed.
So you can try to do two things:
First one: change the environment. Instead of using conda, download and install a global python from the official website. And recommend creating a virtual environment. Then select the environment instead of conda base environment.
Second one: reinstall or downgrade the 'Python' extension(if the first one not work).
This problem can be caused by the package in the environment, so I recommend you just change to another environment.

Visual Studio Code Python Interactive Window env different from selected?

I am using visual studio code to try and replace the Spyder IDE. To replicate Spyder's variable explorer, I am trying to leverage VS code's Python Interactive Window.
Upon launching Vs Code, I select my environment using "Select Interpreter" and then picking the env. This then changes at the bottom of the application as expected.
However, when I then try and run my code in the interactive window it appears to reference a different environment? It also keeps telling me to install ipykernel.
Is this functioning correctly? I do see an option to change the env in the interactive window but that doesn't do anything.enter image description here
I found a similar question here But I have ipykernel installed in my environment so I'm not sure why it wouldn't notice that? Is there another dependency?
Maybe we can simplify the problem.
Click top-right environment and changes it to which you want.
Start off by opening your Anaconda prompt and from there activate your virtual environment (type: conda activate my_env, replacing my_env with your environment name, and hit enter.)
Then type the command: 'code', which will open up VS Code from within your active virtual environment. Before this approach, also check that your VS Code settings.json file has the python path set correctly to your environment installation. Now it should work.
To see your install path: Anaconda is installed in your user home directory: Windows 10: C:\Users\\Anaconda3\

VS Code: Can't load anaconda environment on Python Interactive

I am using VS Code in Windows 10.
I am able to use the dependencies in my conda environment if I Run the Python Script in Terminal. However, I am not able to use the environment in the Python Interactive shell.
For instance, I am using my datascienceenvironment which has the package fuzzywuzzy. I have included the env path into the settings.jsonas the python.pythonPath. But the Python version used in the Jupyter Notebook is the default anaconda base C:\\ProgramData\\Anaconda3\\python.exe
What is also extrange, is that if I run !conda list within the Notebook, I can see the fuzzywuzzy package.
What am I missing?
Thanks!
I'm a developer on the Interactive Windows. Priyatham has already pointed you in the right direction. Currently our Window tries to use the currently selected environment (the one in the lower left corner). But we didn't want to totally block customers if they didn't have Jupyter installed in each environment. So if the selected interpreter doesn't have Jupyter in the environment we'll check other environments on the system, looking for the closest python version match to the currently selected one. If we find something with Jupyter we'll launch the Interactive Window using that. In this case we do show a popup in the lower right indicating that we didn't find Jupyter and that we are falling back on a different environment, but this message can be pretty easy to miss.

How to tell VScode, on my Mac running high Sierra, which version of python to use

I use VScode to write and run python. I use it with a Jupyter extension. I have 2 virtual environments created using Anaconda. One py27, for python 2.7.13 and the other, py36, for Python 3.6.5.
I have a simple code which I edited to only run in python2. When I run VScode, the virtual environment I run it in does not seem to matter. VScode seems to run but I can't figure out how to make it use py36 (python 3.6.5) or py27 (python 2.7.13).
By using different commands in the command palette, or double-clicking on phrases in the bottom border of VScode I can eventually get it to run which version I want. But I have not found a reproducible method.
I have tried about 100 times with no luck. I thought I found a method that would repeat but I tried it again and it didn't work.
I know this question is very vague but it would take pages to explain what I've tried. I have about 5 or 6 settings which I've tried a plethora of combinations. One of the commands I tried is to select a python interpreter. I have several options but none seem to have an effect. Also, in the bottom border of the VScode window, there is the name of a specific python interpreter. You can click on this to select a different python interpreter. As far as I can tell this doesn't do anything. Actually, it's a hindrance because a user may think they are actually using that interpreter.
I've tried both py27 and p36 but I get no difference. If I can get visual studio code to start out in py27, I can make it change to py36 and back to py27. But how to make it start in py27 seems random. My virtual environments are in my home directory, /User/myname/py27 for example along with the VScode app.
The documentation at https://code.visualstudio.com/docs/python/environments explains how to select your virtual environment. Without knowing where you installed the virtual environments the best I can tell you is you can manually specify what interpreter to use with the python.pythonPath setting or if you have both virtual environments in a directory outside of your workspace folder you can specify the common folder with the python.venvPath setting.

How to specify python3 kernel in jupyter in pyCharm?

Here is my setting
and this is my script
I am trying to use jupyter notebook in pyCharm, but it kept using python2 instead of python3.
Any idea about this problem?
Add:
this pic is running jupyter notebook in chrome.
My problem was that I had multiple kernels, and PyCharm launches the default kernel. One approach might be to configure PyCharm to specify the kernel of choice to start up, I didn't investigate how to do that. I simply changed the default kernel in Jupyter and this worked for me (I have a virtualenv for tensorflow). c.MultiKernelManager.default_kernel_name = 'tensorflow'.
The preferences image you show is indeed how you would setup your interpreter for PyCharm, but that's not what the output/logging of PyCharm looks like. I'm guessing that's a jupyter-notebook display, which means you are running into the issue in jupyter-notebook and not PyCharm. So you need to change your setup for jupyter. Based on some quick searching pip install jupyter will install a python 2.7 version of jupyter. Sounds like what you want is
pip3 install jupyter
which will install the python3 version for you. You will likely have to uninstall your current version of jupyter.
When you kick off Jupyter-notebook from within PyCharm there is a configuration which is created. If the configuration is initially 2.7 ( I think it defaults to the current interpreter), and then keep using that same configuration, it wouldn't matter the state of the current project interpreter because it would be using the value saved in the run configuration.
You can modify your run configuration by
Run | Run...
Edit Configurations...
Select your Jupyter Notebook run configuration on the left (here is untitled4)
Make sure the python interpreter is correct here on the right
I was able to start a jupyter notebook like this and get it to output python 3 by doing this. Hope this is what you are needing.

Categories

Resources