I was working for two projects these
days. One project needs cuda8.0 and python3.5, while the other
depends on cuda9.1 and python2.7. As usual, I
used Jupyter notebook to write code. This article records the
process to configure Jupyter notebook to support two different
kernels and environments.
1. Install
Jupyter
No matter which version of
python have you installed, use following command to install
Jupyter:
python -m pip install
jupyter or pip install jupyter.
2. Install both cuda8.0 and
cuda9.0
Since I have installed cuda8.0,
I just need to add cuda9.0 onto system.
So,
download cuda_9.0.176_384.81_linux.run from the
linkhttps://developer.nvidia.com/cuda-90-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1604&target_type=runfilelocal,
install it.
During installing process, you
must answer several questions. Since you have
already installed cuda8.0, you must say "no" for questions
" Install NVIDIA Accelerated
Graphics Driver for Linux-x86_64 384.81?" and "Do you want to install a
symbolic link at
/usr/local/cuda?".
Say "yes" for question
"Install the
CUDA 9.0 Toolkit"
3. Prepare two virtual environments, one for
cuda8.0 and python3.5, another for cuda9.0 and
python2.7;
Just run commands
"virtualenv
-p /usr/bin/pythonx.xenvn" to create
a environment for pythonx.x. The tricks to link
this environment to a special version
of cuda is to set the "PATH" and
"LD_LIBRARY_PATH" to the corresponding directories. for example, if
you are going to use cuda8.0 in env1, you must add "export
PATH=/usr/local/cuda-8.0/bin:$PATH" , "export
LD_LIBARAY_PATH=/usr/local/cuda-8.0/lib64" and "export
CUDA_HOME=/usr/local/cuda-8.0" to its activate script. When you run
source ./activate at the bin directory of this environment, it will
take effect.
for example, I established a development
environment forfastai
as follow:
wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
bash Anaconda3-5.0.1-Linux-x86_64.sh -b
--running the shell above will create a virtual environment base on anaconda3---
Then I modified the environment variable as following commands:cd
echo '#!/bin/sh' >> enter_env
echo 'export PATH=~/anaconda3/bin:$PATH' >> enter_env
export PATH=~/anaconda3/bin:$PATH
export PATH=/usr/local/cuda-9.0/bin:$PATH
echo 'export PATH=/usr/local/cuda-9.0/bin:$PATH'
>>enter_env
export
LD_LIBARAY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH
echo 'export
LD_LIBARAY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH'
>>enter_env
export
CUDA_HOME=/usr/local/cuda-9.0
echo 'export
CUDA_HOME=/usr/local/cuda-9.0'
>>enter_env
echo 'source activate envname' >> enter_env
jupyter notebook --generate-config
echo "c.NotebookApp.ip = '*'" >> ~/.jupyter/jupyter_notebook_config.py
echo "c.NotebookApp.open_browser = False" >> ~/.jupyter/jupyter_notebook_config.py
pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension --sys-prefix
python
-m pip install ipykernel
ipython kernel install --name
envname
Enter environment envname as
following:
cd
source activate envname
source deactivate
cd
Use " virtualenv -p
/usr/bin/python2 env2" to create next environment
"env2"
source ~/env2/bin/activate env2
python -m pip install ipykernel
ipython kernel install --name env2
4. install some python module
pip install bcolz
pip install opencv-python
pip install graphviz
pip install sklearn_pandas
pip install isoweek
pip install pandas_summary
pip install torch torchvision
pip install torchtext