Closed Matthias-A-Steiner closed 1 year ago
Thanks. There is a fix for this. An enhancement that would handle this more conveniently was planned for SageMath-9.7, but it didn't happen before the release.
First, to answer your question, the venv is part of the design of SageMath 9.7. It did not exist in 9.4. It has nothing to do with this problem.
The change between 9.4 and 9.7 which does affect this is that in 9.4 the environment in the SageMath app included everything in the user's environment at the time sage was launched. That was causing problems for people who had old copies of Sage lying around on their system and had set up environment variables to deal with those. Those environment variables could break the SageMath app by causing it to import imodules from old versions of Sage. This change was to arrange that the SageMath app launches with a minimal environment.
You can set additional environment variables by creating an iPython startup file. (Thanks to Samuel Lelièvre for this information.)
In your case, you could create a file in the following subdirectory of your .sage directory:
$HOME/.sage/ipython-5.0.0/profile_default/startup
which sets up your environment. For example, you could create a file named:
$HOME/.sage/ipython-5.0.0/profile_default/startup/10-environ.py
containing two lines similar to these:
import os
os.environ['TEXMACS_HOME_PATH'] = '/path/to/your/texmacs/home
Multiple startup files are allowed and they are run in lexicographical order before ipython starts up, as explained in the README file in the startup directory. That README file suggests using numerical prefixes (e.g. 10-) to control the order.
Hopefully the next release will allow you to edit your environment within the gui that starts the SageMath app.
Dear Marc,
thanks for your fast reply and the detailed explanation. I created the file 10-envrion.py
in the suggested directory putting these two lines in it:
import os os.environ['TEXMACS_HOME_PATH'] = '/Applications/TeXmacs.app/Contents/Resources/share/TeXmacs'
I also tried
import os os.environ['TEXMACS_PATH'] = '/Applications/TeXmacs.app/Contents/Resources/share/TeXmacs'
Yet, in both cases the sage session in TeXmacs produced the same error message as before to eventually freeze. Maybe I got the Python syntax wrong, maybe the TeXmacs sage plugin in not compatible with SageMath-9-7. I guess I'll have to reinstall SageMath-9-4 till the new release (SageMath-9-8?) is out.
Cheers Tilda
Reinstalling 9.4 would be silly.
Please start your SageMath-9.7 app in the terminal and print out os.environ to see whether the variables have been correctly set. The error message is telling you which environment variable is not set. Check if it has been set in your os.environ.
There should be two lines in the file. It looks like you only have one (without a semicolon) from what you wrote in the comment.
Thanks again. I restarted my ageMath-9.7 app in the terminal and printed out os.environ. Judging from the output
environ{ . . .
'TEXMACS_PATH': '/Applications/TeXmacs.app/Contents/Resources/share/TeXmacs'}
the environment obviously seems to be correctly set. But the error message prevails, even though my 10-envrion.py
is a two-liner. Even after removing all visible traces of SageMath-9-4.app from my system, I still get the old error message in the TeXmacs session.
Judging from your first message the name of the environment variable is TEXMACS_HOME_PATH but it looks like the variable that you set in your startup file was named TEXMACS_PATH. I think you should try TEXMACS_HOME_PATH instead.
I've tried that, but it did not make any difference. The TeXmacs sage plugin tm_sage.py
is in TEXMACS_PATH which is /Applications/TeXmacs.app/Contents/Resources/share/TeXmacs + /plugins/tmpy + /session. Setting the environment to TEXMACS_HOME_PATH redirects to user specific reconfigurations in case they're done. They are read in first, if there are none, TEXMACS_PATH is evaluated. From tm_sage.py
:
import os
import sys
from os.path import exists
tmpy_home_path = os.environ.get("TEXMACS_HOME_PATH") + "/plugins/tmpy"
if (exists (tmpy_home_path)):
sys.path.append(os.environ.get("TEXMACS_HOME_PATH") + "/plugins/")
else:
sys.path.append(os.environ.get("TEXMACS_PATH") + "/plugins/")
For SageMath-9-4 this worked well.
Dear Marc, thanks for your suggestions so far. Would you consider the configuration issue SageMath specific or related to the sage-plugin in TeXmacs? If the latter is the case I could, if this is all right with you, refer to our exchange on the TeXmacs forum.
Tilda
I am planning to install TeXmacs and investigate what happens on my system. But I haven't gotten to it yet. Sorry.
very kind of you
I installed TeXmacs and my conclusion is that this is not related to Sage. TeXmacs is not correctly initializing its environment. This is made more complicated by the fact that they are using python 2.7 internally, even though they only support python 3 sessions. (Their shebang is:
#! /usr/bin/env python
which gives python 2.7 on macOS.)
I was able to get the sage sessions to work by editing the files tm_sage.py and postscript.py inside of the app bundle. But this is really something that TeXmacs should fix, in my opinion. Also this is unrelated to the sage environment, although I still do plan to add the ability to change the sage environment.
Thanks for investigating. It's good to hear that you got SageMath-9-7 running in TeXmacs sage session . May I ask what exactly you had to tweak in tm_sage.py
and postscript.py
.
The python set-up in TeXmacs is indeed a bit confusing. When I run /usr/bin/env python
on the shell level I get: Python 3.10.8 (main, Oct 12 2022, 02:40:34) [Clang 11.0.3 (clang-1103.0.32.62)] on darwin
from a shell session in TeXmacs: Python 2.7.16 (default, Mar 25 2021, 03:11:28) [GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Whereas when I open a python session, after having edited init-python.scm
accordingly, I get
Python 3.10.8 [/opt/local/bin/python3] Python plugin for TeXmacs.
I suppose you're quite right that "TeXmacs is not correctly initializing its environment. This is made more complicated by the fact that they are using python 2.7 internally, even though they only support python 3 sessions."
Cheers, Tilda
I think the simplest hack to make a sage session work is to just set the two environment variables to their expected values in the file:
/Applications/TeXmacs.app/Contents/Resources/share/TeXmacs/plugins/tmpy/session/tm_sage.py
But doing this makes it impossible to relocate the app and it really should be handled in the app's startup code. I hope you will raise an issue at the TeXmacs project.
--- tm_sage.py.orig 2022-11-20 17:49:33
+++ tm_sage.py 2022-11-21 08:04:38
@@ -13,6 +13,8 @@
import os
import sys
from os.path import exists
+os.environ["TEXMACS_HOME_PATH"] = os.path.join(os.environ["HOME"], ".TeXmacs")
+os.environ["TEXMACS_PATH"] = "/Applications/TeXmacs.app/Contents/Resources/share/TeXmacs"
tmpy_home_path = os.environ.get("TEXMACS_HOME_PATH") + "/plugins/tmpy"
if (exists (tmpy_home_path)):
sys.path.append(os.environ.get("TEXMACS_HOME_PATH") + "/plugins/")
I think this can be closed now.
I’m on mac OSX 13.6/15.7 and currently using TeXmacs 2.1.2. I’ve recently upgraded from SageMath-9-4 (which worked perfectly fine on these systems) to SageMath-9-7.
When I want to launch a Sage session in TeXmacs now, I get the following error message:
and the session freezes.
I was being told that the error message means that
os.environ.get(“TEXMACS_HOME_PATH”)
is returningNone
, i.e. it is not defined, so Python is running outside the shell which called TeXmacs.This problem did not occur with SageMath-9-4.
So, comparing the directories
/private/var/tmp/sage-9.4-current
with/private/var/tmp/sage-9.7-current
, I noticed that there is a softlinked subdirectoryvenv
in sage-9.7 which is linked tolocal/var/lib/sage/venv-python3.10.5/
which itself is linked to/Applications/SageMath-9-7.app/Contents/Frameworks/Sage.framework/Versions/9.7/local/var/lib/sage/venv-python3.10.5
.Could it be that these multiple softlinks prevent launching SageMath-9-7 from within a TeXmacs sage session? If so, how could the issue be fixed?
Any suggestions appreciated.
Cheers Tilda