How To Change Executable Path For A Jupyter Notebook Mac

Jupyter Notebook is an open-source web application that is used to create and share documents that contain data in different formats which includes live code, equations, visualizations, and text. Uses include data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and much more.

Jupyter has support for over 40 different programming languages and Python is one of them. Python is a requirement (Python 3.3 or greater, or Python 2.7) for installing the Jupyter Notebook itself.

Change Jupyter Notebook startup folder (Mac OS)¶ To launch Jupyter Notebook App: Click on spotlight, type terminal to open a terminal window. Enter the startup folder by typing cd /somefoldername. Type jupyter notebook to launch the Jupyter Notebook App The notebook interface will appear in a new browser window or tab. In the Jupyter terminal, sys.executable returns the same result as in my local terminal, and I can import all the same packages. HOWEVER, if I start a new Jupyter notebook from the same launcher, running side-by-side the functioning Jupyter terminal on the same server, sys.executable returns a DIFFERENT path (one that I thought I had deleted.

Refer to the following articles for the installation of the Jupyter Notebook.

In Jupyter everything runs in cells. It gives options to change the cell type to markup, text, Python console, etc. Within the Python IPython console cell, jupyter allows Python code to be executed.

Installing Python Library in Jupyter

Using ! pip install

To install Python libraries, we use pip command on the command line console of the Operating System. The OS has a set of paths to executable programs in its so-called environment variables through which it identifies directly what exactly the pip means. This is the reason that whenever pip command can directly be run on the console.

How To Change Executable Path For A Jupyter Notebook Mac

In Jupyter, the console commands can be executed by the ‘!’ sign before the command within the cell. For example, If the following code is written in the Jupyter cell, it will execute as a command in CMD.

Output

Similarly we can install any package via jupyter in the same way, and it will run it directly in the OS shell.

Syntax:

Example: Let’s install NumPy using Jupyter.

But using this method is not recommended because of the OS behavior. This command executed on the current version in the $PATH variable of the OS. So in the case of multiple Python versions, this might not install the same package in the jupyter’s Python version. In the simplest case it may work.



Using sys library

To solve the above-mentioned problem, it is recommended to use sys library in Python which will return the path of the current version’s pip on which the jupyter is running. sys.executable will return the path of the Python.exe of the version on which the current Jupyter instance is

Syntax:

Example:

How To Change Executable Path For A Jupiter Notebook Machine

By the above code, the package will be installed in the same Python version on which the jupyter notebook is running.

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

Recommended Posts:

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

How To Change Executable Path For A Jupiter Notebook Macbook Pro

Please Improve this article if you find anything incorrect by clicking on the 'Improve Article' button below.

How To Change Executable Path For A Jupiter Notebook Mac Os