ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 05 Oct 2011 05:55:33 -0500How do I get sage to honor my PYTHONPATH environmental variable?http://ask.sagemath.org/question/7934/how-do-i-get-sage-to-honor-my-pythonpath-environmental-variable/I have a number of modules that I have in my documents folder but sage does not look like it honors my PYTHONPATH environmental variable. What do I have to add to my .bashrc or .bash_profile to have sage look at alternate paths?Mon, 28 Feb 2011 10:54:52 -0600http://ask.sagemath.org/question/7934/how-do-i-get-sage-to-honor-my-pythonpath-environmental-variable/Answer by DSM for <p>I have a number of modules that I have in my documents folder but sage does not look like it honors my PYTHONPATH environmental variable. What do I have to add to my .bashrc or .bash_profile to have sage look at alternate paths?</p>
http://ask.sagemath.org/question/7934/how-do-i-get-sage-to-honor-my-pythonpath-environmental-variable/?answer=12156#post-id-12156Sage uses PYTHONPATH for its own purposes. If you add the directory/directories to SAGE_PATH (export SAGE_PATH=/some/dir/here) it should work, at least it seems to for me.
Beware: it looks like SAGE_PATH is added *before* Sage's existing python in sage-env:
PYTHONPATH="$SAGE_PATH:$SAGE_ROOT/local/lib/python" && export PYTHONPATH
so if you shadow one of the built-in modules you could get strange errors. [Not that you couldn't get errors if it were the other way 'round, of course, but you might not even be able to get to the prompt.]Mon, 28 Feb 2011 13:10:53 -0600http://ask.sagemath.org/question/7934/how-do-i-get-sage-to-honor-my-pythonpath-environmental-variable/?answer=12156#post-id-12156Comment by EmersonL for <p>Sage uses PYTHONPATH for its own purposes. If you add the directory/directories to SAGE_PATH (export SAGE_PATH=/some/dir/here) it should work, at least it seems to for me.</p>
<p>Beware: it looks like SAGE_PATH is added <em>before</em> Sage's existing python in sage-env:</p>
<pre><code>PYTHONPATH="$SAGE_PATH:$SAGE_ROOT/local/lib/python" && export PYTHONPATH
</code></pre>
<p>so if you shadow one of the built-in modules you could get strange errors. [Not that you couldn't get errors if it were the other way 'round, of course, but you might not even be able to get to the prompt.]</p>
http://ask.sagemath.org/question/7934/how-do-i-get-sage-to-honor-my-pythonpath-environmental-variable/?comment=21546#post-id-21546I'm also interested in this, but unfortunately I don't understand much of what is here written. Is it possible to explain this again for a computer newbie? (I'm trying to do this with ubuntu)Sun, 26 Jun 2011 01:28:17 -0500http://ask.sagemath.org/question/7934/how-do-i-get-sage-to-honor-my-pythonpath-environmental-variable/?comment=21546#post-id-21546Comment by tdstephens3 for <p>Sage uses PYTHONPATH for its own purposes. If you add the directory/directories to SAGE_PATH (export SAGE_PATH=/some/dir/here) it should work, at least it seems to for me.</p>
<p>Beware: it looks like SAGE_PATH is added <em>before</em> Sage's existing python in sage-env:</p>
<pre><code>PYTHONPATH="$SAGE_PATH:$SAGE_ROOT/local/lib/python" && export PYTHONPATH
</code></pre>
<p>so if you shadow one of the built-in modules you could get strange errors. [Not that you couldn't get errors if it were the other way 'round, of course, but you might not even be able to get to the prompt.]</p>
http://ask.sagemath.org/question/7934/how-do-i-get-sage-to-honor-my-pythonpath-environmental-variable/?comment=21543#post-id-21543Emerson, these are directives specified in the .bashrc or .bash_profile file sitting in your home directory. The best thing for you to do is to learn about the .bashrc file (and the .bash_profile file) in general, then look into what are known as environment variables, which are these PATH things they are talking about.Mon, 27 Jun 2011 04:35:48 -0500http://ask.sagemath.org/question/7934/how-do-i-get-sage-to-honor-my-pythonpath-environmental-variable/?comment=21543#post-id-21543Answer by Bétréma for <p>I have a number of modules that I have in my documents folder but sage does not look like it honors my PYTHONPATH environmental variable. What do I have to add to my .bashrc or .bash_profile to have sage look at alternate paths?</p>
http://ask.sagemath.org/question/7934/how-do-i-get-sage-to-honor-my-pythonpath-environmental-variable/?answer=12697#post-id-12697Answer by DSM is definitely right, but I got confused because I did'nt understand that the most apparent part of his answer is quoted from Sage sources. So for dummies like me, I tell it again:
1. Don't try to define PYTHONPATH yourself !
2. Add the following line in your `.bashrc` file: <blockquote>`export SAGE_PATH=/some/dir/`</blockquote>
and then each time sage is running, when you type `import stuff` , Sage will search for `stuff.py` (or for a shared library `stuff.so`, or for a directory `stuff` with a file __init__.py) in `/some/dir/` *before* searching in the usual Sage modules repository ($SAGE_ROOT/local/lib/python).
Hints: when sage is running, use `os.environ['PYTHONPATH']` to verify that PYTHONPATH has the expected value. Each time you modify your .bashrc file, don't forget to launch a new terminal (and a new sage) before testing !Wed, 05 Oct 2011 05:55:33 -0500http://ask.sagemath.org/question/7934/how-do-i-get-sage-to-honor-my-pythonpath-environmental-variable/?answer=12697#post-id-12697