Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gett KeyError: 'scale' from GitHub example #65

Closed
OrbitalMechanic opened this issue May 4, 2020 · 11 comments
Closed

Gett KeyError: 'scale' from GitHub example #65

OrbitalMechanic opened this issue May 4, 2020 · 11 comments

Comments

@OrbitalMechanic
Copy link

OrbitalMechanic commented May 4, 2020

I'm attempting to run the example posted on the GitHub page for diffeqpy. I've installed diffeqpy successfully on a Mac Pro (2019) running Mac OS X 10.15.4 (Catalina). I'm running the Anaconda distribution for Python ver. 3.7.6.

The code I'm running is the following:

#!/Users/user/opt/anaconda3/bin/python
from diffeqpy import de

def f(u,p,t):
    return -u

u0 = 0.5
tspan = (0., 1.)
prob = de.ODEProblem(f, u0, tspan)
sol = de.solve(prob)

print( "\n\n")
print( " sol   = ", sol   )
print( "\n\n")
print( " sol.t = ", sol.t )
print( " sol.u = ", sol.u )
print( "\n\n")

import matplotlib.pyplot as plt
plt.plot( sol.t, sol.u )
plt.show()

The problem I'm running into seems to be in Matplotlib:

(base) user@Samuels-Mac-Pro ~ % python-jl diffeqpy-ex-1.py
┌ Warning: `getindex(o::PyObject, s::Symbol)` is deprecated in favor of dot overloading (`getproperty`) so elements should now be accessed as e.g. `o.s` instead of `o[:s]`.
│   caller = top-level scope at none:4
└ @ Core none:4



 sol   =  <PyCall.jlwrap retcode: Success
Interpolation: Automatic order switching interpolation
t: [0.0, 0.10003996803834632, 0.3421523089031354, 0.6555323945666935, 1.0]
u: [0.5, 0.45240062712255974, 0.35512001851684183, 0.2595828347330421, 0.18393979662761353]>



 sol.t =  [0.         0.10003997 0.34215231 0.65553239 1.        ]
 sol.u =  [0.5        0.45240063 0.35512002 0.25958283 0.1839398 ]



Traceback (most recent call last):
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/julia/pseudo_python_cli.py", line 308, in main
    python(**vars(ns))
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/julia/pseudo_python_cli.py", line 59, in python
    scope = runpy.run_path(script, run_name="__main__")
  File "/Users/user/.julia/conda/3/lib/python3.7/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/Users/user/.julia/conda/3/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/Users/user/.julia/conda/3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "diffeqpy-ex-1.py", line 19, in <module>
    import matplotlib.pyplot as plt
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/matplotlib/pyplot.py", line 40, in <module>
    from matplotlib.figure import Figure, figaspect
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/matplotlib/figure.py", line 20, in <module>
    from matplotlib import backends, docstring, projections
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/matplotlib/projections/__init__.py", line 4, in <module>
    from mpl_toolkits.mplot3d import Axes3D
  File "/Users/user/.julia/conda/3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/__init__.py", line 1, in <module>
    from .axes3d import Axes3D
  File "/Users/user/.julia/conda/3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 42, in <module>
    class Axes3D(Axes):
  File "/Users/user/.julia/conda/3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 52, in Axes3D
    azim=-60, elev=30, zscale=None, sharez=None, proj_type='persp',
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/matplotlib/docstring.py", line 116, in dedent_interpd
    return interpd(func)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/matplotlib/docstring.py", line 40, in __call__
    func.__doc__ %= self.params
KeyError: 'scale'
(base) user@Samuels-Mac-Pro ~ %

The statement executing plt.plot seems to be okay, but I get KeyError: 'scale', which I do not understand.

Any suggestions?

Sam Dupree.

@tkf
Copy link
Contributor

tkf commented May 4, 2020

It's failing at import matplotlib.pyplot as plt.

  • Does /Users/user/opt/anaconda3/bin/python -c "import matplotlib.pyplot as plt" work?
  • Does python-jl -c "import matplotlib.pyplot as plt" work?

@tkf
Copy link
Contributor

tkf commented May 4, 2020

Also, it's problematic that you have both /Users/user/opt/anaconda3/ and /Users/user/.julia/conda/3/. You can try re-build PyCall.jl by

import julia
julia.install()

Its output may tell us something useful, even if it fails.

@OrbitalMechanic
Copy link
Author

OrbitalMechanic commented May 4, 2020 via email

@OrbitalMechanic
Copy link
Author

OrbitalMechanic commented May 4, 2020 via email

@tkf
Copy link
Contributor

tkf commented May 4, 2020

It looks like you need to manually set up PyCall. See: https://github.com/JuliaPy/PyCall.jl#specifying-the-python-version

In short: Open julia REPL and then run

julia> ENV["PYTHON"] = "/Users/user/opt/anaconda3/bin/python"

julia> using Pkg

julia> Pkg.build("PyCall")

@OrbitalMechanic
Copy link
Author

OrbitalMechanic commented May 4, 2020 via email

@ChrisRackauckas
Copy link
Member

Now I'd like to ask what was it that led you to have me manually install PyCall? Nothing on diffeqpy's GitHub page would have led me to do that.

Yeah, we should probably add it to the README.

@tkf
Copy link
Contributor

tkf commented May 4, 2020

what was it that led you to have me manually install PyCall?

I wrote python-jl so I could guess what's wrong. I think python-jl and julia.install can print better error message or do a better error recovery like you did manually here.

Having said that, python-jl is still a fundamentally flaky tool to set up (as we observed in this issue; although it's nice when it works). I feel like I should be spending time on solving this in a more principled way (e.g., JuliaPy/PyCall.jl#612), if I were to tackle this problem.

@OrbitalMechanic
Copy link
Author

OrbitalMechanic commented May 5, 2020 via email

@tkf
Copy link
Contributor

tkf commented May 5, 2020

Would you elaborate a little concerning the first workaround discussed above? It not clear to me if that workaround is applicable to my case or applicable at all.

Did you try the workaround? That's the easiest way to check it if it works for you. Also, if you followed the link, there is an explanation: https://pyjulia.readthedocs.io/en/latest/troubleshooting.html#turn-off-compilation-cache. In particular:

Note that this option slows down loading and using Julia packages especially for complex and large ones.

By the way, please format your code snippet with tripe back quotes. It's hard to read. 😉

@ChrisRackauckas
Copy link
Member

Fixed by PythonCall transition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants