How to find out what works in a Jupyter laptop?

I use Jupyter notebook in a browser for programming in Python, I installed Anaconda (Python 3.5). But I am pretty sure that Jupyter manages my python commands with its own python interpreter, not with anaconda. How can I change it and use Anaconda as an interpreter?

Thanks!

Ubuntu 16.10 - Anaconda3

+25
source share
4 answers
import sys sys.executable 

will provide you with a translator. You can select the interpreter you need when creating a new laptop. Make sure the path to your anaconda interpreter is added to your path (most likely in your bashrc / bash_profile file).

For example, I have the following line in my .bash_profile:

 export PATH="$HOME/anaconda3/bin:$PATH" 
+34
source
 from platform import python_version print(python_version()) 

This will give you the exact version of Python your script is running on. e.g. output:

 3.6.5 
+27
source
  import sys print(sys.executable) print(sys.version) print(sys.version_info) 

See below: - output when I run JupyterNotebook outdoors CONDA

 /home/dhankar/anaconda2/bin/python 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jul 2 2016, 17:42:40) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] sys.version_info(major=2, minor=7, micro=12, releaselevel='final', serial=0) 

It can be seen below when I launch the same JupyterNoteBook in CONDA Venv created with the command -

 conda create -n py35 python=3.5 ## Here - py35 , is name of my VENV 

in my Jupyter laptop it prints:

 /home/dhankar/anaconda2/envs/py35/bin/python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:53:06) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0) 

also, if you already have different VENVs created with different versions of Python, you switch to the correct kernel by choosing KERNEL >> CHANGE KERNEL in the JupyterNotebook menu ... JupyterNotebookScreencapture

Also to install ipykernel in your existing CONDA virtual environment -

http://ipython.readthedocs.io/en/stable/install/kernel_install.html#kernels-for-different-environments

Source --- https://github.com/jupyter/notebook/issues/1524

  $ /path/to/python -m ipykernel install --help usage: ipython-kernel-install [-h] [--user] [--name NAME] [--display-name DISPLAY_NAME] [--profile PROFILE] [--prefix PREFIX] [--sys-prefix] 

Install the IPython kernel specification.

optional arguments: -h, - -h elp show this help message and exit --user Set the current user instead of the system-wide --name NAME Specify a name for the kernel specification. This is necessary to have multiple IPython cores at the same time. --display-name DISPLAY_NAME Specify a display name for the kernel specification. This is useful when you have multiple IPython cores. --profile PROFILE Specify the IPython profile to load. This can be used to create custom kernel versions. --prefix PREFIX Specify the installation prefix for the kernel specification. This is necessary for installation in a non-standard location, such as conda / virtual-env. --sys-prefix Install in Python sys.prefix. Shortcut for --prefix = '/ Users / bussonniermatthias / anaconda'. For use in conda / virtual-envs.

+10
source

Assuming you have the wrong backend system, you can modify the kernel backend by creating a new one or by editing the existing kernel.json in the kernels folder of your jupyter jupyter --paths data jupyter --paths . You can have multiple cores (R, Python2, Python3 (+ virtualenvs), Haskell), for example. you can create a specific Anaconda core:

 $ <anaconda-path>/bin/python3 -m ipykernel install --user --name anaconda --display-name "Anaconda" 

Create a new kernel:

<jupyter-data-dir>/kernels/anaconda/kernel.json

 { "argv": [ "<anaconda-path>/bin/python3", "-m", "ipykernel", "-f", "{connection_file}" ], "display_name": "Anaconda", "language": "python" } 

You need to make sure that ipykernel installed on the anaconda distribution.

That way, you can simply switch between the cores and have different laptops using different cores.

0
source

Source: https://habr.com/ru/post/1012480/


All Articles