Importing a Python file

125 views
Skip to first unread message

tvn

unread,
Mar 8, 2013, 10:54:17 AM3/8/13
to sage-s...@googlegroups.com
I'd like to import some f.py g,py files in  separate directories /path/to/dir1 , path/to/dir2  to SAGE so that I can do "import f"  and "import g" from the SAGE prompt. 

One way to do that is setting the variable  SAGE_PATH=/path/to/dir1/:/path/to/dir2   in ~/.bash_profile.  However doing that will cause problem when I want to read the document of any function in SAGE.  For example, 

sage: solve??   
ImportError                               Traceback (most recent call last)
....
ImportError: No module named conf


So my question is how to properly adding external directories to SAGE ?  




I've posted a similar question 4 months ago but doesn't received a satisfiable answer here https://groups.google.com/forum/?fromgroups=#!searchin/sage-support/SAGE_PATH/sage-support/Bm1vetO7atw/HjXe1tq1YUUJ

Jan Groenewald

unread,
Mar 8, 2013, 11:40:49 AM3/8/13
to sage-s...@googlegroups.com
Hi

Try preserve the old path:
export SAGE_PATH=$SAGE_PATH:/path/to/dir1/:/path/to/dir2

Regards,
Jan


--
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...@googlegroups.com.
To post to this group, send email to sage-s...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
  .~.
  /V\     Jan Groenewald
 /( )\    www.aims.ac.za
 ^^-^^

tvn

unread,
Mar 8, 2013, 11:46:19 AM3/8/13
to sage-s...@googlegroups.com
Still same problem after doing that.  This makes me think that it won't work when SAGE_PATH is set to anything other than empty (By default SAGE_PATH is not set to anything at all)

John H Palmieri

unread,
Mar 8, 2013, 12:52:07 PM3/8/13
to sage-s...@googlegroups.com


On Friday, March 8, 2013 8:46:19 AM UTC-8, tvn wrote:
Still same problem after doing that.  This makes me think that it won't work when SAGE_PATH is set to anything other than empty (By default SAGE_PATH is not set to anything at all)

This is not a general problem; I'm guessing that it is specific to your particular setup. You are adding some directories to SAGE_PATH; maybe some of the file names in those directories are conflicting with Sage files, so various imports in the Sage library don't work anymore (because they are importing the wrong file). For example, if I put a file called "conf.py" in a directory in my SAGE_PATH, then I can't read documentation any more. So maybe you have a problematic file name. You could list the files here and we could try to troubleshoot it, or you could prefix all of your files with "tvn_", for instance, and try again.

--
John

tvn

unread,
Mar 8, 2013, 1:13:26 PM3/8/13
to sage-s...@googlegroups.com
Thanks !  I have a file called common.py and that screws up something related to Sage documentation.  After renaming that file everything seems to work well again. 
Reply all
Reply to author
Forward
0 new messages