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.Mon, 07 Nov 2016 07:00:08 -0600Importing Python packages into Sage or Vice Versahttp://ask.sagemath.org/question/35457/importing-python-packages-into-sage-or-vice-versa/ Hi all,
this is my first post. I'm a long time user of Python, and I'm fairly new to Sage. I'm using Ubuntu, if this helps. Currently, python doesn't recognize any of Sage's packages, and Sage can't import even standard Python packages like pandas.
I've looked at various instructions online about how to import sage packages into python and vice versa, but they all seem incredibly intricate, and none of them seem to work for me.
Here are a few attempts that I made:
1. Running "sudo sagemath --python -m easy_install pandas" in terminal. (Still can't import pandas while running sage; even after running: "sys.path.append('/usr/lib/sagemath/local/lib/python2.7/site-packages/pandas-0.19.1-py2.7-linux-x86_64.egg')" from within sage.)
2. Following the instructions in the "import sage packages in python" question. (I don't have enough karma to post links.)
3. Doing various bizzarre attempts at changing sage_root or adding to it my python path.
4. Attempting to import pip while running sage, and install pandas this way. (Can't import pip.)
I tried a few more things (like downloading packages and "build"ing them, and then doing a few more very technical and annoying things), and all of my attempts fail. Is there really no simple way to do this? What is the most fool-proof way to do this that exists? It would be enormously helpful for me to be able to use python packages while working in sage, or vice versa.Sun, 06 Nov 2016 09:34:37 -0600http://ask.sagemath.org/question/35457/importing-python-packages-into-sage-or-vice-versa/Comment by slelievre for <p>Hi all,</p>
<p>this is my first post. I'm a long time user of Python, and I'm fairly new to Sage. I'm using Ubuntu, if this helps. Currently, python doesn't recognize any of Sage's packages, and Sage can't import even standard Python packages like pandas.</p>
<p>I've looked at various instructions online about how to import sage packages into python and vice versa, but they all seem incredibly intricate, and none of them seem to work for me.</p>
<p>Here are a few attempts that I made:</p>
<ol>
<li>Running "sudo sagemath --python -m easy_install pandas" in terminal. (Still can't import pandas while running sage; even after running: "sys.path.append('/usr/lib/sagemath/local/lib/python2.7/site-packages/pandas-0.19.1-py2.7-linux-x86_64.egg')" from within sage.)</li>
<li>Following the instructions in the "import sage packages in python" question. (I don't have enough karma to post links.)</li>
<li>Doing various bizzarre attempts at changing sage_root or adding to it my python path.</li>
<li>Attempting to import pip while running sage, and install pandas this way. (Can't import pip.)</li>
</ol>
<p>I tried a few more things (like downloading packages and "build"ing them, and then doing a few more very technical and annoying things), and all of my attempts fail. Is there really no simple way to do this? What is the most fool-proof way to do this that exists? It would be enormously helpful for me to be able to use python packages while working in sage, or vice versa.</p>
http://ask.sagemath.org/question/35457/importing-python-packages-into-sage-or-vice-versa/?comment=35462#post-id-35462@Andrew, you should be able to post links now.Mon, 07 Nov 2016 01:35:01 -0600http://ask.sagemath.org/question/35457/importing-python-packages-into-sage-or-vice-versa/?comment=35462#post-id-35462Answer by mforets for <p>Hi all,</p>
<p>this is my first post. I'm a long time user of Python, and I'm fairly new to Sage. I'm using Ubuntu, if this helps. Currently, python doesn't recognize any of Sage's packages, and Sage can't import even standard Python packages like pandas.</p>
<p>I've looked at various instructions online about how to import sage packages into python and vice versa, but they all seem incredibly intricate, and none of them seem to work for me.</p>
<p>Here are a few attempts that I made:</p>
<ol>
<li>Running "sudo sagemath --python -m easy_install pandas" in terminal. (Still can't import pandas while running sage; even after running: "sys.path.append('/usr/lib/sagemath/local/lib/python2.7/site-packages/pandas-0.19.1-py2.7-linux-x86_64.egg')" from within sage.)</li>
<li>Following the instructions in the "import sage packages in python" question. (I don't have enough karma to post links.)</li>
<li>Doing various bizzarre attempts at changing sage_root or adding to it my python path.</li>
<li>Attempting to import pip while running sage, and install pandas this way. (Can't import pip.)</li>
</ol>
<p>I tried a few more things (like downloading packages and "build"ing them, and then doing a few more very technical and annoying things), and all of my attempts fail. Is there really no simple way to do this? What is the most fool-proof way to do this that exists? It would be enormously helpful for me to be able to use python packages while working in sage, or vice versa.</p>
http://ask.sagemath.org/question/35457/importing-python-packages-into-sage-or-vice-versa/?answer=35458#post-id-35458I usually install new python packages in Sage via ```./sage --python -m easy_install <package_name>``` (no sudo needed). Have you tried this? (if it is successful, any new sage notebook will recognise ```import <package_name>```). Also, which version of sage are you using?Sun, 06 Nov 2016 10:59:36 -0600http://ask.sagemath.org/question/35457/importing-python-packages-into-sage-or-vice-versa/?answer=35458#post-id-35458Answer by slelievre for <p>Hi all,</p>
<p>this is my first post. I'm a long time user of Python, and I'm fairly new to Sage. I'm using Ubuntu, if this helps. Currently, python doesn't recognize any of Sage's packages, and Sage can't import even standard Python packages like pandas.</p>
<p>I've looked at various instructions online about how to import sage packages into python and vice versa, but they all seem incredibly intricate, and none of them seem to work for me.</p>
<p>Here are a few attempts that I made:</p>
<ol>
<li>Running "sudo sagemath --python -m easy_install pandas" in terminal. (Still can't import pandas while running sage; even after running: "sys.path.append('/usr/lib/sagemath/local/lib/python2.7/site-packages/pandas-0.19.1-py2.7-linux-x86_64.egg')" from within sage.)</li>
<li>Following the instructions in the "import sage packages in python" question. (I don't have enough karma to post links.)</li>
<li>Doing various bizzarre attempts at changing sage_root or adding to it my python path.</li>
<li>Attempting to import pip while running sage, and install pandas this way. (Can't import pip.)</li>
</ol>
<p>I tried a few more things (like downloading packages and "build"ing them, and then doing a few more very technical and annoying things), and all of my attempts fail. Is there really no simple way to do this? What is the most fool-proof way to do this that exists? It would be enormously helpful for me to be able to use python packages while working in sage, or vice versa.</p>
http://ask.sagemath.org/question/35457/importing-python-packages-into-sage-or-vice-versa/?answer=35459#post-id-35459Run the sage shell by typing `sage -sh` in a terminal.
In the sage shell, run `pip install pandas`.
Next time you launch Sage, you can `import pandas`.
Before:
$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 7.4, Release Date: 2016-10-18 │
│ Type "notebook()" for the browser-based notebook interface. │
│ Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: import pandas
Traceback (most recent call last)
...
ImportError: No module named pandas
sage:
Installing:
$ sage -sh
Starting subshell with Sage environment variables set. Don't forget
to exit when you are done. Beware:
* Do not do anything with other copies of Sage on your system.
* Do not use this for installing Sage packages using "sage -i" or for
running "make" at Sage's root directory. These should be done
outside the Sage shell.
Bypassing shell configuration files...
Note: SAGE_ROOT=/opt/s/sage-7.4
(sage-sh) you@YourComputer:~$ pip install pandas
Collecting pandas
Downloading pandas-0.19.1.tar.gz (8.4MB)
100% |████████████████████████████████| 8.4MB 116kB/s
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): pytz>=2011k in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.7.0 in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from python-dateutil->pandas)
Installing collected packages: pandas
Running setup.py install for pandas ... done
Successfully installed pandas-0.19.1
You are using pip version 8.1.2, however version 9.0.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(sage-sh) you@YourComputer:~$
After:
$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 7.4, Release Date: 2016-10-18 │
│ Type "notebook()" for the browser-based notebook interface. │
│ Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: import pandas
sage:
Sun, 06 Nov 2016 13:01:47 -0600http://ask.sagemath.org/question/35457/importing-python-packages-into-sage-or-vice-versa/?answer=35459#post-id-35459Comment by slelievre for <p>Run the sage shell by typing <code>sage -sh</code> in a terminal.</p>
<p>In the sage shell, run <code>pip install pandas</code>.</p>
<p>Next time you launch Sage, you can <code>import pandas</code>.</p>
<p>Before:</p>
<pre><code>$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 7.4, Release Date: 2016-10-18 │
│ Type "notebook()" for the browser-based notebook interface. │
│ Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: import pandas
Traceback (most recent call last)
...
ImportError: No module named pandas
sage:
</code></pre>
<p>Installing:</p>
<pre><code>$ sage -sh
Starting subshell with Sage environment variables set. Don't forget
to exit when you are done. Beware:
* Do not do anything with other copies of Sage on your system.
* Do not use this for installing Sage packages using "sage -i" or for
running "make" at Sage's root directory. These should be done
outside the Sage shell.
Bypassing shell configuration files...
Note: SAGE_ROOT=/opt/s/sage-7.4
(sage-sh) you@YourComputer:~$ pip install pandas
Collecting pandas
Downloading pandas-0.19.1.tar.gz (8.4MB)
100% |████████████████████████████████| 8.4MB 116kB/s
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): pytz>=2011k in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.7.0 in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from python-dateutil->pandas)
Installing collected packages: pandas
Running setup.py install for pandas ... done
Successfully installed pandas-0.19.1
You are using pip version 8.1.2, however version 9.0.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(sage-sh) you@YourComputer:~$
</code></pre>
<p>After:</p>
<pre><code>$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 7.4, Release Date: 2016-10-18 │
│ Type "notebook()" for the browser-based notebook interface. │
│ Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: import pandas
sage:
</code></pre>
http://ask.sagemath.org/question/35457/importing-python-packages-into-sage-or-vice-versa/?comment=35468#post-id-35468The error message is complaining that you have no SSL support.
You should install `libssl` and `libssl-dev` using your distribution's package manager.
Either type this in a terminal
$ apt-get install libssl libssl-dev
or use the graphical user interface for Ubuntu's package manager.Mon, 07 Nov 2016 07:00:08 -0600http://ask.sagemath.org/question/35457/importing-python-packages-into-sage-or-vice-versa/?comment=35468#post-id-35468Comment by slelievre for <p>Run the sage shell by typing <code>sage -sh</code> in a terminal.</p>
<p>In the sage shell, run <code>pip install pandas</code>.</p>
<p>Next time you launch Sage, you can <code>import pandas</code>.</p>
<p>Before:</p>
<pre><code>$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 7.4, Release Date: 2016-10-18 │
│ Type "notebook()" for the browser-based notebook interface. │
│ Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: import pandas
Traceback (most recent call last)
...
ImportError: No module named pandas
sage:
</code></pre>
<p>Installing:</p>
<pre><code>$ sage -sh
Starting subshell with Sage environment variables set. Don't forget
to exit when you are done. Beware:
* Do not do anything with other copies of Sage on your system.
* Do not use this for installing Sage packages using "sage -i" or for
running "make" at Sage's root directory. These should be done
outside the Sage shell.
Bypassing shell configuration files...
Note: SAGE_ROOT=/opt/s/sage-7.4
(sage-sh) you@YourComputer:~$ pip install pandas
Collecting pandas
Downloading pandas-0.19.1.tar.gz (8.4MB)
100% |████████████████████████████████| 8.4MB 116kB/s
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): pytz>=2011k in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.7.0 in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from python-dateutil->pandas)
Installing collected packages: pandas
Running setup.py install for pandas ... done
Successfully installed pandas-0.19.1
You are using pip version 8.1.2, however version 9.0.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(sage-sh) you@YourComputer:~$
</code></pre>
<p>After:</p>
<pre><code>$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 7.4, Release Date: 2016-10-18 │
│ Type "notebook()" for the browser-based notebook interface. │
│ Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: import pandas
sage:
</code></pre>
http://ask.sagemath.org/question/35457/importing-python-packages-into-sage-or-vice-versa/?comment=35467#post-id-35467To display blocks of code in questions, answers or comments, select the lines of code, then click the "code" button (the icon with '101 010'). Alternatively, indent each line of code by four spaces. Surrounding code with triple-bacquotes does not work. Can you edit your comment to do that?Mon, 07 Nov 2016 06:53:17 -0600http://ask.sagemath.org/question/35457/importing-python-packages-into-sage-or-vice-versa/?comment=35467#post-id-35467Comment by edenharder for <p>Run the sage shell by typing <code>sage -sh</code> in a terminal.</p>
<p>In the sage shell, run <code>pip install pandas</code>.</p>
<p>Next time you launch Sage, you can <code>import pandas</code>.</p>
<p>Before:</p>
<pre><code>$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 7.4, Release Date: 2016-10-18 │
│ Type "notebook()" for the browser-based notebook interface. │
│ Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: import pandas
Traceback (most recent call last)
...
ImportError: No module named pandas
sage:
</code></pre>
<p>Installing:</p>
<pre><code>$ sage -sh
Starting subshell with Sage environment variables set. Don't forget
to exit when you are done. Beware:
* Do not do anything with other copies of Sage on your system.
* Do not use this for installing Sage packages using "sage -i" or for
running "make" at Sage's root directory. These should be done
outside the Sage shell.
Bypassing shell configuration files...
Note: SAGE_ROOT=/opt/s/sage-7.4
(sage-sh) you@YourComputer:~$ pip install pandas
Collecting pandas
Downloading pandas-0.19.1.tar.gz (8.4MB)
100% |████████████████████████████████| 8.4MB 116kB/s
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): pytz>=2011k in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.7.0 in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in /opt/s/sage-7.4/local/lib/python2.7/site-packages (from python-dateutil->pandas)
Installing collected packages: pandas
Running setup.py install for pandas ... done
Successfully installed pandas-0.19.1
You are using pip version 8.1.2, however version 9.0.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(sage-sh) you@YourComputer:~$
</code></pre>
<p>After:</p>
<pre><code>$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 7.4, Release Date: 2016-10-18 │
│ Type "notebook()" for the browser-based notebook interface. │
│ Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: import pandas
sage:
</code></pre>
http://ask.sagemath.org/question/35457/importing-python-packages-into-sage-or-vice-versa/?comment=35465#post-id-35465When i run `pip install python-igraph` it gives that
```
pip install python_igraph
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting python_igraph
Could not fetch URL https://pypi.python.org/simple/python-igraph/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
Could not find a version that satisfies the requirement python_igraph (from versions: )
No matching distribution found for python_igraph
```
Could you teach me how to install it correctly?Mon, 07 Nov 2016 06:03:35 -0600http://ask.sagemath.org/question/35457/importing-python-packages-into-sage-or-vice-versa/?comment=35465#post-id-35465