为Jupyternotebook配置多个内核_wizard_新浪博客

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 link https://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.x  envn" 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 for  fastai as follow:
 
  
 
  
 
  
 
  
 
  
 
  
 
  

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
 
 
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





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值