As explained below we can work around most issues raised. And here is the customising to run in ubiquitous TeXworks (TeXstudio in detail below).
SageMaths is developed to run with a customised version of Python currently undergoing changes from version 2.7 to 3.x.
SageTex is not provided as a package in Tex Live but is supplied by MiKTeX. Normally if a package is available via the TeX package manager you are encouraged to use it in preference to download from CTAN.
SageTex recommends (in fact requires) that the compatible version dependant .sty is obtained from within SageMaths for that reason you will need to find and copy D:\Programme\SageMath 8.6\runtime\opt\sagemath-8.6\local\share\texmf\tex\latex\sagetex\sagetex.sty to your working folder. This should prevent MiKTeX from using its incompatible version. (alternatively uninstall the MiKTeX version and add the TDS compliant folder D:\Programme\SageMath 8.6\runtime\opt\sagemath-8.6\local\share\texmf in MiKTeX or copy the texmf\tex folder contents to either your local or system texmf\tex)
This is just step one of many pitfalls I encountered. So now you can compile the example or one of your own files with the version that will work with "SageMath 8.6" (note this issue has dogged SageTeX with every version update and is aggravated by having a space in between)
Whilst mentioning spaces POSIX will accept escaped spaces such as '\ ' however in the hybrid calls between windows and POSIX through Cygwin using "/program\ files/" would cause windows to choke so it would be easier to use DOS style short filenames such as c:\progra~1\sagema~1\ etc. however that's not necessary in this case since the application is in D:\path\with\no\spaces.
That raises the next issue which is that Cygwin expects when crossing drives to have a prefix /cygdrive/c for drive c: and /cygdrive/d for d:
However by trimming the commands to the bone I eventually dropped all such problems
For all the above reasons, and more, the simple task of calling
sage example.sagetex.sage requires scripting behind the scenes, it would be oh so easy if there was simply a sage.exe to transmute all those problems. so what have I learnt over the weeks of investigation.
1) SageMath is wrapped in layers of wrappers and a law unto itself
2) Prior to installing make a c:\sage\work\ and when asked where your user HOME is then point to that folder.
3) Install sagemath into a directory with no version name (thus no spaces) e.g. c:\sage\app\
Here is your answer, In your case first ensure D:\Programme\SageMath 8.6\runtime\bin is on your path e.g. if running from a temporary command line or in a .cmd file add
set path=D:\Programme\SageMath 8.6\runtime\bin;%path%
do the first pdfLaTeX run (with the correct sty in the folder)
either copy or move example.sagetex.sage to your "HOME" directory probably in your case c:\users\yourname then you can simply run
bash -l /opt/sagemath-8.6/sage 'example.sagetex.sage'
IT SHOULD WORK ! and you will find
and a folder called
sage-plots-for-example.tex (with 15 items)
all these need to be moved to wherever you wish to second run pdfLaTeX i.e. where your original aux and pdf files are after second run you get the expected results.
To avoid all that messing about we need a minimal script as below, call it any name you like but I called it
sage.cmd and placed it in the bin directory
The PATH is the ONLY exception to the rule of NO spaces
The following script will not work if your .tex is down a path with spaces, Be Warned
Save as Sage.cmd
:: IF this directory is already on path you don't need the next line
@set path=D:\Programme\SageMath 8.6\runtime\bin;%path%
:: This next line is essential to temporarily correct the directory misdirection
:: but has the side effect of rebuilding a temporary dot sage subdirectory
:: This next line does the donkey work
bash -l /opt/sagemath-8.6/sage '%~n1.sagetex.sage'
:: the following command is optional if you want to delete .sage then remove the ::
:: rmdir /S /Q %~dp1.sage
Inside TeXstudio add a user command to the file (you could also add the pdfLaTeX run before and after)
"D:/Programme/SageMath 8.6/runtime/bin/sage.cmd" "?am"
I forgot to mention that if you now have sage.cmd as suggested within sage...\bin on system path then the command for the editor can be simply
sage "?am" (at worst sage.cmd "?am")
Also you could have a desktop shortcut pointing to the sage.cmd with a "%1" at the end it will allow you to drag and drop a filename.sagetex.sage file for processing
If you want a .cmd or .bat (they are basically both the same) file to automatically run a tex file through all compiles you can have for example one called say SageRunner.cmd (or.bat)
PdfLaTeX your usual options (e.g. synctex) "%1"
PdfLaTeX your usual options "%1"
That should work if you simply drag and drop the filename.tex onto it
I have used "..." in most commands to allow for spaces in the "file name" however there are some places that the call via BaSh (Bourne Shell) would stumble so to make it the simplest (dirty) solution I had to forgo scripting for all drive switching and associated filename syntax checking.