How To Change Executable Path For A Jupyter Notebook Mac

Import sys sys.executable in my Python 3 console, the output is. Usrbinpython3 and I'm able to import whatever libraries I've installed with pip3, no problem. When I do so in my Jupyter Notebook running a Python 3 kernel, the output is. Usrbinpython and the libraries that I've.

  1. I was in the Jupyter Notebook properties to change the "Start In" location for my notebook. For some reason when I Applied my changes and tried to restart notebook, the program would give.
  2. Inside of that will be a shortcut called “Jupyter Notebook” Mac: It should create a shortcut on your desktop called “Launcher”. Open that, and inside will be a shortcut to the Jupyter Notebook; Jupyter Notebook will open in your home folder. (C:Users on Windows, /Users/ on Mac).
  3. Copy the Jupyter Notebook launcher from the menu to the desktop. Right click on the new launcher and change the Target field, change%USERPROFILE% to the full path of the folder which will contain all the notebooks. Double-click on the Jupyter Notebook desktop launcher (icon shows IPy) to start the Jupyter Notebook App.

3.1 Jupyter notebooks

This section will give you a brief overview of what a Jupyter notebook is and how to use them, but if you would like a more detailed understanding, please read the official documentation. Jupyter Labs has now been released as a newer version of notebooks, giving you a full IDE (integrated development environment) and more control over the notebooks and working environment. This guide will not explore these features, as we are more interested in how to use the notebook.

Note: throughout this section you can substitute the phrase “Jupyter notebooks” with “Jupyter Labs” if you would prefer to have a full IDE allowing you more control over the system.

Jupyter notebooks are run on Python, though additional things can be downloaded to allow you to use your programming language of choice. For an example of what you can do with Jupyter notebooks, click here, and here for a collection of neat and applied notebooks.

3.1.1 Installing Jupyter notebooks

Mac’s come shipped with a version of Python, but it is most likely outdated, and it doesn’t contain everything we want. In order to get running, I strongly recommend downloading the Anaconda distribution over other distributions, or even just directly from Python’s website. The instructions below will be enough to get you up and running with Jupyter notebooks in your language of choice.

  • Download the full Anaconda distribution i.e. not miniconda
    • Be sure to choose Python 3.x, not Python 2.x, as it’s the newer version and is forwards-compatible.
    • Be sure to only install for one user, not the whole system
    • Be sure to select Add Anaconda to my PATH environment variable under Advanced Options
    • Be sure to install Anaconda to the drive where your data lives. To do this you will need to manually edit the installation path within the Anaconda installer wizard, otherwise it will automatically end up in the C: drive
  • Use kernels to connect your programming language of choice with python and the notebook
    • To see how to get a particular language to work in Jupyter Notebooks, please click on the appropriate language:
Machine

3.1.2 Kernels

Jupiter

A kernel is program that allows the notebook to connect with, and run, your code. Jupyter comes with the Python code pre-installed, but if you want to use a different language, you will need to download a specific kernel.

Below, the installation instructions are described for common languages used in epidemiology. To see a full list of kernels available for Jupyter, along with the appropriate documentation and installation instructions, follow this link.

3.1.2.1 Installing the Stata kernel

The instructions for installing the stata_kernel are based from the original documentation here. It should work with Stata 12 (I have tested it). If these instructions do not work for you, it may be that there has been an update to the kernel, at which point, please refer to the original documentation linked above.

Open a command prompt (Windows) / terminal (linux/mac) and type/copy-paste the following commands, pressing enter after each line

  • pip install stata_kernel
  • python -m stata_kernel.install

Windows-specific steps

In order to let stata_kernel talk to Stata, you need to link the Stata Automation library:

Change
  1. In the installation directory (most likely C:Program Files (x86)Stata12 or similar), right-click on the Stata executable, for example, StataSE.exe (this will just show as StataSE, but is listed as an application). Choose Create Shortcut. Placing it on the Desktop is fine.
  2. Right-click on the newly created Shortcut to StataSE.exe, choose Properties, and append/Register to the end of the Target field. So if the target is currently 'C:Program FilesStata12StataSE.exe', change it to 'C:Program FilesStata12StataSE.exe' /Register (note the space before /). Click OK.
  3. Right-click on the updated Shortcut to StataSE.exe; choose Run as administrator.

3.1.2.2 Installing the SAS kernel

*This has not yet been tested here. The instructions for installing the sas_kernel are based from the original documentation here*

Open a command prompt (Windows) / terminal (linux/mac) and type/copy-paste the following commands, pressing enter after each line. First we need to install a dependency called saspy that helps the kernel connect SAS to python

  • pip install saspy
  • pip install sas_kernel
How to change executable path for a jupiter notebook macbook pro

You should now see something like this.

Now verify that the SAS Executable is correct

  • find the sascfg.py file – it is currently located in the install location (see above) [install location]/site-packages/saspy/sascfg.py. To query pip for the location of the file, type pip show saspy. Failing that, this command will search the OS for the file location: find / -name sascfg.py
  • edit the file with the correct path the SAS executable and include any options you wish it include in the SAS invocation. See examples in this file

3.1.2.3 Connecting R with Jupyter

If you are hoping to make nice documents and reproducible work using R, I would highly recommend that you use the R Markdown or R Notebook through RStudio application instead. However, if you would prefer Jupyter, then please read on.

It is possible to download an R kernel, much like for Stata and SAS, but it can be a bit fickle, so a different approach is described below. It is important to note that with this method you are installing a fresh version of R, so you will not have access to the packages you have previously installed - you will need to reinstall them in this R environment, which could be done within a Jupyter notebook.

Open a command prompt (Windows) / terminal (Linux/Mac) and enter the following commands:

  • conda install r-essentials r-igraph
  • Rscript -e 'install.packages('languageserver')'

If you would rather install an R kernel than a fresh install of R within the Anaconda distribution, you can follow the instructions here. The advantage of this is that it allows the notebook to access previously installed packages as they are not running off a fresh version of R.

How To Change Executable Path For A Jupyter Notebook Mac

3.1. Launching Jupyter Notebook App

The Jupyter Notebook App can be launched by clicking on the Jupyter Notebookicon installed by Anaconda in the start menu (Windows) or by typing ina terminal (cmd on Windows):

This will launch a new browser window (or a new tab) showing theNotebook Dashboard, a sort of control panel that allows (among other things)to select which notebook to open.

When started, the Jupyter Notebook App can access only files within its start-up folder(including any sub-folder). No configuration is necessary if you place your notebooksin your home folder or subfolders.Otherwise, you need to choose a Jupyter Notebook App start-up folder which will containall the notebooks.

See below for platform-specific instructions on how to startJupyter Notebook App in a specific folder.

3.1.1. Change Jupyter Notebook startup folder (Windows)¶

  • Copy the Jupyter Notebook launcher from the menu to the desktop.
  • Right click on the new launcher and change the Target field, change %USERPROFILE% tothe full path of the folder which will contain all the notebooks.
  • Double-click on the Jupyter Notebook desktop launcher (icon shows [IPy]) to start theJupyter Notebook App. The notebook interface will appear in a new browser window or tab.A secondary terminal window (used only for error logging andfor shut down) will be also opened.

3.1.2. 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/some_folder_name.
  • Type jupyternotebook to launch the Jupyter Notebook AppThe notebook interface will appear in a new browser window or tab.

3.2. Shut down the Jupyter Notebook App

Closing the browser (or the tab) will not close theJupyter Notebook App. To completely shut it down you need toclose the associated terminal.

In more detail,the Jupyter Notebook App is a server that appears in your browserat a default address (http://localhost:8888).Closing the browser will not shut down the server.You can reopen the previous addressand the Jupyter Notebook App will be redisplayed.

You can run many copies of the Jupyter Notebook App and they will showup at a similar address (only the number after “:”, which is the port,will increment for each new copy).Since with a single Jupyter Notebook App you can already open many notebooks,we do not recommend running multiple copies of Jupyter Notebook App.

3.3. Close a notebook: kernel shut down¶

When a notebook is opened, its “computational engine” (called the kernel)is automatically started.Closing the notebook browser tab, will not shut down the kernel,instead the kernel will keep running until is explicitly shut down.

To shut down a kernel, go to the associated notebookand click on menu File -> Close and Halt. Alternatively, the Notebook Dashboardhas a tab named Running that shows all the running notebooks (i.e. kernels)and allows shutting them down (by clicking on a Shutdown button).

3.4. Executing a notebook¶

Download the notebook you want to execute and put it in yournotebook folder (or a sub-folder of it).

Then follow these steps:

  • Launch the Jupyter Notebook App (see previous section).
  • In the Notebook Dashboard navigate to find the notebook:clicking on its name will open it in a new browser tab.
  • Click on the menu Help -> User Interface Tour for an overviewof the Jupyter Notebook App user interface.
  • You can run the notebook document step-by-step (one cell a time) by pressingshift + enter.
  • You can run the whole notebook in a single step by clicking on the menuCell -> Run All.
  • To restart the kernel (i.e. the computational engine), click on the menuKernel -> Restart. This can be useful to start over a computation fromscratch (e.g. variables are deleted, open files are closed, etc…).

More information on editing a notebook:

  • Notebook Basics(or alternate link)

Note

Save notebooks: modifications to the notebooks are automatically saved everyfew minutes. To avoid modifying the original notebook, make acopy of the notebook document (menu File -> Make a copy …) andsave the modifications on the copy.

Warning

Pay attention to not open the same notebook documenton many tabs: edits on different tabs can overwrite each other!To be safe, make sure you open each notebook document in only one tab.If you accidentally open a notebook twice in two different tabs, justclose one of the tabs.

How To Change Executable Path For A Jupiter Notebook Machine

More info on the Jupyter Notebook App environment see References.