Reputation: 7713
I already referred to this related post
Currently am using Jupyter Notebook
which has Python2
kernel only. But my server has both Python2 and Python3.
However, I would like to add python3
kernel. By following the above post, I tried the below
1 !mkdir python-virtual-environments && cd python-virtual-environments && virtualenv env && virtualenv -p python3 env && . env/bin/activate #activated virtual environment
2 !jupyter kernelspec list #lists only Python2 kernel
3 !which python3 # outputs the python3 path `/usr/bin/python3`
4 !pip install ipykernel # stream of requirement already satisfied messages
5 !python3 -m pip install ipykernel # error-1
6 !python3 -m ipykernel install --user # error-2
I get the below errors
error-1
Exception:
Traceback (most recent call last):
File "/usr/lib/python3.5/shutil.py", line 538, in move
os.rename(src, real_dst)
PermissionError: [Errno 13] Permission denied: '/usr/lib/python3/dist-packages/prompt_toolkit' -> '/tmp/pip-rgd7fgjj-uninstall/usr/lib/python3/dist-packages/prompt_toolkit
.....
PermissionError: [Errno 13] Permission denied: 'toolbars.py'
error-2
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.5/dist-packages/tornado-6.0.4.dist-info'
You are using pip version 9.0.1, however version 20.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
/usr/bin/python3: No module named ipykernel
Questions
When I activate the virtualenv
, all the commands that I execute after activation (line 2,3,4,5,6) are being run in my virtual env. Am I right?
line 4 has a stream of requirement already satisified messages. Am trying to install ipykernel
in my virtual environment. Why does it say it's already satisfied. Is it looking at my system installation because the message has python2.7.2?
Line 5, Why do I get permission denied
error?
Upvotes: 1
Views: 799
Reputation: 12837
The problem is that you're running everything from jupyter notebook using !
which starts a temporary shell for every command, thus all your commands are executed in a different shell. Hence, virtualenv is not activated, and you're getting requirements satisfied when you use pip
as it's checking system's python.
You need to use the terminal to activate virtual environement (though it can be done using jupyter, but a bit cumbersome):
From the terminal, first activate your virtualenv (which whould have python 3 as you mentioned it when you created this env (virtualenv -p python3 env
)):
. python-virtual-environments/env/bin/activate
It should show something like this (env) $
when activated, then if you check python and pip, it should give your env's python and pip.
(env) $ which python
home/abcd/python-virtual-environments/env/bin/python
(env) $ which pip
/home/abcd/python-virtual-environments/env/bin/pip
Now, you can install kernel if it's not already installed:
(env) ➜ pip install ipykernel
Upvotes: 1