iiasa/ixmp

AttributeError: module 'ixmp' has no attribute 'config'

ravitby opened this issue · 5 comments

The output for the following command mix-models il-transport run S1 reported --go is:

Traceback (most recent call last):
  File "/Users/ravitb/Workspace/venv/message-env/bin/mix-models", line 5, in <module>
    from message_ix_models.cli import main
  File "/Users/ravitb/Workspace/TAU/ilTransport/message-ix-models/message_ix_models/__init__.py", line 7, in <module>
    from message_ix_models.util._logging import setup as setup_logging
  File "/Users/ravitb/Workspace/TAU/ilTransport/message-ix-models/message_ix_models/util/__init__.py", line 29, in <module>
    from .cache import cached
  File "/Users/ravitb/Workspace/TAU/ilTransport/message-ix-models/message_ix_models/util/cache.py", line 23, in <module>
    from .context import Context
  File "/Users/ravitb/Workspace/TAU/ilTransport/message-ix-models/message_ix_models/util/context.py", line 13, in <module>
    from .config import Config
  File "/Users/ravitb/Workspace/TAU/ilTransport/message-ix-models/message_ix_models/util/config.py", line 13, in <module>
    ixmp.config.register("no message_data", bool, False)
AttributeError: module 'ixmp' has no attribute 'config'```

ixmp does generally have the attribute config. So I suspect there is something wrong with the installation. It might be that message_ix_models and ixmp were installed in different virtual environments or that ixmp wasn't installed in message_ix_models' venv and a global version of the package was used. From your output alone, it's impossible to tell. Could you please include the output of ixmp show-versions, maybe compared to mix-models show-versions?

Thank you, this is the output of the ixmp show-versions:


ixmp:        3.8.1.dev30+g6d1f86c
     6d1f86c (HEAD -> main, origin/main, origin/HEAD) Bump jinja2 from 3.1.3 to 3.1.4 in /doc (#528)
message_ix:  3.8.1.dev73+g27cd54e
     27cd54e (HEAD -> main, upstream/main, origin/main, origin/HEAD) Bump jinja2 from 3.1.3 to 3.1.4 in /doc (#837)
message_ix_models: 2024.4.23.dev26+g31950edb
     31950edb (HEAD -> main, origin/main, origin/HEAD) Merge pull request #190 from iiasa/costs/final-year-2110
message_data: 2020.6.21.dev3042+gda556bf4e
     f9fa0f4da (HEAD -> il/transport-2024-01-20, origin/il/transport-2024-01-20) Revert input data to the original state

click:       8.1.7
dask:        2024.5.0
genno:       installed
graphviz:    0.20.3
jpype:       1.4.0
… JVM path:  /Library/Java/JavaVirtualMachines/jdk-22.jdk/Contents/Home/lib/libjli.dylib
openpyxl:    3.1.2
pandas:      2.2.2
pint:        0.23
xarray:      2024.3.0
yaml:        6.0.1

iam_units:   installed
jupyter:     1.0.0
matplotlib:  3.7.0
plotnine:    0.13.6
pyam:        1.9.0

GAMS:        'gams' executable not in PATH

python:      3.9.6 (default, Feb  3 2024, 15:58:27)
[Clang 15.0.0 (clang-1500.3.9.4)]
python-bits: 64
OS:          Darwin
OS-release:  23.2.0
machine:     arm64
processor:   arm
byteorder:   little
LC_ALL:      None
LANG:        en_US.UTF-8
LOCALE:      (None, 'UTF-8')```

This is mostly looking good, but 'gams' executable not in PATH might create issues down the line. You can try to troubleshoot this with step 3 here.

The versions of ixmp and message-ix-models are recent, so that's not the issue here. Could you please see if mix-models show-versions shows the same versions? If not, please detail the differences.

I suspect this is an instance of the case we have discussed previously @glatterf42 (I don't recall if we have recorded in a particular issue or installation tip the way to avoid it):

  • User makes a regular install of a package, e.g. ixmp, using pip from PyPI.
  • User then makes a editable install of the same package without first uninstalling.
  • This results in pip failing to entirely clean up the first install. In particular, there will be a directory like …/site-packages/ixmp/ that is completely empty.
  • When other code later tries to import ixmp, Python finds this empty directory to be an (empty) package named ixmp, and loads this (it does not go on to find and load the editable install).

We see the Git info for ixmp from the show-versions output, so this is consistent with an editable install per the above steps.

The fix is to first uninstall the package, entirely, and then do the editable install.

@ravitby can you please try that and report whether it resolves the issue?

Thanks @khaeru , I reinstalled ixmp and the issue was solved.