Ask Your Question

Revision history [back]

One option: in any notebook where you want to use, for example, ImageMagick's binary "convert", first you have to find that file. On my machine it's in /usr/local/bin. Then add this to the notebook:

import os
os.environ['PATH'] += ':/usr/local/bin'

Another option is to add /usr/local/bin (or whatever directory is appropriate) to PATH for any notebook. You will need to create a Jupyter configuration file for this, and I can't see a way to do this while running Jupyter: you will have to use the Terminal. Locate the SageMath app; on my computer it is on my Desktop: it's /Users/palmieri/Desktop/SageMath-9-6.app. From the Terminal, do this, replacing the first part with the location of your SageMath app:

% /Users/palmieri/Desktop/SageMath-9-6.app/Contents/Frameworks/Sage.framework/Versions/9.6/venv/bin/ipython profile create

This will print a message along these lines:

[ProfileCreate] Generating default config file: '/Users/palmieri/.ipython/profile_default/ipython_config.py'
[ProfileCreate] Generating default config file: '/Users/palmieri/.ipython/profile_default/ipython_kernel_config.py'

Now edit either of these, I don't think it matters which one. These instructions come from @slelievre, via https://groups.google.com/g/sage-support/c/NiCkmMCEfd4/m/CqjM31Q3AgAJ. Find these lines:

## lines of code to run at IPython startup.
#  Default: []
# c.InteractiveShellApp.exec_lines = []

Replace the last line with

c.InteractiveShellApp.exec_lines = ["import os; os.environ['PATH'] += ':/usr/local/bin' "]

(Make sure to remove the "#" at the start: that's a comment character.)

One option: in any notebook where you want to use, for example, ImageMagick's binary "convert", first you have to find that file. On my machine it's in /usr/local/bin. Then add this to the notebook:

import os
os.environ['PATH'] += ':/usr/local/bin'

(The leading colon is important: PATH is a list of directories separated by colons. If you want this to be platform independent, then I guess you should use os.environ['PATH'] += os.pathsep + '/usr/local/bin': see https://docs.python.org/3/library/os.html#os.pathsep.)

Another option is to automatically add /usr/local/bin (or whatever directory is appropriate) to PATH for any notebook. You will need to create a Jupyter configuration file for this, and I can't see a way to do this while running Jupyter: you will have to use the Terminal. Locate the SageMath app; on my computer it is on my Desktop: it's /Users/palmieri/Desktop/SageMath-9-6.app. From the Terminal, do this, replacing the first part with the location of your SageMath app:

% /Users/palmieri/Desktop/SageMath-9-6.app/Contents/Frameworks/Sage.framework/Versions/9.6/venv/bin/ipython profile create

This will print a message along these lines:

[ProfileCreate] Generating default config file: '/Users/palmieri/.ipython/profile_default/ipython_config.py'
[ProfileCreate] Generating default config file: '/Users/palmieri/.ipython/profile_default/ipython_kernel_config.py'

Now edit either of these, these files, I don't think it matters which one. These instructions come from @slelievre, via https://groups.google.com/g/sage-support/c/NiCkmMCEfd4/m/CqjM31Q3AgAJ. Find these lines:

## lines of code to run at IPython startup.
#  Default: []
# c.InteractiveShellApp.exec_lines = []

Replace the last line with

c.InteractiveShellApp.exec_lines = ["import os; os.environ['PATH'] += ':/usr/local/bin' "]

(Make sure to remove the "#" at the start: that's a comment character.)