Ask Your Question
1

file with extension sws

asked 2017-12-13 15:06:09 +0200

danielvolinski gravatar image

Hi All,

I downloaded several SageMath files with extension sws, but I am unable to open them with SageMath 8.0 on Windows native. Is there any translator from sws to ipynb file? How should I proceed?

Thanks,

Daniel

edit retag flag offensive close merge delete

Comments

This is a possible duplicate of https://ask.sagemath.org/question/358...

Iguananaut gravatar imageIguananaut ( 2017-12-14 12:53:58 +0200 )edit

3 Answers

Sort by » oldest newest most voted
3

answered 2020-11-09 10:17:49 +0200

Sébastien gravatar image

updated 2020-11-09 21:54:45 +0200

Since sagemath-9.2 (see ticket #28838), the command sage -sws2rst was resurrected via a new pip-installable package sage-sws2rst. It can be installed in Sage 9.2 using sage -i sage_sws2rst.

Below is an example of usage. First we download a sage worksheet (.sws) prepared for Sage Days 20 at CIRM (Marseille, 2010):

$ wget http://slabbe.org/Sage/2010-perpignan/CIRM_Tutorial_1.sws
$ ls
CIRM_Tutorial_1.sws

We translate the sws worksheet into a ReStructuredText syntax file (.rst) using sage -sws2rst. This creates also a directory of images:

$ sage -sws2rst CIRM_Tutorial_1.sws
Processing CIRM_Tutorial_1.sws
File at CIRM_Tutorial_1.rst
Image directory at CIRM_Tutorial_1_media
$ ls
CIRM_Tutorial_1_media  CIRM_Tutorial_1.rst  CIRM_Tutorial_1.sws

Then, we can check that it works properly by looking at the generated rst file. Alternatively, we can translate it to a basic html file using rst2html:

$ rst2html.py CIRM_Tutorial_1.rst CIRM_Tutorial_1.html
CIRM_Tutorial_1.rst:176: (WARNING/2) Explicit markup ends without a blank line; unexpected unindent.
CIRM_Tutorial_1.rst:334: (WARNING/2) Inline strong start-string without end-string.

As seen above, there are few warnings sometimes because the translation made by sws2rst is not 100% perfect, but most of it is okay:

$ firefox CIRM_Tutorial_1.html

Moreover, one can use the sage -rst2ipynb script (installed with sage -i rst2ipynb + you may need to install pandoc on the system) to translate the rst file obtained above to a Jupyter notebook:

$ sage -rst2ipynb CIRM_Tutorial_1.rst CIRM_Tutorial_1.ipynb

One can check the result:

$ sage -n jupyter

(This answer was copy-pasted from the ReleaseTour of Sage-9.2)

Note that to translate old .sws files to .ipynb, you may also use the export notebook:

$ sage -n -h
[...]
* List available legacy Sage notebooks:

      sage --notebook=export --list

* Export a legacy Sage notebook as a Jupyter notebook:

      sage --notebook=export --ipynb=Output.ipynb admin:10
edit flag offensive delete link more

Comments

Does this works under windows ?

tmonteil gravatar imagetmonteil ( 2020-11-09 14:15:08 +0200 )edit

The 9.2 windows installer is not yet available at https://github.com/sagemath/sage-wind... I will ask a colleague running windows to test it when it will be available.

Sébastien gravatar imageSébastien ( 2020-11-09 16:29:51 +0200 )edit

OK thanks. Since this question arise quite often, if it is not working on windows, i am thinking about offering a web service that does the translation online.

tmonteil gravatar imagetmonteil ( 2020-11-09 19:24:27 +0200 )edit

excellent solution, thank you

louisgag gravatar imagelouisgag ( 2021-03-05 14:01:26 +0200 )edit
1

answered 2017-12-14 13:01:04 +0200

Iguananaut gravatar image

To be clear, this isn't anything specific to Windows. The .sws worksheets are for the legacy Sage Notebook software, that is largely being supplanted by the Jupyter Notebook which is what the Windows version provides by default.

You can still run the legacy notebook from the command-line by running the "SageMath Shell" and entering

sage -notebook=sagenb

Enter whatever you want for the "admin password" (It's not important; this is just a legacy of its original design to be a multi-user system). Then I think you have to actually "Upload" the sws files into the Notebook server; it doesn't allow you to directly browse the local filesystem.

This will allow you to quickly use those files, but I would suggest trying to convert them to the ipynb format as discussed in this question: https://ask.sagemath.org/question/358...

edit flag offensive delete link more

Comments

Hi iguananaut, I was able to access the files using the legacy sage, that is OK. Regarding the conversion, it did not work for me. I used the following command: sage -sws2rst riemann.sws riemann.rst It instructed me to install BeautifulSoup which I did with the following command easy_install BeautifulSoup I then proceeded to use the same convert command above and got: ('Processing', 'riemann.sws') bunch of stuff ... OSError: [Errno 13] Permission denied: '/tmp/tmp8zq48e/sage_worksheet/cells' What should I do now?

danielvolinski gravatar imagedanielvolinski ( 2017-12-14 14:18:30 +0200 )edit
1

For the conversion to ipynb, you should run sage -n and simply click on the name of your sws file, as it appears in the list "Convert old notebooks to Jupyter".

eric_g gravatar imageeric_g ( 2017-12-19 10:51:30 +0200 )edit
0

answered 2018-02-18 07:36:57 +0200

slelievre gravatar image

Convert SageNB (.sws) worksheets to Jupyter (.ipynb) worksheets

There are several ways to go, depending on whether you want to convert SageNB worksheets from your SageNB collection (they live in the .sage folder in your home folder), or .sws files that exist elsewhere in your filesystem.

For a SageNB .sws worksheet located somewhere visible in your file system, you could convert it to reStructuredText (.rst) using sws2rstand then convert the .rst file to a Jupyter .ipynb worksheet with rst-to-ipynb.

Or you could upload it to your SageNB collection, as indicated by @Iguananaut (run sage -n sagenb, upload the .sws files to your SageNB collection), then use the exporter (launch it by running sage -n export in a terminal) which will offer to export all SageNB worksheets in your SageNB collection to Jupyter worksheets.

edit flag offensive delete link more

Comments

As I mentioned in the comment to the first answer, the sws2rst command did not work for me.

Moreover the sage -n sagenb and sage -n export open a window but there is no list of files to be translated to the new format so I can select any file.

And another question: I found SageMath files with extension *.sagews, how to translate those?

I found several old extensions of SageMath: *.sage, *.sagews, *.sws. Are there more?

I'm working with SageMath 8.1 on Windows 10 Native.

Thanks,

Daniel

danielvolinski gravatar imagedanielvolinski ( 2018-02-18 20:01:07 +0200 )edit

Sorry, I meant "I can't select any file"

danielvolinski gravatar imagedanielvolinski ( 2018-02-18 20:01:51 +0200 )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: 2017-12-13 15:06:09 +0200

Seen: 4,736 times

Last updated: Nov 09 '20