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

Update install instructions with note about using conda and pip together #835

Closed
glatterf42 opened this issue Apr 26, 2024 · 2 comments · Fixed by #843
Closed

Update install instructions with note about using conda and pip together #835

glatterf42 opened this issue Apr 26, 2024 · 2 comments · Fixed by #843
Assignees
Labels
docs Documentation
Milestone

Comments

@glatterf42
Copy link
Member

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):

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. 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):

.. note::
   Installing from source requires using ``pip``. We strongly recommend installing in a virtual environment (venv), so for these steps, we strongly recommend using a venv managing tool that is pip-compatible like `python's venv <https://docs.python.org/3/library/venv.html>`__, `pipenv <https://pipenv.pypa.io/en/latest/>`__, or `virtualenv <https://virtualenv.pypa.io/en/latest/user_guide.html>`__, to name just a few.
  
   If you insist on using ``conda`` to mange your venv, please read `conda's guide to using pip in a venv <https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#using-pip-in-an-environment>`__. In particular, please make sure you use ``conda`` only to install ``pip`` in your venv and then use that specific ``pip`` for all further install commands.
@glatterf42 glatterf42 added the docs Documentation label Apr 26, 2024
@glatterf42 glatterf42 added this to the 3.9 milestone Apr 26, 2024
@glatterf42 glatterf42 self-assigned this Apr 26, 2024
@khaeru
Copy link
Member

khaeru commented Apr 26, 2024

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:

  • User first makes a regular install of message_ix (whether from a local directory or from PyPI or GitHub directly).
  • User next wants to switch to using an editable install from local source, e.g. a Git repo directory.
  • User does 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).

@glatterf42
Copy link
Member Author

Great, thanks! We can include this possible fix for the issue in a Known issue with the same PR :)

@glatterf42 glatterf42 linked a pull request May 23, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants