JuliaPy / SymPy.jl

Julia interface to SymPy via PyCall
http://juliapy.github.io/SymPy.jl/
MIT License
268 stars 62 forks source link

"Failed to precompile SymPy" #459

Closed BeauJSmith closed 2 years ago

BeauJSmith commented 2 years ago

Hello, All,

SymPy is giving me a bit of grief. Even though I can add the package, I can't seem to run it. When I type "using SymPy," I get the following stacktrace:

ImportError: No module named site
ERROR: LoadError: Failed to precompile SymPy [24249f21-da20-56a4-8eb1-6a02cf4ae2e6] to **[username]**
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, ignore_loaded_modules::Bool)
   @ Base ./loading.jl:1466
 [3] compilecache(pkg::Base.PkgId, path::String)
   @ Base ./loading.jl:1410
 [4] _require(pkg::Base.PkgId)
   @ Base ./loading.jl:1120
 [5] require(uuidkey::Base.PkgId)
   @ Base ./loading.jl:1013
 [6] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:997
 [7] include(fname::String)
   @ Base.MainInclude ./client.jl:451
 [8] top-level scope
   @ none:1

What causes this error, and how can I fix it?

Thank you!

jverzani commented 2 years ago

Can you give a hint as to your OS and Julia version. The last commit passed tests on the three main OSes.

BeauJSmith commented 2 years ago

Mac Mini M1 2020, macOS Monterey 12.2.1 Julia 1.7.2

jverzani commented 2 years ago

Hmm, I wonder if the mac has issues with sympy. It may be.

If you don't mind helping me debug this, would the following commands work:

julia> using PyCall

julia> sympy = PyCall.pyimport_conda("sympy", "sympy")
PyObject <module 'sympy' from '/Users/verzani/.julia/conda/3/lib/python3.7/site-packages/sympy/__init__.py'>

julia> sympy.symbols("x")
PyObject x
BeauJSmith commented 2 years ago

Here's what happens:

julia> using PyCall
ImportError: No module named site
jverzani commented 2 years ago

Hmm, that seem like an internet issue to me. Does

using PythonCall

work? It has, I believe, a different installation method for the underlying python.

BeauJSmith commented 2 years ago

I don't think it's an Internet issue. I'm able to download and include other packages, including PythonCall.

jverzani commented 2 years ago

Seems like it sits with PyCall. Mu understanding, which may be way out of date, is that the github CI only tests the newer macs with rosetta emulation, and this may be the issue. Then again, it maybe something else. I see this open issue https://github.com/JuliaPy/PyCall.jl/issues/960 which seems to be similar.

Now, if PythonCall works, you can access much of SymPy directly without this package. (The package does have many conveniences thought). Here is a sample:

using PythonCall
] conda add --pip sympy   <-- in package mode
# restart julia  <-- it seems necessary, may not be

julia> using PythonCall
    CondaPkg Found dependencies: /private/tmp/python_call/CondaPkg.toml
    CondaPkg Found dependencies: /Users/verzani/.julia/environments/v1.7/CondaPkg.toml
    CondaPkg Found dependencies: /Users/verzani/.julia/packages/PythonCall/Z6DIG/CondaPkg.toml
    CondaPkg Dependencies already up to date

julia> sympy = pyimport("sympy")
Python module: <module 'sympy' from '/private/tmp/python_call/.CondaPkg/env/lib/python3.10/site-packages/sympy/__init__.py'>

julia> x = sympy.symbols("x")
Python Symbol: x

julia> sympy.solve(x^2 -2, x)
Python list: [-sqrt(2), sqrt(2)]

julia> sympy.integrate(sympy.exp(x) * sympy.sin(x), x)
Python Add: exp(x)*sin(x)/2 - exp(x)*cos(x)/2

This bumps into warts pretty quickly though, as the right promotion rules aren't defined, etc. However, it can get pretty far with the basics.

BeauJSmith commented 2 years ago

It worked, and it does exactly what I need it to do.

Thank you so much!

jverzani commented 2 years ago

Great, glad to hear.