Recently, I've been touching Python, but I've been struggling a little because there are too many new and old methods and various information on the net just to build the environment.
I made it using Conda, which seemed to be the best for building a virtual environment in Python, but when I tried to use it with Jupyter, which is popular recently, I was addicted to it because I could not switch the kernel of the virtual environment well. , I will leave a memorandum about how to do it.
If all goes well, you'll be able to instantly switch between development environments from Jupiter's [Kernel]-> [Change kernel] as shown below, which is quite convenient! !!
Conda and Jupyter installed
$ conda create -n numpyenv python=3.5 numpy jupyter
It is necessary to install jupyter even for the virtual environment to be created.
$ conda info -e
Using Anaconda Cloud api site https://api.anaconda.org
# conda environments:
#
numpyenv /Users/username/anaconda/envs/numpyenv
opencvenv /Users/username/anaconda/envs/opencvenv
py35 /Users/username/anaconda/envs/py35
root * /Users/username/anaconda
You can see that an environment called numpyenv has been created.
A package for switching kernels is provided on Jupyter, so install it.
$ pip install environment_kernels
$ jupyter notebook --generate-config
Probably ~/.jupyter/jupyter_notebook_config.py I think that the setting file called is generated.
Add the following to ~ / .jupyter / jupyter_notebook_config.py. ** (Note: may be old) **
c.NotebookApp.kernel_spec_manager_class = 'environment_kernels.EnvironmentKernelSpecManager'
c.EnvironmentKernelSpecManager.env_dirs=['/Users/username/anaconda/envs/']
** (* Addition: 2016/12/09) ** As you mentioned in the comments, in Latest version, it seems that only the following line is all right.
c.EnvironmentKernelSpecManager.conda_env_dirs = [ '/Users/username/anaconda/envs/' ]
For conda_env_dirs, check the path where the virtual environment is generated with conda info -e
etc. and set it appropriately.
$ jupyter notebook
When you start Jupyter, you can see that you can safely select a new kernel called numpyenv.
reference: [Python] Create a virtual environment with Anaconda Cadair/jupyter_environment_kernels Jupyter Notebook and Conda
Recommended Posts