Closed glatterf42 closed 5 months ago
AttributeError: 'message_ix' has no attribute 'Scenario'
I know I've seen these before and I don't know if the cause is always the same.
AFAICT, this happens in the following case:
message_ix
(whether from a local directory or from PyPI or GitHub directly).pip install --editable .
.What happens in this case is that the editable install files are created in their site-packages/
directly, but an empty directory site-packages/message_ix/
is left behind from the regular install. IOW, pip removes the files but not the directory for the existing, regular install.
When the user next tries to import message_ix
, Python finds the empty directory site-pacakges/message_ix/
and imports it, but this contains absolutely nothing, hence the API is not usable.
The fix I've tried is to first pip uninstall message-ix
before pip install --editable .
. This has worked in all cases I've encountered (regardless of whether users are using conda, venv, etc. or not).
Great, thanks! We can include this possible fix for the issue in a Known issue
with the same PR :)
Recently, I helped a colleague resolve installation issues involving conda and pip. The error message they received was (not too sure about the error name):
I know I've seen these before and I don't know if the cause is always the same. If I remember correctly, I usually advised people to install everything from scratch in a new venv, which also solved the problem. This time, however, I understood the issue in more detail: The colleague had used conda to install message_ix, but now wanted to utilize a specific branch, so tried to upgrade to an installation from source. Of course, pip and conda don't mix well, but in theory, using pip after conda and then sticking with pip is fine in conda-managed venvs. However, the user had a global pip installation (referring to the global Python interpreter, that is), but none in their conda-venv. So they tried running
pip install
and it succeeded, but not in the way they wanted to. We were able to solve this problem by creating a new venv with conda, using conda to install pip in there, and then only using pip to install the message stack.So my suggestion here is to include a note about similar issues in the 'full' installation guide once we manage to separate 'full' and 'quick'. It should go something like this (although it could be expanded to cover the install from pypi, too):