Ask Your Question
1

import astropy in a sage notebook v

asked 2023-09-12 19:12:56 +0100

PatB gravatar image

Hi Sagesse!

I'm wondering if there's an easy way to get a sage notebook (v8.7) to import the module astropy which is found /usr/lib/python3/dist-packages/astropy/ on my linux system.

I am guessing it would require doing an export SAGE_PATH= xxx and then a launch of my notebook as sage --notebook in the usual fashion .

Right now I have the problem :

importError Traceback (most recent call last) <ipython-input-1-7c3762fa282d> in <module>() 1 JD_ecl = RealNumber('2460059.34') 2 Period = RealNumber('1.195') ----> 3 from astropy.time import Time 4 times = ['1999-01-01T00:00:00.123456789', '2010-01-01T00:00:00'] 5 t = Time(times, format='isot', scale='utc')

*ImportError: No module named astropy.time*

and when I check my path in the notebook, it references a directories in my sagepath which in fact don't exist at this point. But maybe I can put a symlink there ....

Example:

import sys print(sys.path) ['', '/home/patricia/SageMath/local/lib/python27.zip', '/home/patricia/SageMath/local/lib/python2.7', '/home/patricia/SageMath/local/lib/python2.7/plat-linux2', '/home/patricia/SageMath/local/lib/python2.7/lib-tk', '/home/patricia/SageMath/local/lib/python2.7/lib-old', '/home/patricia/SageMath/local/lib/python2.7/lib-dynload', '/home/patricia/SageMath/local/lib/python2.7/site-packages', '/home/patricia/SageMath/local/lib/python2.7/site-packages/IPython/extensions', '/home/patricia/.sage/ipython-5.0.0']


Qu'en pensez-vous ?

edit retag flag offensive close merge delete

Comments

2

Any particular reason you're using a version of Sage that's over four years old? Try sage -pip install astropy to install the package into Sage's python. Since Sage 8.7 is based on Python 2, the latest astropy you could use seems to be 2.0.16, which is quite outdated (all the more reason to upgrade).

rburing gravatar imagerburing ( 2023-09-12 21:08:54 +0100 )edit

To convert old sws notebooks to ipynb, there used to be the command

sage -n export

but it seems broken in recent versions of SageMath: on my computer running SageMath 10.1, it returns AttributeError: 'ExportSageNBHandler' object has no attribute '_notebook'.

eric_g gravatar imageeric_g ( 2023-09-13 10:42:47 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-09-13 04:44:24 +0100

PatB gravatar image

Un gros merci Ricardo!

The sage pip install worked - for python2.7. Yes, I should be ashamed to use this 4 year old sage. I chose to use it because I couldn't find any other way to play with my old style notebooks of type .sws

Question: Is there some utility that you could recommend that easily does the conversion .sws to ipynb ?

image description

edit flag offensive delete link more

Comments

1

De rien! That is a valid use case for old SageMath versions of course. There are instructions for conversion of .sws to .ipynbhere: https://ask.sagemath.org/question/401... I had to use sage -pip install sage_sws2rst and sage -pip install rst2ipynb and modify the rst2ipynb script to replace --atx-headers by --markdown-headings=atx, but then it worked in SageMath 10.0 on Ubuntu 22.04.

rburing gravatar imagerburing ( 2023-09-13 11:02:13 +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

1 follower

Stats

Asked: 2023-09-12 19:12:56 +0100

Seen: 167 times

Last updated: Sep 13 '23