Hi Marc,

Very good question. I think that allowing users to modify the standard 
config files is the right thing to do, but I'm really not sure. I worry 
that the next person will want to modify a different setting, and you don't 
want to get dragged into recreating IPython/Jupyter preferences. For 
debugging, would it be worth providing a warning if a config file is found, 
or if a config file is found with any nonstandard settings? (The default 
config file is entirely commented out.)

By the way, I debugged Samuel's suggestion by running "./sage -n" with a 
local installation: it printed error messages in the terminal where I ran 
it that let me know that something was wrong. I figured out that I had to 
use quotes, as in

  c.InteractiveShellApp.exec_lines = ['import sys; ...']

rather than

  c.InteractiveShellApp.exec_lines = [import sys; ...]

I don't know where to view the corresponding error messages for the OS X 
app.

A question for both of you: I think the standard situation is to not have a 
profile directory, you have to run "sage --ipython profile create". Is 
there a good way to do this instead from a Jupyter notebook? Then someone 
could create a profile directory without having to use the terminal, 
although they would need to use a text editor to modify it.

-- 
John

On Friday, June 24, 2022 at 3:12:52 PM UTC-7 Marc Culler wrote:

> Thank you for figuring that out Samuel.  Now here is a question for both 
> of you.  The macOS app intentionally sets a minimal environment when it 
> starts sage.  It is intentionally minimal because it would be dangerous, in 
> terms of security, but more importantly in terms of the potential for 
> creating hard-to-debug crashes of the app, to simply accept whatever weird 
> stuff the user happens to have in their environment.  The decision to set a 
> specific minimal environment for the app was made after such a crash, which 
> was related to traces of an obsolete Sage installation left in a user's 
> .bashrc file.
>
> But dangerous should not necessarily mean impossible.  It would be 
> feasible to add a preferences panel to the app which could include a PATH 
> string to be appended to the minimal default PATH at startup.  Being forced 
> to type that string into a preferences dialog would at least alert the user 
> to the possibility that the next weird crash might be their own fault.  But 
> Samuel's answer indicates that expert users can actually do this using a 
> completely orthogonal preferences setting (one of millions, I suspect) 
> namely editing an IPython config file hidden in the user's .sage 
> directory.  His answer shows that it is not impossible, just difficult.
>
> My question is whether Samuel's approach is better than providing a simple 
> way to modify the PATH, and thereby inviing an unsophisticated user to make 
> a big mess which could cripple the app.  The esoteric knowledge needed to 
> find and edit that config file provides a pretty good filter for ensuring 
> that people who do this know what they are doing, or at least know that 
> they are responsible for the consequences of making a mistake while doing 
> it.  Also, it is unclear to me how many users would actually want to use 
> such a feature.  Adding features that almost no one needs is not my idea of 
> a good design approach.
>
> What do the two of you think?
>
> - Marc
>
> On Friday, June 24, 2022 at 2:08:17 PM UTC-5 John H Palmieri wrote:
>
>> Hi Samuel,
>>
>> Thank you for this. One thing: I made a mistake in my comments on 
>> ask.sagemath.org. Changing sys.path changes the Python path, not the 
>> path for executables. One option is to use
>>
>>     import os; os.environ["PATH"] += ":/usr/local/bin"
>>
>> Any better ways to do this? Your pointer on how to include this into 
>> IPython config files works, as long as the lines are in quotes:
>>
>> c.InteractiveShellApp.exec_lines = [
>>     'import os; os.environ["PATH"] += ":/usr/local/bin" ']
>>
>>
>>
>> On Friday, June 24, 2022 at 10:09:39 AM UTC-7 slelievre wrote:
>>
>>> 2022-06-22 16:37:11 UTC, John H Palmieri:
>>> >
>>> > How do I set the PATH in the OS X Jupyter notebook,
>>> > if I'm using the 3-manifolds binary app? I mean, I know
>>> > how to do it in an individual notebook, but how do I set
>>> > the default PATH for every notebook? For example,
>>> > how do I add /usr/local/bin so that it's in the PATH
>>> > every time I open a new notebook?
>>>
>>> Hi John,
>>>
>>> Good job with your comments at
>>>
>>> - Ask Sage question 62873
>>>   https://ask.sagemath.org/question/62873
>>>   Animating plots in Jupyter/Sagemath
>>>
>>> Here is a possibility for the missing bit, after reading
>>>
>>> - discussion at [Stack Overflow question 34976803](
>>> https://stackoverflow.com/q/34976803)
>>> - [Lucy Park: When Python imports but IPython does not](
>>> https://www.lucypark.kr/blog/2013/02/10/when-python-imports-and-ipython-does-not/
>>> )
>>>
>>> To define some code to be run at the start of each
>>> Sage session, and/or each time the Sage Jupyter
>>> kernel starts, edit one or both of the files
>>>
>>> - `$HOME/.sage/ipython-5.0.0/profile_default/ipython_config.py`
>>> - `$HOME/.sage/ipython-5.0.0/profile_default/ipython_kernel_config.py`
>>>
>>> in which you should find a section like this:
>>>
>>>     ## lines of code to run at IPython startup.
>>>     #  Default: []
>>>     # c.InteractiveShellApp.exec_lines = []
>>>
>>> Uncomment the last line in that section and add
>>> any code to run. For example:
>>>
>>>     ## lines of code to run at IPython startup.
>>>     #  Default: []
>>>     c.InteractiveShellApp.exec_lines = [
>>>         import sys; sys.path.append('/usr/local/bin')
>>>     ]
>>>  
>>> Feel free to consolidate your comments and this idea
>>> into an answer to the Ask Sage question.   --Samuel
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/cca085d1-7134-4297-b666-1877f86aec84n%40googlegroups.com.

Reply via email to