Issue
I am running some codes in the Jupyter Notebook and found this issue in my machine.
- When I execute "print(sys.version)" I got my python version that my jupyter kernel using is 3.8.2 which is as below.
- And when I execute "!python -V" I got another python version which is 3.9.1.
- When I type "!jupyter kernelspec list" I only have 1 python 3 for the jupyter kernel. (Ignored the TFOD which was my virtual env that I created for last project)
Or can refer the image below for the output.
However, in my machine, I only installed two python version which is 3.8 and 3.9 as below. And I am using 3.9 as my default.
I actually found the code "!python -m ipykernel install --user --name=Python_39" can solve my problem and let me created another kernel that using python 3.9.
But I still keen why this could happen and how to change(or add) the Jupyter Kernel that respective to the python that installed in my machine through appropriate way?
Because py3.9 is my active environment as I installed many libraries and wish to run on it rather than other (py3.8) version in the jupyter notebook.
Solution
It is not mentioned how you create your Jupyter notebook server, but I would suggest you do that from python's virtual environment
- This should activate an environment of python which when activated, gives you a consistent view of a specific python version and the dependencies (python libraries) you installed on this environment.
- when the virtualenv is activated, you can just use
python
instead ofpython3.x
as the activated virtualenv tells your shell to refer to its own version of python whenpython
is called. - if your jupyter is instantiated from a virtualenv, it will work with this specific python version - as it is the only one it knows.
- if your project already uses a venv, you can instantiate jupyter from it each time.
This is a snippet from what I would do on a linux shell:
// create a new venv:
shell# python3.9 -m venv ./myenv/
// activate the venv to operate on the shell:
shell# source ./myenv/bin/activate
// install jupyter to the venvs libraries
(myvenv) shell# python3.9 -m pip install jupyter
// run the jupyter server
(myvenv) shell# python -m jupyter notebook --port=8888 --no-browser --ip=0.0.0.0 --allow-root"
- The workspace\directories you see from your notebook will be the one you instantiated it in.
- you can access the jupyter notebook's user interface from your browser: http://127.0.0.1:8888
- You can also try this article or similar: https://www.codingforentrepreneurs.com/blog/install-jupyter-notebooks-virtualenv/
Answered By - TheRealDealidols
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.