Ask Your Question
1

Using sagemath on windows 10 : impossible to attach file

asked 2018-07-09 17:27:02 +0100

Javidlg gravatar image

updated 2018-07-10 13:22:12 +0100

tmonteil gravatar image

Hi! I've installed sagemath on windows 10 and I'm going crazy. The problem it seems to be that all the program is runing in some kind of temporal directory . I leave here some feedback from my console:

sage: load_attach_path()

['.']

If I change the path,

sage: load_attach_path('C:\Users\Javier\Desktop\current\height1')

sage: load_attach_path()

['.', 'C:\\Users\\Javier\\Desktop\\current\\height1']

So we can confirm the new path was added. Inside the folder height1 I have a file "'heigth1.sage". Let's try to attach it:

sage: attach("height1.sage")
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-4-cb4dd36405f2> in <module>()
----> 1 sage.repl.load.load(sage.repl.load.base64.b64decode("aGVpZ2h0MS5zYWdl"),globals(),True)

/opt/sagemath-8.2/local/lib/python2.7/site-packages/sage/repl/load.py in load(filename, globals, attach)
    252             # See Trac 11812.
    253             if attach:
--> 254                 add_attached_file(fpath)
    255             with open(preparse_file_named(fpath)) as f:
    256                 code = compile(f.read(), preparse_file_named(fpath), 'exec')

/opt/sagemath-8.2/local/lib/python2.7/site-packages/sage/repl/attach.py in add_attached_file(filename)
    376     sage.repl.inputhook.install()
    377     fpath = os.path.abspath(filename)
--> 378     attached[fpath] = os.path.getmtime(fpath)
    379
    380

/opt/sagemath-8.2/local/lib/python2.7/genericpath.py in getmtime(filename)
     60 def getmtime(filename):
     61     """Return the last modification time of a file, reported by os.stat()."""
---> 62     return os.stat(filename).st_mtime
     63
     64

OSError: [Errno 2] No such file or directory: '/home/Javier/C:\\Users\\Javier\\Desktop\\current\\height1/height1.sage'

Recall the Error No such file or directory: '/home/Javier/C:\Users\Javier\Desktop\current\height1/height1.sage'. What ?? Please, help me ! I will appreciate your feedback very much!

edit retag flag offensive close merge delete

Comments

Did you try absolute paths and write \ instead of /?

sage: attach('/home/Javier/C:\Users\Javier\Desktop\current\height1/height1.sage')
sage: attach('/home/Javier/C:\Users\Javier\Desktop\current\height1\height1.sage')
Sébastien gravatar imageSébastien ( 2018-07-09 23:45:27 +0100 )edit

I decided to move back to linux, so my comment doesnt have sense anymore. Thanks for the feedback!

Javidlg gravatar imageJavidlg ( 2019-03-04 16:15:25 +0100 )edit

still, your question makes sense for other windows users

Sébastien gravatar imageSébastien ( 2019-03-22 20:39:08 +0100 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2018-07-10 13:12:07 +0100

Iguananaut gravatar image

Sage on Windows is still running in a UNIX-like environment called Cygwin. In Cygwin, you'll find that Windows style paths generally do work in Python. For example you'll find that the following works:

sage: print(open('C:\\Users\\Javier\\Desktop\\current\\height1\\height1.sage').read())

(Note the double-backslashes--the \ in Python is an escape character, so when you use Windows paths in Python you have to escape the backslash itself. Frequently Python will be forgiving of this if you have some \<C> that is not a known escape sequence. But if you have something like \n then it will still treat that as a newline (for example, since \n is a known escape sequence in Python).

However, it looks like there's a bug in os.path.abspath on Cygwin, where it does not recognize Windows-style paths as absolute paths. I'm glad you brought this up, since I believe that should actually be fixed in Python. This is because Python on Cygwin doesn't actually inherently understand Windows paths--the translation to UNIX-style paths happens transparently in the Cygwin layer. Oops!

You're better off using UNIX-style paths with forward-slashes. Check out what

sage: os.path.abspath('Desktop/current/height1/height1.sage')

returns. I think you'll be pleasantly surprised.

edit flag offensive delete link more

Comments

1

Note that prepending the string with "r" (for "raw") avoids the need to escape backslashes:

print(open(r'C:\Users\Javier\Desktop\current\height1\height1.sage').read())
slelievre gravatar imageslelievre ( 2018-07-10 18:27:34 +0100 )edit

I decided to move back to linux, so my comment doesnt have sense anymore. Thanks for the feedback!

Javidlg gravatar imageJavidlg ( 2019-03-04 16:15:38 +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: 2018-07-09 17:26:08 +0100

Seen: 1,229 times

Last updated: Jul 10 '18