# Problem using SymPy

**URL:** <https://discourse.julialang.org/t/problem-using-sympy/98012>\
**Category:** New to Julia\
**Tags:** sympy\
**Created:** [April 27, 2023, 8:08pm UTC](https://discourse.julialang.org/t/problem-using-sympy/98012 "2023-04-27T20:08:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joeit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joeit/32/49330_2.png) [@joeit](https://discourse.julialang.org/u/joeit)\
**Post date:** [April 27, 2023, 8:08pm UTC](https://discourse.julialang.org/t/problem-using-sympy/98012/1 "2023-04-27T20:08:11Z")

</div>

Hi everybody, I am new to Julia and I would like to use the sympy functionalities.  
I have Julia 1.8 installed on Mac OS, with python 3.  
The SymPy package throws the error below.  
Any clue?  
Thanks  
Joe

**julia\>** using SymPy

**ERROR:** InitError: KeyError: key :pi not found

Stacktrace:

[1] **\_\_getproperty**

@ ~/.julia/packages/PyCall/twYvK/src/PyCall.jl:313 [inlined]

[2] **getproperty(o::PyCall.PyObject, s::Symbol)**

@ PyCall ~/.julia/packages/PyCall/twYvK/src/PyCall.jl:318

[3] **init()**

@ SymPy ~/.julia/packages/SymPy/gkr7m/src/SymPy.jl:131

[4] **\_include\_from\_serialized(pkg::Base.PkgId, path::String, depmods::Vector{Any})**

@ Base ./loading.jl:831

[5] **\_require\_search\_from\_serialized(pkg::Base.PkgId, sourcepath::String, build\_id::UInt64)**

@ Base ./loading.jl:1039

[6] **\_require(pkg::Base.PkgId)**

@ Base ./loading.jl:1315

[7] **\_require\_prelocked(uuidkey::Base.PkgId)**

@ Base ./loading.jl:1200

[8] **macro expansion**

@ ./loading.jl:1180 [inlined]

[9] **macro expansion**

@ ./lock.jl:223 [inlined]

[10] **require(into::Module, mod::Symbol)**

@ Base ./loading.jl:1144

during initialization of module SymPy

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [April 27, 2023, 9:59pm UTC](https://discourse.julialang.org/t/problem-using-sympy/98012/2 "2023-04-27T21:59:52Z")

</div>

Does something like this work?

```julia
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.pi
PyObject pi

```

---

<div class="post-metadata">

**Author:** ![joeit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joeit/32/49330_2.png) [@joeit](https://discourse.julialang.org/u/joeit)\
**Post date:** [May 24, 2023, 6:55am UTC](https://discourse.julialang.org/t/problem-using-sympy/98012/3 "2023-05-24T06:55:08Z")

</div>

Hi, thanks for your reply. Unfortunately, it does not work:

```julia
**julia>** using PyCall

**julia>** sympy = PyCall.pyimport_conda("sympy", "sympy")

PyObject <module 'sympy' (<_frozen_importlib_external._NamespaceLoader object at 0x136533970>)>

**julia>** sympy.pi

**ERROR:** KeyError: key :pi not found

Stacktrace:

[1] **__getproperty**

@ ~/.julia/packages/PyCall/twYvK/src/PyCall.jl:313 [inlined]

[2] **getproperty(**o::PyObject, s::Symbol**)**

@ PyCall ~/.julia/packages/PyCall/twYvK/src/PyCall.jl:318

[3] top-level scope

@ REPL[3]:1

**julia>**

```

Edt: could it possibly be a clash between homebrew python and conda python?

---

<div class="post-metadata">

**Author:** ![fgerick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fgerick/32/13228_2.png) [@fgerick](https://discourse.julialang.org/u/fgerick)\
**Post date:** [May 24, 2023, 8:20am UTC](https://discourse.julialang.org/t/problem-using-sympy/98012/4 "2023-05-24T08:20:20Z")

</div>

anything is possible!

> **[Python Environment](https://xkcd.com/1987/)**
>
> The Python environmental protection agency wants to seal it in a cement chamber, with pictorial messages to future civilizations warning them about the danger of using sudo to install random Python packages.

---

<div class="post-metadata">

**Author:** ![joeit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joeit/32/49330_2.png) [@joeit](https://discourse.julialang.org/u/joeit)\
**Post date:** [June 3, 2023, 8:07am UTC](https://discourse.julialang.org/t/problem-using-sympy/98012/5 "2023-06-03T08:07:17Z")

</div>

Hi, I upgraded my installation to 1.9. I also removed the brew installation of python and left only conda in my system. Conda and brew are know to be not working well together. Now Pycall works.

```julia
julia> using PyCall
julia> sympy = PyCall.pyimport_conda("sympy", "sympy")
PyObject <module 'sympy' from '/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/sympy/ __init__.py'>
julia> sympy.pi
PyObject pi

```

The SymPy package also works flawlessly:

```julia
julia> using SymPy

julia> x = symbols("x")
x

julia> y = sin(pi*x)
sin(π⋅x)

julia> y(1)   
0

```

I think it was a conda+brew problem, a problem that users should be warned about.
