Trouble in jupyter notebook running by line (f10) with VS Code - python

Problem:
When I try running code by line (f10) with VS Code, "ipykernel setup required for this feature" message pops up.
What I've tried:
Using Anaconda Prompt: "conda install ipykernel", "conda install -c conda-forge ipykernel"
-When I tried this, the prompt said "conda-forge:: ipykernel-6.4.1-py38h595 --> pkgs/main:: ipykernel-6.2.0-py38haa95532_1"
Doesn't it mean I already install ipykernel v.6.20 or higher?
After I tried this I checked Jupyter --Version it said ipykernel 5.3.2
Other specs are qualified. (VS Code, Jupyter, Anaconda versions etc,)
Using Terminal (in VS Code): "pip install ipykernel"
Reinstalling all of add-ins such as Python for VS, Python, Anaconda, Jupyterlab, VS Code
Updating ExecutionPolicy: CurrentUser-RemoteSigned, LocalMachins-AllSigned, others Undefined.
+) Created virtual-env named envi which is conda env. In VS Code I selected this interpreter and also reloaded all windows.
As I understand, Conda install Ipkkernel > Reload is what pop-up msg required.
This is what I'm going through now.. I just got interested in Python and now I cannot doing anything..

I had the same problem. It seems there was a problem with the version of ipython or ipykernel since I managed to fix it by running the following commands in conda environment:
pip install --upgrade ipython
pip install --upgrade ipykernel
Don't know which of the two was the problem but I was able to use the jupyter notebook line-by-line feature after this.

Related

Unable to start jupyter notebook in visual studio code

I am trying to make a jupyter notebook in visual studio code but I keep getting this:
''Unable to start session for kernel Python 3.8.3 64-bit ('Lenovo':
virtualenv). Select another kernel to launch with.''
I have anaconda installed and the jupyter notebook works fine in the anaconda navigator. I also tried to use python 3.8.3 base:'conda' but it didnt work. I'm using windows 10
This issue also occurs on my computer. The solution is to restore the version number of a dependency package "traitlets" of ipython kernel to 4.3.3.
You could try to use "pip list" to view the version of the module "traitlets" in the current virtual environment. If it shows version 5.0, it is recommended that you use version 4.3.3.
You could reinstall "traitlets 4.3.3" with the following command:
python -m pip install 'traitlets==4.3.3' --force-reinstall
If this command is not available, you could use 'pip' to uninstall traitlets5.0 (pip uninstall traitlets) and then use 'pip' to install traitlets4.3.3.(pip install traitlets==4.3.3)
Reference: Unable to start session for kernel Python.
I had the exact same problem. Fix it by uninstalling the Python extension that is linked to that error message.
If you are using conda to manage your Python environments, activate your target environment at a command prompt, then enter the following:
$ conda install traitlets=4.3.3
This solved the problem for me.

Unable to start Jupyter notebook on VS Code

(Using latest miniconda + VS Code on 64-bit Windows10:) After clean reinstalling VS Code, I can no longer launch jupyter notebook from within it. When I tried to create a new jupyter file for the first time, the Python extension installed ipykernel in my virtual environment "da38" (my main working environment). Then it stays on Connecting to IPython kernel: Connecting to kernel for an unusually long time, and stops with the error message Unable to start session for kernel Python 3.8.5 64-bit ('da38':conda) (images pasted below). I also removed and re-created da38 environment just in case. Used jupyter many times before with no issues until this new VS Code install today, and an identical setup is working on my other computer. Any help is appreciated. Thanks!
I had the latest version and below command worked for me
python -m pip install 'traitlets==4.3.3' --force-reinstall
This issue also occurs on my computer. The solution is to restore the version number of a dependency package "traitlets" of ipython kernel to 4.3.3.
You could try to use "conda list" to view the version of the module traitlets in the current conda environment. If it shows version 5.0, it is recommended that you use version 4.3.3.
Reference: Unable to start session for kernel Python.
I had this same problem. What worked for me is updating ipykernel.
$ pip install ipykernel --upgrade
I also did a few other upgrades just in case.
$ pip install traitlets --upgrade
$ pip install notebook --upgrade
I did not role back to an older version like 'traitlets==4.3.3'.
If anyone facing same issues now, Can check below steps which helped me to solve this
Update and Restart VS code
Install latest Jupyter Extension from Extensions.
We need to update "ipykernel" and restart VSC:
pip install ipykernel --upgrade

Can't install python packages for a conda environment

I could use some clarification regarding anaconda envs and the installed packages. I have just began using environments other than the base to keep my installations clean.
I just deleted my anaconda3 folder, installed it from scratch, made a new environment and tried to run a jupyter-notebook.
When reading excel via pandas I get the error Missing optional dependency 'xlrd'
prompting me to install xlrd via conda or pip.
So I open the terminal, activate the env I’m working in and install it using conda. I close the JN from the terminal, reopen it and run the same code. The problem persists.
I repeat the procedure, this time indicating the name of the env at the end. Problem persists.
I checked which python in the terminal, it is indeed the anaconda3/envs/newenv/bin/python
I do the same (in the new env) using pip. I use the command .../anaconda3/envs/newenv/bin/python -m pip install xlrd. I get the message Requirement already satisfied: xlrd in ./anaconda3/envs/newenv/lib/python3.7/site-packages (1.2.0).
I even tried installing the package inside the notebook using !conda install xlrd, still I get the same error.
Finally, I open Jupyter via the base env, and the package works there perfectly.
I have no idea why I can’t install this under the newenv, which was the point of having local envs after all.
Thanks heaps for your help!
You need to install the kernel in Jupyter to be able to use it.
jupyter kernelspec list
That command will give you the list of kernels you have. I am assuming it only shows you Python3
You will now need to install a kernel. Remember to do this while inside your virtual environment
python3 -m pip install ipykernel
python3 -m ipykernel install --user --name <your-new-kernel-name>
You should now see this in Jupyter notebook. Select the kernel in Jupyter and you should be good to go.
Another thing you may want to try is to install Jupyter while inside your virtual environment. While inside your virtual environment, you could do:
python3 -m pip install jupyter lab
and then while still inside your virtual environment, run jupyter after checking which jupyter. It should solve your problem as well.

Can't run Python code in Visual Studio Code with Jupyter - "Jupyter kernel cannot be started from 'Python 3.6.8 64-bit"

I've installed Jupyter extension in the latest Visual Studio:
Visual Studio 1.3.01 64
Jupyter 1.1.4
As I am using tensorflow I need Python 3 64bit.
When I try to run simple code I get:
Jupyter kernel cannot be started from 'Python 3.6.8 64-bit ('tensorflow64': virtualenv)'. Using closest match Python 3.7.0 32-bit instead.
Code:
#%%
import tensorflow as tf
session = tf.Session()
hello = tf.constant("Hello from Milan.")
print(session.run(hello))
a = tf.constant(20)
b = tf.constant(22)
print('a + b = {0}'.format(session.run(a + b)))
All works fine if I Run code not using Jupyter from VS Code.
Message from Jupyter is not the best description of the issue, missing ipykernel package.
Fix was to install additional python package 'ipykernel' into virtual environment with Python 3.64 bit.
pip install ipykernel
Additional info:
https://github.com/Microsoft/vscode-python/issues/3579
conda create --name test_env
conda activate test_env
conda install -c anaconda ipykernel
python -m ipykernel install --user --name=test_env
Or this You can run this it might work
ipython kernel install --user --name=ENVNAME
Simple installation is the best. While learning Python et-all I had installed many things in many different ways. It was a mess. Removed everything and did a fresh install only I used pyenv and pipenv. However pipenv does not work with the latest version which you can install using brew. Solution revert back to version 2018.10.13 using pip install. Then I discovered that pipenv was no longer recommended so, I removed it. Built a test project and could not get jupyter to run. Spent all day trying everything.
Solution was, remove the old version of pipenv and install the latest using brew. All is well.
However, I do like the features of pyenv like setting global etc.
You have to select and save the .ipynb file with VSCode indicating a kernel that is reachable from your Jupyter installation:
In my case installing anaconda and call following comments solves it:
conda create -n tf tensorflow
conda activate tf

python, anaconda, Spyder -- uninstalling python package using pip DOES NOT work in Spyder + ipython

By using pip, I can successfully install new packages in ipython running in the Spyder environment. All I need to run is this:
!python -m pip install mypackage
However, trying to uninstall packages doesn't seem to work, at all. When I run:
!python -m pip uninstall mypackage
The console goes into a state of hanging. It's not strictly 'hanging' because neither Spyder nor the console hangs but the command just isn't returning anything
I am attaching a screenshot to help explain what I mean. The screenshot shows what happens AFTER I have pressed ENTER on this line - and nothing happens!
Does anything know why?
You should not use pip with Spyder. It can break your whole distribution. Spyder is part of the Anaconda package and you should use the conda command instead of pip. The conda command works similar to the pip command. Instead of pip install package you'd use conda install package.
(Spyder maintainer here) Both pip and conda are not meant to be run inside one of our IPython consoles because they expect to be running in a real system terminal (xterm, Terminal.app or cmd.exe).
In this case, pip expects input from the user (the confirmation that he/she really wants to uninstall a package). That confirmation can't be displayed in our consoles and it makes it looked like its blocked.
What you could do is to pass the -q option to pip to avoid confirmation. But in general it's a very bad idea to use pip and conda inside our consoles for the reasons I stated above.
I have a windows 10 64 bit machine, i installed spyder with pip and it could not work. so to uninstall i just used this command
pip uninstall spyder
however, if spyder has been installed with alongside Anaconda, Uninstalling Anacanda will delete its all packages including spyder.

Categories