Ask Your Question
1

Sagemath calling Python 2.7 even though I have 3.8.8 installed.

asked 2021-08-25 13:35:26 +0100

keshav gravatar image

updated 2021-08-26 09:55:41 +0100

FrédéricC gravatar image

I am working on Macbook and I recently installed sagemath using dmg. I have been working with anaconda for some time and I have installed many modules with it. Sagemath is running fine with jupyter notebook, but it is calling python 2.7instead of 3.8.8 because of which I am not able to access those modules. Any ideas on how to fix this problem?

edit retag flag offensive close merge delete

Comments

FrédéricC gravatar imageFrédéricC ( 2021-08-25 17:15:15 +0100 )edit

Yes, I downloaded the latest release from there, which is v9.4 .

keshav gravatar imagekeshav ( 2021-08-25 18:34:23 +0100 )edit

What do you mean by "it is calling python 2.7"? Can you provide more details?

John Palmieri gravatar imageJohn Palmieri ( 2021-08-26 03:49:15 +0100 )edit

I mean that the sage kernel is using Python 2.7 from the root as the interpreter, but I want to use 3.8. So how do I make sage kernel use 3.8 .

keshav gravatar imagekeshav ( 2021-08-26 05:00:40 +0100 )edit
1

I can't reproduce this. When I download SageMath-9.4.dmg from the 3-manifolds page, it uses Python 3.9.5, whether I use the command line interface or Jupyter. How do you know it's running 2.7? Is this from the command line and you're seeing 2.7 in the banner? Or is it with the notebook?

John Palmieri gravatar imageJohn Palmieri ( 2021-08-26 06:41:48 +0100 )edit

2 Answers

Sort by » oldest newest most voted
3

answered 2021-08-26 23:29:26 +0100

(a) To check the version of Python being used, evaluate these commands:

import sys
sys.version

(b) The SageMath app is self-contained and won't interact with conda installations or other packages on your system. Installing arbitrary packages with the MacOS SageMath app does not seem to be supported: see https://github.com/3-manifolds/Sage_m..., for example.

Installing a pip package like nltk should work, though. You have to do (from a Terminal window):

/path/to/SageMath-9-4.app/Contents/Frameworks/Sage.framework/Versions/9.4/local/bin/sage -pip install --user -U nltk

(The pipinvocation is taken from https://www.nltk.org/install.html.)

If you want to use conda packages, then SageMath should be installed via condarather than with the self-contained app. See https://doc.sagemath.org/html/en/inst... and https://wiki.sagemath.org/Conda. Then it should see all packages installed by conda.

edit flag offensive delete link more

Comments

Thanks, it's working great after installation using conda.

keshav gravatar imagekeshav ( 2021-08-27 19:49:59 +0100 )edit

Great, happy to help!

John Palmieri gravatar imageJohn Palmieri ( 2021-08-27 22:13:11 +0100 )edit
3

answered 2021-08-28 15:07:41 +0100

Marc Culler gravatar image

The recommended way to install a pip-based package into the SageMath macOS app is to use the %pip magic command. This works in both the notebook and the terminal. To install nltk, simply type, in either interface,

%pip install nltk
edit flag offensive delete link more

Comments

Nice. Where is that documented?

John Palmieri gravatar imageJohn Palmieri ( 2021-08-28 18:44:41 +0100 )edit

Thanks, I am sure this answer will work great but I didn't want to install two copies of python modules.

keshav gravatar imagekeshav ( 2021-08-28 21:56:51 +0100 )edit

Well, it is mentioned in the README file for the Sage_macOS github repository, but I don't know where it is discussed in the Sage documentation.

Marc Culler gravatar imageMarc Culler ( 2021-08-29 02:15:05 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2021-08-25 13:34:53 +0100

Seen: 594 times

Last updated: Aug 28 '21