Ask Your Question
1

SAGE 8.1, cannot import python modules from notebook

asked 2018-02-28 20:34:14 +0200

daranha gravatar image

I'm running into trouble trying to setup SAGE 8.1. What happened is the following. I'm working in Linux Ubuntu 16.4. I installed SAGE 7.5.1 from command-line. Then I installed SAGE 8.1 from pre-built binaries. I deleted the old sage version and now when I run the command sage, it tries to find SAGE 7.5.1 and fails. I already ran:

ln -s /SageMath8.1/sage /usr/local/bin/sage

And nothing changed. Even though I can run SAGE 8.1 with:

/SageMath8.1/.sage

But once there I cannot import python modules:

>>> import pandas as pd
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-17-af55e7023913> in <module>()
----> 1 import pandas as pd

ImportError: No module named pandas

I guess there's a problem with paths, but I don't know how to solve it. Any help?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
6

answered 2018-03-02 01:00:01 +0200

Dillon Ethier gravatar image

updated 2018-03-02 14:03:17 +0200

Sage uses its own Python environment that's separate from whichever one(s) you may have previously installed. Try installing the package into Sage with the command

sage -pip install pandas

and see if that helps.

edit flag offensive delete link more

Comments

is it 'bad practice' to try to use the same python environment?

daranha gravatar imagedaranha ( 2018-03-05 18:59:47 +0200 )edit

It is not a bad practice, it is just that with your installation setup, SageMath does not use the system python. You can check which python SageMath does use with

sage -python -c 'import sys; print(sys.executable)'
vdelecroix gravatar imagevdelecroix ( 2019-07-06 19:48:57 +0200 )edit
2

answered 2018-03-02 15:03:26 +0200

slelievre gravatar image

updated 2019-06-30 15:12:24 +0200

Regarding your trouble understanding what happens when you type sage in a terminal:

  • run which sage to try to figure out what gets run when you type sage
  • run echo $PATH to check what other locations are searched before /usr/local/bin
  • check if you defined an alias in your .bashrc or .bash_profile or .bash_aliases (see this blog post about .bashrc and others)
  • if the ln -s command you ran did not succeed, it might be either because there already is such an alias there, or because of a permissions problem; try with

    sudo ln -sf /SageMath8.1/sage /usr/local/bin
    
edit flag offensive delete link more

Comments

Thanks for your answer, though I'm still struggling. - 'which sage' command didn't provide an answer. - three locations are searched before '/usr/local/bin': '/home/myself/bin' , '/home/myself/.local/bin', and /usr/local/sbin/' - I don't understand your third point. - It cannot create a symbolic link because it already exists.

daranha gravatar imagedaranha ( 2018-03-05 19:16:45 +0200 )edit

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: 2018-02-28 20:34:14 +0200

Seen: 1,745 times

Last updated: Jun 30 '19