Ask Your Question
-1

Problem importing Sage library in Python script on Windows

asked 2020-01-08 19:52:08 +0200

mattb gravatar image

I have a script that is fully operational which uses Sage as a python library in my python script. It runs completely normal on MacOS. However, when I tried to transfer this to work, where we are on Windows, I cannot load Sage in my python script. I get a ModuleNotFoundError.

Some background on this. My MacOS setup was generated via miniconda, including the conda package install of sage. Really, I'm only using Sage for a nice python friendly interface to Maxima, where I can do some very complex symbolic matrix computations very quickly.

On Windows, I was using MSYS2. However, after reading that Sage does not support this whatsoever, I installed Cygwin. Everything, except Sage, is running fine on Cygwin. I installed Sage via the Windows installer.

What do I need to do with the installation to get my python script to find Sage?

As an aside, is there a reason why there is no conda package for Sage on Windows, only Linux and MacOS? Trying to install Sage on Windows has been an all day, 2 day nightmare, and it is still not working. The Windows installer works fine if you just want to use Sage completely standalone. But it seems completely incompatible for integration with other languages/tools. I even tried to self compile. It took ~5-6 hours, then I got an error that one of the packages, bleach, failed. When I looked at the log for that, it seems like there was a connection issue and the source could not be downloaded. This all seems like complete overkill for using Sage in a python script.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-01-09 12:10:57 +0200

Iguananaut gravatar image

I'm not sure what you mean exactly by "using Sage in a Python script". You didn't really provide any details.

Sage has always traditionally included its own Python interpreter, and so using Sage meant you'd have to run the Python interpreter that comes with Sage (if you're at all familiar with conda as you say, this is a little like having its own conda environment). The folks who've packaged Sage for conda make that a little more transparent, since you can now install sage directly in a conda environment. But either way it's effectively similar.

What do I need to do with the installation to get my python script to find Sage?

You will need to run it with the Python interpreter that comes with Sage. If you have additional dependencies, as I wrote, this is a complete Python environment so you can pip install them using Sage's Python.

As an aside, is there a reason why there is no conda package for Sage on Windows, only Linux and MacOS?

Because Sage on Windows depends on Cygwin, and there is no official Cygwin target for conda. There could be, and it's something I would like there to be, but it would be a large effort for which there is currently no support.

But it seems completely incompatible for integration with other languages/tools.

Not necessarily but it is a little tricky. Search this site for other questions like this one where I explain how to use Sage in PyCharm--again it's not all that different from using a virtualenv; still just a little trickier. If you have any good ideas for how to make this easier I'm all for it.

When I looked at the log for that, it seems like there was a connection issue and the source could not be downloaded.

I noticed also there were some problems with some connection problems with some of the mirrors yesterday. Try just running make again and the build should resume where it left off. If you followed the instructions here it should work.

Sage is a complex beast: Its large set of non-standard and/or tightly-pinned dependencies makes it non-trivial to install and use compared to a normal Python package. People have been working hard for years to make that easier (see, again, your success with conda) but this is not easy. You're welcome to lend a hand if you have any insights.

edit flag offensive delete link more

Comments

OK, so it's a bit of a misunderstanding on my part. SageMath is actually a complete environment, not just an add in package. I did try to run in sage, but I couldn't seem to figure out how to load the other needed packages into the sage environment. I'll do some more reading, including your link, to see if I can figure this one out. Unfortunately, Windows is such a pain to deal with all these things. I wish we were running Linux or Mac at work, but that is not the case.

if all I'm using SageMath for is a go between with Maxima, is there any scaled down implementation that doesn't necessarily need the SageMath environment?

mattb gravatar imagemattb ( 2020-01-09 13:38:28 +0200 )edit

SageMath is really two things: There's what's referred to sometimes as "sagelib": the actual sage Python package, and then there's "Sage the Distribution" consisting of sagelib and all its dependencies. Though there's been some work done toward making Sage installable with pip like any Python package (there's no strong reason Sage needs its own Python interpreter) it's still non-trivial because you need most of the dependencies already in place. An (outdated) list of those dependencies is here. Some of those are optional, but many non-trivial ones are very integral. conda makes it seem easy because it can pull in all those dependencies, but outside that context it's not trivial.

Iguananaut gravatar imageIguananaut ( 2020-01-09 14:57:57 +0200 )edit

If you can be more specific about what exactly you tried to do and where you got stuck I might be able to give a more precise answer.

Iguananaut gravatar imageIguananaut ( 2020-01-09 14:58:21 +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

1 follower

Stats

Asked: 2020-01-08 19:52:08 +0200

Seen: 591 times

Last updated: Jan 09 '20