thorek1 / MacroModelling.jl

Macros and functions to work with DSGE models.
https://thorek1.github.io/MacroModelling.jl/stable
MIT License
98 stars 15 forks source link

Installation fails #33

Closed gdalle closed 1 year ago

gdalle commented 1 year ago

Hi there, congrats on the package! I'm reviewing your JOSS submission, so expect more issues from me as I make my way through the checklist :)

https://github.com/openjournals/joss-reviews/issues/5598

When I try to install MacroModelling.jl, some Python compatibility issues pop up. I strongly suggest you use PythonCall.jl + CondaPkg.jl to manage your Python dependencies. As the following bug suggests, PyCall is less reliable and reproducible.

```julia (@v1.9) pkg> activate --temp Activating new project at `/tmp/jl_ZNvdrc` (jl_ZNvdrc) pkg> add MacroModelling ... Precompiling project... ✗ MacroModelling 0 dependencies successfully precompiled in 2 seconds. 196 already precompiled. 1 dependency errored. To see a full report either run `import Pkg; Pkg.precompile()` or load the package julia> using MacroModelling [ Info: Precompiling MacroModelling [687ffad2-3618-405e-ac50-e0f7b9c75e44] ERROR: LoadError: InitError: Failed to import required Python module sympy. For automated sympy installation, try configuring PyCall to use the Conda.jl package's Python "Miniconda" distribution within Julia. Relaunch Julia and run: ENV["PYTHON"]="" Pkg.build("PyCall") before trying again. Note that Conda.jl can use custom conda environment. Read more about `CONDA_JL_HOME` configuration in Conda.jl documentation: https://github.com/JuliaPy/Conda.jl To install sympy using /home/guillaume/mambaforge/bin/conda, you can run the following command from your system shell: /home/guillaume/mambaforge/bin/conda install sympy The pyimport exception was: PyError (PyImport_ImportModule The Python package sympy could not be imported by pyimport. Usually this means that you did not install sympy in the Python version being used by PyCall. PyCall is currently configured to use the Python version at: /home/guillaume/mambaforge/bin/python3 and you should use whatever mechanism you usually use (apt-get, pip, conda, etcetera) to install the Python package containing the sympy 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 sympy module, you can use `pyimport_conda("sympy", PKG)`, where PKG is the Anaconda package that contains the module sympy, or alternatively you can use the Conda package directly (via `using Conda` followed by `Conda.add` etcetera). ) ModuleNotFoundError("No module named 'sympy'") ```
thorek1 commented 1 year ago

this one is about sympy (python package) not being there. essentially you need to make sure julia talks to python (SymPy.jl relies on PyCall.jl and Conda.jl) and has sympy installed in the python environment linked to julia. In a previous version I tried to automatise this with CondaPkg but it had no effect in my case. I will try again with the latest version.

gdalle commented 1 year ago

essentially you need to make sure julia talks to python (SymPy.jl relies on PyCall.jl and Conda.jl) and has sympy installed in the python environment linked to julia.

I figured as much, but I tried installing it the naive way by just following the instructions in the README, which didn't mention anything about setting up Python :)

In a previous version I tried to automatise this with CondaPkg but it had no effect in my case. I will try again with the latest version.

The main advantage of CondaPkg is that it dispenses the user from having to fight with Python themselves. I've used it successfully several times, happy to help if needed

thorek1 commented 1 year ago

I added CondaPkg and sympy as a python dependency. it worked on the Julia linux docker image out of the box. thx for the hint.

thorek1 commented 1 year ago

This seems trickier than i thought. SymPy.jl relies on PyCall->Conda I understand this setup does not guarantee automatic installation of the sympy python package but using PythonCall->CondaPkg would. let me check whether importing it using pythoncall ensures the same functionality as SymPy.jl

thorek1 commented 1 year ago

I got it to work with PythonCall as a backend and tested it in a separate branch. The issue is I don't get PythonCall to work with PrecompileTools. Do you have any experience with this?

It would be a petty sacrificing some speed for convenience.

On the PythonCall website it says during precompilation you must not interact with python...

thorek1 commented 1 year ago

and I got that fixed now as well. I'm not relying on python during recompilation after all.

have a look at the latest version. it should run out of the box. it does in the CI runs at least.

and thanks for the suggestion to use PythonCall that should make it easier for many users to get this up and running

gdalle commented 1 year ago

Awesome! I'll check it out and finish my review next week

gdalle commented 1 year ago

https://github.com/jverzani/SymPyCall.jl

Might be interesting

thorek1 commented 1 year ago

Yeah, I implemented an adapted version of their code in the latest version of MacroModelling. It works with CondaPkg now and the installation should work out of the box. I asked the SymPyCall authors to register their package so that I can use that instead my hacky way.

gdalle commented 1 year ago

Should have known it was not a coincidence 😎

gdalle commented 1 year ago

Installation is working