Ask Your Question
1

Adding some *.py files to sagemath notebook?

asked 2013-05-07 20:38:16 +0100

russ_hensel gravatar image

updated 2015-01-14 10:06:35 +0100

FrédéricC gravatar image

Ok I have spent hours going thru online docs for such a simple question but now give up, so now I am asking:

I am running the sage appliance in virtual box ( sage5.1 ) under windows 7.

I have some python file, but no setup.py file for them.

I would like to add them to sage so in the notebook I can import them.

Can anyone tell me where to put them, hopefully without expecting me to know my well very well around linux ( I can copy move make directories, and modify some access rights, but I do not want to learn bash scripting ) If you could give command on a close to cut and paste basis that would be wonderful.

edit retag flag offensive close merge delete

Comments

Do you expect to do this often, like having your own local python module library? Or maybe this is a one-off?

rickhg12hs gravatar imagerickhg12hs ( 2013-05-08 01:16:58 +0100 )edit

not sure, in this case it is a module from a course which does not have an install utility.

russ_hensel gravatar imageruss_hensel ( 2013-05-08 16:48:27 +0100 )edit

3 Answers

Sort by » oldest newest most voted
1

answered 2013-05-08 04:03:57 +0100

rickhg12hs gravatar image

Here's what I usually do:

import sys
sys.path.append('/path/to/my/local/python/files') # move your python files here
import mypythonfile
edit flag offensive delete link more

Comments

Depending on the collection source/purpose/use of the python files, I'll put them in something like /home/myhomedir/sage/mypythonfiles, or in a subdir somewhere under /usr/local or /opt. I steer clear of OS related dirs like /etc, /bin, /usr/lib, /lib, etc., because I don't want to break anything and I don't want to worry about what OS updates might do.

rickhg12hs gravatar imagerickhg12hs ( 2013-05-08 18:11:41 +0100 )edit
0

answered 2013-05-08 03:21:23 +0100

ppurka gravatar image

This is what I do

import os
os.chdir("/path/to/directory") # /path/to/directory is where my python file is kept
from mypythonfile import *
edit flag offensive delete link more
0

answered 2013-05-08 17:16:33 +0100

russ_hensel gravatar image

updated 2013-05-08 17:17:02 +0100

This is the original poster with an update. Tried both of the above from the notebook after moving the files to /etc/mesa

Neither worked -- then I remembered that linux is full of gotchas so I broke out of the notebook right-ctrl and f1, then logged in as root ( password sage ) and from the command line changed the file rights: chmod uog=rwx -R /etc/mesa

Then I restarted the sage vm. So far it seems to work ( the import sys method, the other may work as well, I will try later. )

Thanks very much.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-05-07 20:38:16 +0100

Seen: 897 times

Last updated: May 08 '13