Ask Your Question
2

Running sage (8.9) from command line (Windows)

asked 2019-12-18 14:03:47 -0600

geroyx gravatar image

updated 2019-12-19 09:10:20 -0600

I want to run sage in the cmd. I heard the command is ("nearly")

C:\Programme\SageMath8.9\runtime\bin\bash -l 
      C:/Programme/SageMath8.9/runtime/opt/sagemath-8.9/sage 
          C:/Users/ccc/Desktop/Test/SageTeX/sagebsp01.sagetex.sage

But this gives me several errors

What have I to do?

€dit: Anyway...

C:\Programme\SageMath8.9\runtime\bin\bash -l C:/Programme/SageMath8.9/runtime/opt/sagemath-8.9/sage

starts Sage in the Windows cmd!

Proof:

image description

So I think, the rest should be trivial. Could sb. say me, how the correct command should look like?

Note, that the problem is not my file *.sage, but to set the home directory for that file correctly.

Anyway, in detail:

The errors I get:

C:\WINDOWS\system32>C:\Programme\SageMath8.9\runtime\bin\bash -l C:/Programme/Sa
geMath8.9/runtime/opt/sagemath-8.9/sage 2+2
python2: can't open file '2+2': [Errno 2] No such file or directory

C:\WINDOWS\system32>C:\Programme\SageMath8.9\runtime\bin\bash -l C:/Programme/Sa
geMath8.9/runtime/opt/sagemath-8.9/sage C:/Users/ccc/Desktop/Test/SageTeX/sagebs
p01.sagetex.sage
Traceback (most recent call last):
  File "/opt/sagemath-8.9/src/bin/sage-preparse", line 299, in <module>
    do_preparse(f)
  File "/opt/sagemath-8.9/src/bin/sage-preparse", line 147, in do_preparse
    with atomic_write(fname) as f:
  File "/opt/sagemath-8.9/local/lib/python2.7/site-packages/sage/misc/temporary_
file.py", line 422, in __enter__
    fd, name = tempfile.mkstemp(dir=self.tmpdir)
  File "/opt/sagemath-8.9/local/lib/python2.7/tempfile.py", line 314, in mkstemp

    return _mkstemp_inner(dir, prefix, suffix, flags)
  File "/opt/sagemath-8.9/local/lib/python2.7/tempfile.py", line 244, in _mkstem
p_inner
    fd = _os.open(file, flags, 0600)
OSError: [Errno 2] No such file or directory: '/home/sage/Desktop/Test/SageTeX;/
C:/Users/ccc/Desktop/Test/SageTeX/tmpnnGeqR'

The sage-example (from the standard sagtex-example) I use:

## -*- encoding: utf-8 -*-
## This file (sagebsp01.sagetex.sage) was *autogenerated* from sagebsp01.tex with sagetex.sty version 2019/01/09 v3.3.
import sagetex
_st_ = sagetex.SageTeXProcessor('sagebsp01', version='2019/01/09 v3.3', version_check=True)
try:
 _st_.current_tex_line = 11
 _st_.inline(0, latex(number_of_partitions(1269)))
except:
 _st_.goboom(11)
_st_.current_tex_line = 17
_st_.blockbegin()
try:
     f(x) = exp(x) * sin(2*x)
except:
 _st_.goboom(19)
_st_.blockend()
try:
 _st_.current_tex_line = 24
 _st_.inline(1, latex(f(x)))
except:
 _st_.goboom(24)
try:
 _st_.current_tex_line = 25
 _st_.inline(2, latex(diff(f, x, 2)(x)))
except:
 _st_.goboom(25)
try:
 _st_.current_tex_line = 30
 _st_.plot(0, format='notprovided', _p_=plot(f, -1, 1))
except:
 _st_.goboom(30)
try:
 _st_.current_tex_line = 33
 _st_.inline(3, latex(2^123))
except:
 _st_.goboom(33)
_st_.endofdoc()
edit retag flag offensive close merge delete

Comments

"several errors"; please post (a link to) the full output, and the contents of sagebsp01.sagetex.sage.

rburing gravatar imagerburing ( 2019-12-19 05:35:09 -0600 )edit

@rburing Done. But the file is not the problem. The problem is to run that file....

geroyx gravatar imagegeroyx ( 2019-12-19 09:43:21 -0600 )edit

Out of curiosity why do you want to do this? Sage is a UNIX-based program and not really designed to work well in the Windows cmd shell, as you can tell from the ugly colors alone. I also can't promise that various things like keyboard commands will work well. Is there some other underlying goal? If so, perhaps there is a better way to achieve that goal.

Iguananaut gravatar imageIguananaut ( 2020-08-31 07:46:39 -0600 )edit

2 answers

Sort by » oldest newest most voted
1

answered 2019-12-20 05:48:35 -0600

geroyx gravatar image

It works with:

C:\Programme\SageMath8.9\runtime\bin\bash 
  -l C:/Programme/SageMath8.9/runtime/opt/sagemath-8.9/sage 
       -c "os.chdir('C:\Users\ccc\Desktop\Test\SageTeX');      
                load('sagebsp01.sagetex.sage')"
edit flag offensive delete link more
1

answered 2019-12-23 09:33:13 -0600

Iguananaut gravatar image

Since Sage on Windows runs in Cygwin, the UNIX emulation layer, when you run commands that take a filename it's better to pass a Cygwin path. Try this intead:

> C:\Programme\SageMath8.9\runtime\bin\bash -l /opt/sagemath-8.9/sage /home/sage/Desktop/Test/SageTeX/sagebsp01.sagetex.sage
edit flag offensive delete link more

Comments

I tried that, but it seemed to be not enough. See my answer-post ;)

geroyx gravatar imagegeroyx ( 2019-12-25 13:13:19 -0600 )edit

It should be enough unless there's something specific about your .sage file that it needs to be run out of a specific directory.

Iguananaut gravatar imageIguananaut ( 2019-12-31 04:09:49 -0600 )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: 2019-12-18 14:03:47 -0600

Seen: 249 times

Last updated: Dec 23 '19