6

I downloaded SageMath-9.2 on my mac, but every time I try to use the notebook

by running "sage -n jupyter" on my terminal

I get the following massage:

Please wait while the Sage Jupyter Notebook server starts... 
Traceback (most recent call last): 
    File "/Applications/SageMath-9.2.app/Contents/Resources/sage/local/lib/python3.8/site-packages/sage/repl/ipython_kernel/install.py", line 307, in have_prerequisites 
        from notebook.notebookapp import NotebookApp 
    File "/Applications/SageMath-9.2.app/Contents/Resources/sage/local/lib/python3.8/site-packages/notebook/notebookapp.py", line 66, in 
        from tornado import httpserver 
    File "/Applications/SageMath-9.2.app/Contents/Resources/sage/local/lib/python3.8/site-packages/tornado/httpserver.py", line 29, in 
        import ssl 
    File "/Applications/SageMath-9.2.app/Contents/Resources/sage/local/lib/python3.8/ssl.py", line 98, in
        import _ssl # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'

The Jupyter notebook requires ssl, even if you do not use https. Install the openssl development packages in your system and then rebuild Python (sage -f python3).

And also I can't open the app either for some reason ..... every time I click on the app I get a small window saying :

Jupyter Server failed to start 
For some reason the Jupyter server failed to start. Please check the log for clues, and have that information handy when asking for help.

I hope for some help, its very important for me because I must use SageMath for my college project.. thanks in advance

Danoram
  • 8,132
  • 12
  • 51
  • 71
Safa Amasha
  • 63
  • 1
  • 5
  • The version of the SageMath I am trying to use is 9.2 , and I am using Python 3.8.5 – Safa Amasha Nov 14 '20 at 21:31
  • Welcome to Stack Overflow! You can edit your question at any time. Better to put additional information in the question itself. – CryptoFool Nov 14 '20 at 22:27
  • 1
    It's really strange that you get that error. Maybe the problem isn't what is implied...that either the 'ssl' or '_ssl' module can't be imported. I say this because I just installed Python 3.8 for the first time on my Mac, and `import ssl` and `import _ssl` work straight out of the box! - I'd suggest that you check to see if those imports work for the version of Python you're trying to use. If not, maybe you should either reinstall that version or use and possibly install another one. – CryptoFool Nov 14 '20 at 22:54
  • @Steve I have paython 3.8.5, and looks that import ssl isn't there,do you have any idea how to download the version you are using? – Safa Amasha Nov 15 '20 at 08:26
  • 1
    I used [Homebrew](https://brew.sh/) to install 3.8 and 3.9. I install anything I can with Homebrew. It has never let me down. I don't know why those packages are or aren't in any particular version of Python. In fact, I don't know 100% for sure that my system isn't picking up one version of the `ssl` library that I installed globally somehow. My experience, however, is that each Python install stands alone in terms of modules. If that's true, then my 3.9 definitely came with these modules, because I had just installed it and hadn't done anything with it yet when this question came up. – CryptoFool Nov 16 '20 at 01:49
  • 1
    I use `pyenv` to manage all my Python versions. If you need any info or help with that tool, I've figured out a few things about it through some pain, and would be glad to help you to avoid the same. – CryptoFool Nov 16 '20 at 01:53
  • thank you so much.. – Safa Amasha Nov 18 '20 at 22:56

1 Answers1

5

On macOS Big Sur, there are several ways to install SageMath

Sage can also be used online using

The installation you currently have was downloaded as a macOS app, which ships its own Python which lacks the SSL module (for licence reasons).

To repair it:

  • change to the Sage directory
  • optionally get the latest development version
  • set number of jobs to run in parallel
  • get rid of that Sage's Python
  • configure
  • optionally follow the brew install recommendations at the end of configure
  • make
$ DIR=/Applications/SageMath-9.2.app/Contents/Resources/sage
$ cd $DIR
$ git checkout develop
$ git pull origin develop --tags
$ MAKE='make -j8'
$ V=0
$ source .homebrew-build-env
$ make -s V=0 python3-clean
$ make -s V=0 configure
$ ./configure
$ make -s V=0

The other way to solve your problem is to use the SageMath Jupyter kernel provided by Sage with your system-wide Jupyter (eg as installed via Homebrew).

This should achieve that goal:

$ SAGE_LOCAL=`sage -c 'print(SAGE_LOCAL)'`
$ SAGE_KERNEL=$SAGE_LOCAL/share/jupyter/kernels/sagemath 
$ KERNELS=$HOME/Library/Jupyter/kernels
$ ln -s $SAGE_KERNEL $KERNELS
Samuel Lelièvre
  • 3,212
  • 1
  • 14
  • 27
  • if you are using M1 macos, you should modify the first line of .homebrew-build-env from 'brew --prefix' to '/usr/local/Homebrew/bin/brew --prefix' to use everything in x64_64 rather than arm64 – lispc Feb 08 '21 at 13:00
  • Thank you! I went with the last suggestion (after installing sage with homebrew). I have been trying to do this for hours and this is the only thing that worked for me. – Mishalb Feb 26 '21 at 14:22