I have multiple kernels in my notebook, but when changing the kernel it doesn't really change it and still run the original kernel (which I first open the notebook with).
For example, I run the notebook with python 3.6 environment, but when changing the kernel to python 2.7 it stayed with python 3.6.
I'm changing the kernels via jupyter GUI (kernel -> change kernel) and check the path of python using:
!which python
In all environments I installed ipykernel but it doesn't matter which kernel I'm choosing, the path stayed the same (the path of the original kernel which I used to run the notebook).
I had the same issue, launching jupyter from the terminal after activating the environment worked for me, I followed the steps as below:
Open anaconda prompt
Activate environment with conda activate EnvName
Launch jupyter with jupyter lab
Related
I installed Anaconda and Jupyter lab in "base" environment.
And, I made new environment named "RLRC_Sensor",
then setted ipykernel in "RLRC_Sensor" for using Jupyter lab in "base" environment.
I made new notebook file with "RLRC_Sensor" kernel, (not base)(Jupyter lab is running on "base")
When I use shell command, it's still working on "base"
but code is running on "RLRC_Sensor" environment.
(you can see, "!conda env list" is working on "base")
It makes problem when i use "!pip install something",
it is installed on "base", not environment of kernel.
When I check on vscode with jupyter extension,
shell command works on "RLRC_Sensor" well.
I want to fix to run shell command also work with environment on Jupyter. What should I do?
I'm appreciated to read this problem.
I have a python project (folder) that I'm working on in VS Code (in Windows) and it uses Jupyter notebook. The project uses a virtual env. It was working fine a few days ago. Today when I open up one of the .ipynb files in the project, I see:
Running cells with 'Python 3.9.12 64-bit' requires ipykernel package.
Run the following command to install 'ipykernel' into the Python
environment. Command:
'c:/Users/myName/AppData/Local/Programs/Python/Python39/python.exe -m
pip install ipykernel -U --user --force-reinstall'
I don't understand why VS Code is looking at the system installation of python. I have the following in settings.json in the .vscode subfolder of this project:
{
"python.pythonPath": "proj_env\\Scripts\\python.exe",
"python.terminal.activateEnvironment": true
}
And in the virtual environment for this project, I have confirmed I have ipykernel installed. It was working fine a few days ago. I see that ipykernel was updated 10/31/2022, so just to try it, I updated the ipykernel package in the virtual env from 6.15.2 to 6.17.0.
But clearly for some reason VS Code is looking to the system installation of python instead of the virtual env.
Pulling my hair out because I changed nothing in the past few days. In fact I just opened the project today for the first time since a few days ago when it was working fine.
When I press CTRL+SHIFT+P to select python interpreter, the virtual env python interpreter is already selected. But I still see the warning posted above re: ipykernel package needing to be installed.
Where am I going wrong?
Here's my attempt at an explanation of the solution. I'm sure someone understands this better and can explain it better (please do and I will pick your answer as the solution!):
VS Code uses one python interpreter for .py files and terminal and a different python interpreter for Jupyter notebook (.ipynb) files. The kernel I wanted wasn't there, and it was using the system installation of python, which is why I was getting this message (ipykernel not installed to system environment, and I don't want it there), while the virtual env python (which has ipykernel) was being used for .py and terminal in the same project, hence the confusion.
To 'install' the kernel for Jupyter, I activated the virtual env in VS Code powershell terminal. Then ran:
python -m ipykernel install --user --name=project_name
Then exit VS Code, restart, open project folder and in upper right corner of Jupyter notebook, use the kernel picker to select the kernel. The kernel I just created wasn't there, so I used CTRL+SHIFT+P in VS Code, then type Jupyter: Filter Kernels, and there I could see the kernel I created, and it was checked, then went back to kernel picker and was able to select the correct kernel.
So now the .ipynb code has access to all the packages installed in this virtual environment.
One annoyance is VS Code doesn't 'remember' that this is the kernel I want for this project, so I have to select the kernel each time I open this project. I'm sure there's a solution for this, but I'll have to look for that later.
I located a really weird behavior of Jupyter and caused me to reinstall it but the problem persisted.
I have a Windows machine where I have installed anaconda (the latest version). There are two environments:
(base) Which contains nothing special maybe seaborn pandas etc. and is on python version 3.8.12.
(tf-gpu) Which contains tensorflow-gpu and is on python version 3.9.7.
Mind you, these two environments are created directly from a fresh installation of anaconda, and I didn't touch anything except installing tensorflow-gpu.
When I launch Jupyter through Anaconda, it launches normally on the home folder "C:\User\user" for both environments i.e. correct packages installed and correct version of python on both. I can also launch an instance of Powershell through Anaconda or Windows, (always in home dir), and launch Jupyter both environments behave as they should (packages, python version). So far so good...
The problem starts when I want to launch Jupyter from a directory other than home dir. I keep all my project files in a separate partition (D:), thus I navigate to that directory through a cmd/powershell (launched through Anaconda or Win) and type "jupyter notebook". The notebooks open on that director and:
When the base env is selected the notebook reports a correct name "base"(os.environ['CONDA_DEFAULT_ENV']) and python version 3.8.12 (sys.version_info). Everything behave as base env was setup.
When the tf-gpu env is selected the notebook reports a correct name "tf-gpu" but I get a python version 3.8.12, which is completely wrong! It should be 3.9.7. I can't import tensorflow since I get an error. Essentially I am in the base env without knowing it.
I then check in the same cli window (tf-gpu) that launched jupyter and python --version reports 3.9.7 and of course can import tf run it etc.
Jupyter just reports the environment name but in reality it uses the base environment even though it launched from said env. How can this change?
Why does Jupyter works normally when launched from the user directory?
If this is not solved easily, what is a workaround? Jupyter doesn't recognize symbolic links, and thus I can not navigate to another directory if it is not a subdirectory of home.
Finally, I also tried adding the env as kernel through python -m ipykernel install --user --name tf-gpu --display-name "Tensorflow GPU (tf-gpu)", but it doesn't seem to change a thing.
Update 1:
Of course I activate the tf-gpu through conda activate tf-gpu and check the python version and tensorflow (correct results), the problem is when launching jupyter notebook. The notebook reports the tf-gpu env but wrong python version and tf is missing.
Update 2:
After some searching around it seems that jupyter notebook has much trouble selecting a python version if multiple versions of python are installed in the system (in my case 2, 1 on each environment environments). Which is ridiculous if you think that that's why we are using environments for...
The reason you are having this problem I’m guessing is because your launched jupyter notebook from your conda base environment. You will see a (base) in your comment prompt.
To remedy this, When you use the command prompt to launch, do conda activate tf-gpu before you launch Jupyter notebook, now check if your versions are correct.
What I did and worked was run ipython3 notebook in the environment which launched the notebook server and everything was working properly correct environment name and correct python version and packages (tensorflow is working as it should). This must have updated some configuration files since I can now run jupyter notebook from a different folder and the gpu-tfu env works correctly.
Please remember that these problems were occurring only if I was launching jupyter outside the home directory (C:\User\user) on a different partition. Also keep in mind that this is a Windows installation and more complicated things may be happening with user paths, environments, etc than in linux.
I wanted to run jupyter notebook with python: 3.7.10 so I created a virtual env and activated it using anaconda. Then when I run Jupyter notebook, it still uses python 3.8.8. How can I change the python version used by jupyter notebook?
Thank you for your help in advance.
You have probably typed jupyter notebook in the command prompt and it opened.
Actually jupyter and notebook are two modules that you need to install on your virtual environment. So that you can leverage jupyter notebook from that environment.
In your case since you didn't had them it started from the one having.
Now the way I suggest to start jupyter from a particular environment is from the navigator itself as shown in the figure below.
Select your environment and then install and launch jupyter notebook.
If it doesn't work you can try integrating conda with jupyter notebook and run your environment directly from jupyter notebook using the package nb_conda. Check this 4 min video youtu.be/Ro9l0eapoJU for the process.
I tried to install Hydrogen into ATOM, but get No Kernel Specs found error.
I installed jupyter notebook via anaconda and previous ran a "conda install jupyter" in anacoda prompt.
Is it a python file you’re trying to run?
In terminal what does jupiter kernelspec list —json give you?
If you open a Jupiter notebook can you open a python notebook and run that in a kernel? In terminal jupyter notebook, then select python from new on top left of home page of jupyter.
Is the grammar for that file python or do you have magic python or something else installed? If there is a different grammar you will need to map in hydrogen settings, eg for magic python: {“python”: “magicpython”}