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

SciPy causes trouble on my Linux Installation #48

Closed
StefanPofahl opened this issue Aug 21, 2022 · 8 comments · Fixed by #49
Closed

SciPy causes trouble on my Linux Installation #48

StefanPofahl opened this issue Aug 21, 2022 · 8 comments · Fixed by #49

Comments

@StefanPofahl
Copy link

Hi,
thanks for the fantastic package. It might be that it is not entirely an SciPy.jl issue.
Following fails as well, no matter, if I use JuliaRTS or Julia v1.8.0:

using PyCall
py"""
from scipy import signal
"""

But maybe you know better to whom it might concern.

Below is my error output. I hope it helps.

Regards,

Stefan

ERROR: InitError: PyError (PyImport_ImportModule

The Python package scipy could not be imported by pyimport. Usually this means
that you did not install scipy in the Python version being used by PyCall.

PyCall is currently configured to use the Python version at:

/usr/bin/python3

and you should use whatever mechanism you usually use (apt-get, pip, conda,
etcetera) to install the Python package containing the scipy module.

One alternative is to re-configure PyCall to use a different Python
version on your system: set ENV["PYTHON"] to the path/name of the python
executable you want to use, run Pkg.build("PyCall"), and re-launch Julia.

Another alternative is to configure PyCall to use a Julia-specific Python
distribution via the Conda.jl package (which installs a private Anaconda
Python distribution), which has the advantage that packages can be installed
and kept up-to-date via Julia.  As explained in the PyCall documentation,
set ENV["PYTHON"]="", run Pkg.build("PyCall"), and re-launch Julia. Then,
To install the scipy module, you can use `pyimport_conda("scipy", PKG)`,
where PKG is the Anaconda package that contains the module scipy,
or alternatively you can use the Conda package directly (via
`using Conda` followed by `Conda.add` etcetera).

) <class 'ModuleNotFoundError'>
ModuleNotFoundError("No module named 'scipy'")

Stacktrace:
  [1] pyimport(name::String)
    @ PyCall ~/.julia/packages/PyCall/7a7w0/src/PyCall.jl:550
  [2] pyimport_conda(modulename::String, condapkg::String, channel::String)
    @ PyCall ~/.julia/packages/PyCall/7a7w0/src/PyCall.jl:708
  [3] pyimport_conda
    @ ~/.julia/packages/PyCall/7a7w0/src/PyCall.jl:707 [inlined]
  [4] __init__()
    @ SciPy ~/.julia/packages/SciPy/uXpRL/src/SciPy.jl:419
  [5] _include_from_serialized(path::String, depmods::Vector{Any})
    @ Base ./loading.jl:696
  [6] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String)
    @ Base ./loading.jl:782
  [7] _require(pkg::Base.PkgId)
    @ Base ./loading.jl:1020
  [8] require(uuidkey::Base.PkgId)
    @ Base ./loading.jl:936
  [9] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:923
 [10] eval
    @ ./boot.jl:360 [inlined]
 [11] include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String)
    @ Base ./loading.jl:1116
 [12] include_string(m::Module, txt::String, fname::String)
    @ Base ./loading.jl:1126
 [13] invokelatest(::Any, ::Any, ::Vararg{Any, N} where N; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base ./essentials.jl:708
 [14] invokelatest(::Any, ::Any, ::Vararg{Any, N} where N)
    @ Base ./essentials.jl:706
 [15] inlineeval(m::Module, code::String, code_line::Int64, code_column::Int64, file::String; softscope::Bool)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.7.5/scripts/packages/VSCodeServer/src/eval.jl:233
 [16] (::VSCodeServer.var"#64#68"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.7.5/scripts/packages/VSCodeServer/src/eval.jl:157
 [17] withpath(f::VSCodeServer.var"#64#68"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.7.5/scripts/packages/VSCodeServer/src/repl.jl:249
 [18] (::VSCodeServer.var"#63#67"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.7.5/scripts/packages/VSCodeServer/src/eval.jl:155
 [19] hideprompt(f::VSCodeServer.var"#63#67"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.7.5/scripts/packages/VSCodeServer/src/repl.jl:38
 [20] (::VSCodeServer.var"#62#66"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.7.5/scripts/packages/VSCodeServer/src/eval.jl:126
 [21] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging ./logging.jl:491
 [22] with_logger
    @ ./logging.jl:603 [inlined]
 [23] (::VSCodeServer.var"#61#65"{VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.7.5/scripts/packages/VSCodeServer/src/eval.jl:225
 [24] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [25] invokelatest(::Any)
    @ Base ./essentials.jl:706
 [26] macro expansion
    @ ~/.vscode/extensions/julialang.language-julia-1.7.5/scripts/packages/VSCodeServer/src/eval.jl:34 [inlined]
 [27] (::VSCodeServer.var"#59#60")()
    @ VSCodeServer ./task.jl:417
during initialization of module SciPy

@AtsushiSakai
Copy link
Owner

Can you try this?

As explained in the PyCall documentation,
set ENV["PYTHON"]="", run Pkg.build("PyCall"), and re-launch Julia. Then,
To install the scipy module, you can use `pyimport_conda("scipy", PKG)`,
where PKG is the Anaconda package that contains the module scipy,
or alternatively you can use the Conda package directly (via
`using Conda` followed by `Conda.add` etcetera).

@StefanPofahl
Copy link
Author

Thanks for the response!
This advice was helpful in my situation:
fft GLIBC issue

@AtsushiSakai
Copy link
Owner

So, your issue was solved?

@StefanPofahl
Copy link
Author

I would not say so. - Maybe a warning might be helpful, or a note in your readme.md about known issues.
Maybe also an exchange with the PyCall.jl experts might be helpful? - What do you think?

P.S.:
Thanks for your package!!! :-)

@terasakisatoshi
Copy link
Collaborator

There are two things that many Pythonista should take care of when it comes to calling Python functionalities from Julia.

  1. Select Python environment.

We have to tell PyCall which Python executable we want to use. In most cases the following instructions will suffice for Pythonista

$ julia
julia> ENV["PYTHON"] = Sys.which("python3")
julia> using Pkg; Pkg.add("PyCall"); Pkg.build("PyCall")
julia> exit()
$ julia # re-launch
julia> using SciPy

where Sys.which("python3") works like which command available in Unix and Unix-like systems.

We can skip Pkg.add("PyCall") if we installed PyCall already.

  1. Make sure we have installed scipy in the Python environment we selected above.

If we get an error message including ModuleNotFoundError("No module named 'scipy'"),
we should've installed scipy in advance. Just run:

$ pip3 install scipy

and re-launch Julia again.

@terasakisatoshi
Copy link
Collaborator

For those who are not familiar with Python (or want to avoid using system-wide Python), just do:

$ julia
julia> ENV["PYTHON"] = ""
julia> using Pkg; Pkg.add("PyCall"); Pkg.build("PyCall")
julia> exit() # exit current Julia's session
$ julia # re-launch
julia> using SciPy # it will install scipy automatically via Conda.jl

It will install a minimal Python distribution (via Miniconda) that is private to Julia. (See ~/.julia/conda/3/bin in case you're interested)

This instruction abstracts setting a Python environment and allows us to use Python libraries from Julia out of the box.

Since the current (as of September, 2022) Conda.jl introduces Python 3.10 which is relative new, some people may get issues about GLIBCXX or libstdc++ as discussed in Julia discourse e.g. https://discourse.julialang.org/t/glibcxx-version-not-found/82209

As discussed in this issue/comment one should adjust the version of scipy as necessary.

@terasakisatoshi
Copy link
Collaborator

Maybe a warning might be helpful, or a note in your readme.md about known issues.

It is a good idea to guide the reader through the relevant issues.

I'll update README.md of SciPy.jl.

@StefanPofahl
Copy link
Author

Thanks for your effort! :-)

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

Successfully merging a pull request may close this issue.

3 participants