Installing Sage on Windows for PreTeXt

170 views
Skip to first unread message

Sean Fitzpatrick

unread,
Nov 28, 2023, 11:06:19 AM11/28/23
to PreTeXt support
I'm wondering if anyone has recent experience installing Sage on Windows, and linking up with PreTeXt.

I have a new Windows computer, so I decided to see how hard it is to get a local PreTeXt instance up and running on Windows now.

Aside from Sage, the answer is: pretty easy. (Especially if you have memory of Windows installation from 5 years ago.)

- install Python
- install VSCode
- install Git for Windows and choose VSCode as the default editor
- install TeXLive (easy, but holy crap does the installer take forever)
- pip install PreTeXt, and add PreTeXt tools to VSCode

At this point, I can do everything but generate sageplot images.
Sage no longer provides a Windows binary. You are supposed to enable WSL, and then follow the Linux installation instructions.

I'm not so confident that PreTeXt will successfully link up with a Sage instance living in WSL.

If someone else has done it and it's not so bad, I'll proceed. Otherwise, it is probably not worth the trouble to install for the 3 Sage images I need to build. I can just build on Linux and copy over.

Sean Fitzpatrick

unread,
Nov 28, 2023, 11:10:05 AM11/28/23
to PreTeXt support
Update: I couldn't get there from the main SageMath page, but there are Windows .exe files downloadable from their GitHub releases page:

However, the latest version you can install directly on Windows is 9.3. If you want 10.1, I guess you need to stick with WSL.

Sean Fitzpatrick

unread,
Nov 28, 2023, 12:27:23 PM11/28/23
to PreTeXt support
I forgot a step: you also need the pdf2svg program for Windows.

But there is an easy way to install: if you have the "WingetUI" package manager interface installed, search for pdf2svg.
Two options show up, and the second (v. 0.23) installs without issues. WingetUI even adds it to the path for you, so it "just works".
You can do the same thing for Sage: search for SageMath, select, and click install.

kcri...@gmail.com

unread,
Nov 29, 2023, 6:55:14 AM11/29/23
to PreTeXt support

Update: I couldn't get there from the main SageMath page, but there are Windows .exe files downloadable from their GitHub releases page:

However, the latest version you can install directly on Windows is 9.3. If you want 10.1, I guess you need to stick with WSL.

 
Correct, the exe version was abandoned after the maintainer moved on to other things, it was always a pretty hard job.

In your opinion, how realistic is it for someone not particularly interested in command line, but willing to suck it up to use PTX, to install Sage using WSL?

> I'm not so confident that PreTeXt will successfully link up with a Sage instance living in WSL.

That worries me a bit.  I guess unless everything lives in WSL?

> You can do the same thing for Sage: search for SageMath, select, and click install.

Where does that come from, and what version is it?  I presume it actually works?  Thanks for trying all this out!

Sean Fitzpatrick

unread,
Nov 29, 2023, 8:45:27 AM11/29/23
to pretext...@googlegroups.com
I got Sage 9.3 using Winget. I didn't check to see exactly where it came from.

But building sageplot didn't work. Maybe there's some other configuration I need to do.

I didn't want to bother with WSL.
If I want to use Linux, I'll close my Windows laptop and open my Linux laptop!

Aside from Sage, everything was easy to install on Windows, and I'm able to build using PreTeXt from the vscode terminal.

--
You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/f23339a2-89df-43fa-9f44-a0e0483c3deen%40googlegroups.com.

Steven Clontz

unread,
Nov 29, 2023, 9:47:37 AM11/29/23
to PreTeXt support
Did you try pip installing PreTeXt via WSL, so it lives with Sage?

I think the real answer for Windows users is to have them use Oscar's pretext-full Docker image which ships with the kitchen sink. But I'm not sure how easy that is to do.

Sean Fitzpatrick

unread,
Nov 29, 2023, 10:09:43 AM11/29/23
to pretext...@googlegroups.com
No, I haven't done anything via WSL.
I don't think I want to try installing Docker on Windows either.

If I have spare time (ha!) I might try to figure out how to turn on WSL but it's not a priority when I have a perfectly good Linux laptop within reach.

Mostly I was curious about the current state of "can PreTeXt run natively on Windows?" (meaning no containers, subsystems, or VMs).
The answer for me, so far, is yes, if you don't need Sage.


Sean Fitzpatrick

unread,
Nov 29, 2023, 10:10:45 AM11/29/23
to pretext...@googlegroups.com
Also, to clarify, I did not install the most recent Sage via WSL. I installed version 9.3 directly.

Sean Fitzpatrick

unread,
Nov 29, 2023, 11:23:22 AM11/29/23
to PreTeXt support
Steven, I wonder if you can decrypt the error message I'm getting from the CLI while trying to build sageplot:

warning: Unable to generate some sageplot images: 'NoneType' object has no attribute 'split'

Is that just a sign that nothing was built because it can't find Sage?

Steven Clontz

unread,
Nov 29, 2023, 11:36:58 AM11/29/23
to PreTeXt support
On the contrary, it's Sage that returns such an error: https://sagecell.sagemath.org/?z=eJzzy89L1SsuyMks0dAEAB0cBDw=&lang=sage&interacts=eJyLjgUAARUAuQ==

I have no clever suggestion why, but SageMath has a `None` object and is trying to run `split()` on it. Can you confirm your Sageplot works if you run it in a Sage cell?

Sean Fitzpatrick

unread,
Nov 29, 2023, 12:29:57 PM11/29/23
to pretext...@googlegroups.com
My Sageplot works if I run the CLI on my Linux laptop, so I don't think the issue is with the sage code.

But yes, it also works if I paste the code into SageCell. It's simple code, like
f(x) = 3*x^3-10*x^2+7*x+5
plot(f, (x, -1, 3), ymin=-5, ymax=10, fontsize=20, thickness=3)

kcri...@gmail.com

unread,
Nov 30, 2023, 5:59:09 PM11/30/23
to PreTeXt support
plots return None when actually plotted, if I recall correctly.  So maybe the CLI is trying to do something with that.

Sean Fitzpatrick

unread,
Nov 30, 2023, 6:08:03 PM11/30/23
to pretext...@googlegroups.com
Maybe. This could be another case of "Windows users want a GUI", so no file is created?

I noticed that when I start the Sage console on Windows, it loads the .bashrc file I have for Git Bash (needed to start the ssh agent for git). That seemed a bit weird to me, so maybe my installation is no good.
You received this message because you are subscribed to a topic in the Google Groups "PreTeXt support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pretext-support/2_4Lz6fRKjM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pretext-suppo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/a9397e54-dd1d-40be-9a03-33d738b953ebn%40googlegroups.com.

kcri...@gmail.com

unread,
Dec 1, 2023, 6:59:38 AM12/1/23
to PreTeXt support

Maybe. This could be another case of "Windows users want a GUI", so no file is created?

That seems very unlikely.  However, what is likely is that the way the Sage Windows binary was created was not designed to interact with any Windows stuff (though the error seems a little unusual).  

I presume that just doing a plot command in its console does work.   The best debugging would be to see exactly how Sage is called in the CLI (on Windows) and see whether anything is even returned; I forgot that the CLI is also Python-based, so actually its likely that it's looking for Sage and somehow (I apologize I don't have time to look at it with finals approaching) None gets returned somewhere in there because it can't find Sage properly on Windows.

Sean Fitzpatrick

unread,
Dec 1, 2023, 9:44:43 AM12/1/23
to pretext...@googlegroups.com
Yeah, that's my plan, but I'm in the same time crunch.
I'll first check to make sure it's not just a PATH issue.

--
You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.

Steven Clontz

unread,
Dec 1, 2023, 10:08:31 AM12/1/23
to PreTeXt support
I don't think this is CLI-related unless we're calling Rob's `sage_conversion` function incorrectly: https://github.com/PreTeXtBook/pretext-cli/blob/main/pretext/project/__init__.py#L859

Sean Fitzpatrick

unread,
Dec 1, 2023, 12:06:24 PM12/1/23
to pretext...@googlegroups.com
No. I think the CLI is putting the function call out to Sage, and either not finding Sage, or not getting anything back from Sage. But the error that comes back doesn't suggest one possibility over the other.
You received this message because you are subscribed to a topic in the Google Groups "PreTeXt support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pretext-support/2_4Lz6fRKjM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pretext-suppo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/292f1cb4-79fc-4cb8-9cab-ec1ced95c25fn%40googlegroups.com.

Rob Beezer

unread,
Dec 2, 2023, 12:44:19 AM12/2/23
to pretext...@googlegroups.com
Remember that the code for a sageplot must have a final line that is a Graphics object (or similar), and we replace that with a modified line so we can do further manipulation.

So "None" is suspicious, plot() may not be correct, and testing in the Sage Cell might not be good evidence. But then if this "works" in some cases, maybe what I've said is not correct.
>> <https://github.com/PreTeXtBook/pretext-cli/blob/47ab6086f864c66627acd126c2f4c4f890ac31a7/.devcontainer/devcontainer.json#L5>
>> <https://groups.google.com/d/msgid/pretext-support/f23339a2-89df-43fa-9f44-a0e0483c3deen%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>
>> -- You received this message because you are subscribed
>> to the Google Groups "PreTeXt support" group.
>> To unsubscribe from this group and stop receiving
>> emails from it, send an email to
>> pretext-suppo...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/pretext-support/5e7059a8-4e1d-4d65-9283-d3a8d41c7489n%40googlegroups.com
>> <https://groups.google.com/d/msgid/pretext-support/5e7059a8-4e1d-4d65-9283-d3a8d41c7489n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>
>> --
>> You received this message because you are subscribed to a topic in the Google Groups "PreTeXt support" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/topic/pretext-support/2_4Lz6fRKjM/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to pretext-suppo...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/a9397e54-dd1d-40be-9a03-33d738b953ebn%40googlegroups.com <https://groups.google.com/d/msgid/pretext-support/a9397e54-dd1d-40be-9a03-33d738b953ebn%40googlegroups.com?utm_medium=email&utm_source=footer>.
>

kcri...@gmail.com

unread,
Dec 2, 2023, 8:59:37 AM12/2/23
to PreTeXt support
On Saturday, December 2, 2023 at 12:44:19 AM UTC-5 Rob Beezer wrote:
Remember that the code for a sageplot must have a final line that is a Graphics object (or similar), and we replace that with a modified line so we can do further manipulation.

So "None" is suspicious, plot() may not be correct, and testing in the Sage Cell might not be good evidence. But then if this "works" in some cases, maybe what I've said is not correct.

plot() is certainly going to ordinarily be a graphics object.  And I just tested putting this in a figure/image/sageplot and it worked fine in the CLI.  And Sean said, "My Sageplot works if I run the CLI on my Linux laptop, so I don't think the issue is with the sage code."  So, unfortunately, that isn't the easy fix :-(

Sean, I think you need to start looking at https://github.com/PreTeXtBook/pretext/blob/2930c68504dd1c2710e0afbd1e0f785a785c632a/pretext/pretext.py#L370 and see where the log is saying your Sage is.  I presume that these lines should give you some info as to whether it's finding Sage:

    sage_executable_cmd = get_executable_cmd("sage")
    # TODO why this debug line? get_executable_cmd() outputs the same debug info
    log.debug("sage executable: {}".format(sage_executable_cmd[0]))

Could these lines be causing the split error?  But the directory here is just what happens from the xsltproc, so it should not have any None in it, and the Sage command isn't used until two lines later.

        for sageplot in os.listdir(tmp_dir):
            filebase, _ = os.path.splitext(sageplot)

Anyway, since the only exceptions caught are in the CLI, the following lines are what you end up seeing.  I wonder if you can run just the pretext script in your Windows CLI and see what errors you get instead, they will probably be more informative and not sanitized through this warning.

                except Exception as e:
                    log.warning(f"Unable to generate some sageplot images: {e}")

All this is to say, though, that you're probably going to need to ask on some Sage lists how to get the Sage exe to talk to other stuff.  And since that hasn't been supported for quite some time, you're likely to hear "go use the WSL option".  Sorry.  I think it'd be awesome if you could figure out how to make it work, because then PTX could document it, but given that the exe isn't going to be updated, it may not be the best option.  Aargh.

Rob Beezer

unread,
Dec 2, 2023, 4:18:24 PM12/2/23
to pretext...@googlegroups.com
Thanks, KDC, for the better details. Maybe I'm recalling "show()" as returning None (and have not been in a position to test).

Rob

Sean Fitzpatrick

unread,
Dec 2, 2023, 4:28:17 PM12/2/23
to pretext...@googlegroups.com
Thanks, both.

If there will be no native Sage installs in the future, then it's probably not worth putting much effort into figuring this out.

The GitHub codespace solution is nice, but I've talked to a few people who would rather install locally, and given the market share of Windows...

Right now vscode doesn't offer to open a ptx project in a development container, maybe because that requires Docker or some extension I haven't installed.
But maybe that's a better solution.

The other option is to connect vscode to the WSL, and install everything there.

Or I could remove the dependence on Sage. There are only 3 sageplot images in the whole book and I could make those external assets instead of generated assets.

--
You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.

Sean Fitzpatrick

unread,
Dec 3, 2023, 9:27:25 AM12/3/23
to pretext...@googlegroups.com
I think the final answer in this is going to be:

- if you want to install PreTeXt on Windows and don't intend to use Sage graphics on your books, install Python on Windows and then pip install pretext.

- if you think you might need Sage at some point, you will need to enable the WSL, and install PreTeXt, Sage, and pdf2svg there. There are instructions online on how to connect vscode to the WSL.

What I don't know, but might find out when I have time: if pretext is installed inside the WSL, can it find your local LaTeX? Or do you have to install that both locally (still gotta make those tests for class) *and* on the WSL?

Jan Pearce

unread,
Dec 4, 2023, 8:06:37 AM12/4/23
to PreTeXt support
I don't use Sage, but my students all installed Pretext in Ubuntu in WSL. I recommend Ubuntu 22.04 so the Python version doesn't cause problems.
Jan

Sean Fitzpatrick

unread,
Dec 4, 2023, 8:50:12 AM12/4/23
to pretext...@googlegroups.com
I'm trying to remember if 22.04 is before the change to 'pipx' on Ubuntu.
That's been a minor annoyance on my Ubuntu laptop.

--
You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages