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.
Related
EDIT: Problem solved.
Turns out Avast was classifying python.exe within the environments as a virus due to fresh conda installs (and being in silent mode I never found out). Solution found from here: https://github.com/ContinuumIO/anaconda-issues/issues/8266
__
I have something of a problem which I haven't seen anyone else directly have with conda environments and python kernels.
I can successfully create environments and install packages in them etc., but everytime I try to either (i) start a jupyter notebook or (ii) otherwise call an environment kernel in e.g. the VS Code jupyter extension, the kernel environment kernel "disappears" entirely from the environment in question.
In the former jupyter case, the environment successfully launches the notebook browser window when calling "jupyter-notebook" for the first time, but after some 5-10 seconds the browser dies and gives a connection error (I allowed my browser through firewalls etc. which hasn't helped). Trying to call the notebook again from the command line results in an "Unable to create process using 'C:\Users\user\miniconda3\envs\envname\python.exe C:\Users\user\miniconda3\envs\envname\Scripts\jupyter-notebook-script.py' error, after which calling "where python" on the command line only returns the base kernel, and loses all connection to the environment kernel.
In the VS Code case using the jupyter extension, I correctly get prompted to choose a python interpreter and successfully manage again to execute cells for about 5-10 seconds, until VS Code returns an "Error: Direct kernel connection broken" after which again the kernel just completely vanishes from both the command line and the kernel menu in VS Code.
No files in the environments seem to have changed (AFAIK) and I am completely baffled as to what is going on.
Throughout all of these the base kernel seems to run fine, so I'd venture a guess this has something to do with the way jupyter calls the environment kernel and somehow breaks them in the process. I was successfully running a number of environments for months before on the same setup. The problem initially occurred when I created a new environment, launched VS Code for that environment which inadvertently did not have ipykernel installed, and after getting a prompt from VS Code asking me to install ipykernel, every pre-existing environment consistently started failing in the way described above. After this I reinstalled Anaconda and I have been unable to get a single environment to work.
A minimal example of how the environments were typically created:
conda create --name envname_1 python=3.7
and in testing and installing some packages with conda I cloned the base environment a number of times to sequentially test whether the kernel keeps failing with
conda create --name envname_2 --clone envname_1
and so on. Regardless of the environment the problem persists. After activating the environment with
conda activate envname
asking "where python" within the environment initially correctly returns
C:\Users\user\miniconda3\envs\envname\python.exe
C:\Users\user\miniconda3\python.exe
and after calling the kernel in some jupyter-context and having it fail, "where python" from the command line returns just
C:\Users\user\miniconda3\python.exe
I am running on Windows 10 Home 64-bit (version 2004, OS build 19041.867), miniconda3 4.9.2 with base environment python 3.8.5 (the environment kernels tested have mainly been 3.7.x, but 3.8.x has not made a difference so far in testing). Miniconda is installed in my C:\Users\user\miniconda3 directory. (I'm not sure what other details would be helpful here).
So far I've tried:
Purging everything conda-related or python-related from my computer as completely as possible, by using 1) anaconda-clean and then removing the "envs" and "pkgs" folders separately before running the uninstall from standard conda. Miniconda is just the latest n-th reinstall after which the same issues persist.
Setting up a number of test environments in different ways and sequentially testing where the error occurs - seems to always be when activating the kernel one way or another
Removing all possibly related path variables prior to reinstalling
Removing all other python versions (which correctly started pointing python to the base environment - before this an additional problem was the each environment on the command line was attempting to point to my global python installation instead of either the base or environment kernels - this might be somehow related to what is going on here)
Trying all kinds of other little things related to jupyter-notebooks losing kernels within the notebooks, but mostly those have not been applicable since I cannot even use the command line after calling the kernel to work once.
Verified at each step when creating new environments that the environment kernel is correctly pointed to in the environment until calling it from jupyter or VS Code (+ jupyter lab seems to have the same outcome)
I'm a humble man and don't ask for much, would just like to keep working with isolated environments in the future as well. I'm not exactly a whiz when it comes to these things so I'm unsure where else I should be looking or what else I should be trying. Am starting to lose hope as I've been trying to figure this out for a good week now with nothing to show for it.
I hope I'm just being an idiot and overlooking something simple and obvious here since I've not managed to find any similar issues having been resolved. Regardless, any ideas on where I might look to next would be invaluable!
I'm still learning how this all works, so please bear with me.
I'm running conda 4.8.5 on my Windows 10 machine. I've already installed all necessary Jupyter extensions, I think (Jupyter Lab, Jupyter Notebook, Jupyter Book, Node.js, and their dependencies).
The problem might have to do with the fact that I've installed Miniconda on a separate (D:/) drive.
I've set up a virtual environment (MyEnv) with all the packages I might need for this project. These are the steps I follow:
Launch CMD window
$ conda activate MyEnv
$ jupyter-lab --notebook-dir "Documents/Jupyter Books"
At this point a browser tab opens running Jupyter Lab
From the launcher within Jupyter Lab, open a terminal
$ cd "Documents/Jupyter Books"
$ jb create MyCoolBook
New folder with template book contents gets created in this directory (Yay!)
Without editing anything: $ jb build MyCoolBook
A folder gets added to MyCoolBook called _build, but it doesn't contain much more than a few CSS files.
The terminal throws this error traceback which wasn't very helpful to me. The issue may be obvious to an experienced user.
I am not sure how to proceed. I've reset the entire environment a few times trying to get this to work. What do you suggest? I'm considering submitting a bug report but I want to rule out the very reasonable possibility that I'm being silly.
I asked around in the Github page/forum for Jupyter Book. Turns out it's a matter of text encoding in Windows (I could have avoided this by reading deep into the documentation).
If anyone runs across this issue just know that it can be fixed by reverting to some release, Python 3.7.*, and setting an environment variable (PYTHONUTF8=1) but this is not something I would recommend because some other packages might require the default system encoding. Instead, follow the instructions in this section of the documentation.
VS Code is unable to detect the torch package that I installed exclusively in one of the Conda environments. If I launch VS Code through Anaconda Launcher, however, then it detects torch and everything works fine.
I have done many things in order to make the Conda environment work on VS Code PowerShell terminal, and so far Conda is getting activated on VS Code terminal properly regardless of whether I launch it with or without the Anaconda Launcher. But when trying to run the the program via Code Runner, it always shows the error that the torch module is not found.
But doing the same thing in terminal or launching VS Code through Anaconda launcher works just fine.
I don't know what to do, it is so annoying. I really wanted to work with Python on VS Code as it looks neat and clean compared to other editors and also since it is also light and fast. Unfortunately, making Conda work on VS Code is a nightmare, and it seems like the only way to make it work is through launching it via Anaconda Launcher, but opening Anaconda Launcher takes too much time compared to VS Code -_-
Please help assist with launching the code through VS Code.
It's because conda activation sets various environment variables which are required for a conda environment to function appropriately. And I suspect the Code Runner extension simply doesn't understand the concept of a conda environment, and so it isn't doing any activating which makes the import search fail.
You can try executing code directly through the Python extension instead of Code Runner to see if that works better for you.
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.
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.