Unable to import "from sage.numerical.mip import MixedIntegerLinearProgram"

Skip to first unread message

Eric Parent

Jan 28, 2015, 12:43:17 PM1/28/15
to sage-s...@googlegroups.com

I'm running Debian Wheezy x86_64.
I downloaded the sources (sage-6.4) which I compiled and run for a few months already.

I used to run Python scripts from Sage like this:

$ sage -python <script.py>

The script was actually exported from a notebook I was running. I just felt more comfortable running a script than going through the Notebook interface...

And it worked just fine until this weekend. I guess my problems are due to an update of my OS I did this weekend. I haven't kept note of the various packages I updated. I think GCC was in the lot.

Now, I can run the Notebook without any problem but I get this error when I run my script :

$ sage -python debug.py
Traceback (most recent call last):
File "debug.py", line 3, in <module>
from sage.numerical.mip import MixedIntegerLinearProgram
File "/home/eric/apps/sage-6.4/local/lib/python2.7/site-packages/sage/numerical/__init__.py", line 1, in <module>
import all
File "/home/eric/apps/sage-6.4/local/lib/python2.7/site-packages/sage/numerical/all.py", line 1, in <module>
from optimize import (find_fit,
File "/home/eric/apps/sage-6.4/local/lib/python2.7/site-packages/sage/numerical/optimize.py", line 14, in <module>
from sage.modules.free_module_element import vector
File "sage/rings/integer.pxd", line 9, in init sage.modules.free_module_element (build/cythonized/sage/modules/free_module_element.c:36437)
File "sage/rings/rational.pxd", line 10, in init sage.rings.integer (build/cythonized/sage/rings/integer.c:41630)
File "sage/rings/rational.pyx", line 56, in init sage.rings.rational (build/cythonized/sage/rings/rational.c:30843)
File "/home/eric/apps/sage-6.4/local/lib/python2.7/site-packages/sage/rings/rational_field.py", line 55, in <module>
import infinity
File "/home/eric/apps/sage-6.4/local/lib/python2.7/site-packages/sage/rings/infinity.py", line 213, in <module>
from sage.rings.integer_ring import ZZ
File "sage/rings/integer_ring.pyx", line 67, in init sage.rings.integer_ring (build/cythonized/sage/rings/integer_ring.c:11566)
File "/home/eric/apps/sage-6.4/local/lib/python2.7/site-packages/sage/structure/factorization.py", line 188, in <module>
from sage.misc.all import prod
File "/home/eric/apps/sage-6.4/local/lib/python2.7/site-packages/sage/misc/all.py", line 89, in <module>
from functional import (additive_order,
File "/home/eric/apps/sage-6.4/local/lib/python2.7/site-packages/sage/misc/functional.py", line 36, in <module>
from sage.rings.complex_double import CDF
File "sage/rings/real_double.pxd", line 8, in init sage.rings.complex_double (build/cythonized/sage/rings/complex_double.c:20095)
File "sage/rings/real_double.pyx", line 56, in init sage.rings.real_double (build/cythonized/sage/rings/real_double.c:22825)
ImportError: cannot import name ZZ

The problem concerns a simple import that now does not work. I just putted these two lines in my "debug.py" script:

from sage.numerical.mip import MixedIntegerLinearProgram
print MixedIntegerLinearProgram.__doc__

I re-compiled my sources but the problem remains. Notebook still works just fine.

Any thoughts ?
To be honest, I don't know the ZZ module.

Any help would be appreciated.

Kind regards,


Vincent Delecroix

Jan 28, 2015, 12:50:09 PM1/28/15
to sage-s...@googlegroups.com

If you want to run *pure* python you should use

sage -python my_file.py

By pure Python I mean which does not need any of the Sage stuff like
ZZ. If you want to run your file just do

sage my_file.py


2015-01-28 18:43 UTC+01:00, Eric Parent <er...@eparent.info>:
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.

Eric Parent

Jan 28, 2015, 1:03:03 PM1/28/15
to sage-s...@googlegroups.com

sage debug.py

does not resolve my issue.

I was looking around in the ask.sagemath.org site and found this post : http://ask.sagemath.org/question/10173/run-python-file-from-command-line-in-sage/. Someone fixed similar issues adding this line to the beginning of the Python script:

from sage.all import *

So I tried and it fixed my problem !

I'm afraid I may be importing *way* too many things in my namespace but for now, it'll do the job.

Anybody has hints on why this is required ?

Does that has the effect of activating sage's virtual environment setup (kind of) ?

Kind regards,


Jeroen Demeyer

Jan 28, 2015, 2:43:46 PM1/28/15
to sage-s...@googlegroups.com
On 2015-01-28 19:03, Eric Parent wrote:
> from sage.all import *
You don't actually have to import *

The following would also work:

import sage.all
from sage.numerical.mip import MixedIntegerLinearProgram

Or even

from sage.all import MixedIntegerLinearProgram

> Anybody has hints on why this is required ?
Sage contains a lot of circular imports. Modules have to be imported in
exactly the right order otherwise things break.
Reply all
Reply to author
0 new messages