8000 add check if there is mix of local and non local installation by Czaki · Pull Request #7745 · napari/napari · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add check if there is mix of local and non local installation #7745

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Czaki
Copy link
Collaborator
@Czaki Czaki commented Mar 25, 2025

References and relevant issues

https://napari.zulipchat.com/#narrow/channel/212875-general/topic/ImportError.3A.20cannot.20import.20name.20'_magicgui'/near/508102720

Description

Check if there is a mix of local and non-local installation of napari and then stop process.

Works only if run napari as module python -m napari not when start napari from script.

@Czaki Czaki requested a review from a team as a code owner March 25, 2025 19:25
Copy link
codecov bot commented Mar 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.03%. Comparing base (4104e62) to head (311f39d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7745      +/-   ##
==========================================
+ Coverage   92.99%   93.03%   +0.03%     
==========================================
  Files         648      648              
  Lines       61457    61457              
==========================================
+ Hits        57155    57179      +24     
+ Misses       4302     4278      -24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator
@willingc willingc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion to make function name less specific.

def main():
# There a number of macOS issues we can fix with env vars
# and/or relaunching a subprocess
_check_editable_installation()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is not a macOS specific issue, it should go above the line comment.

Czaki and others added 2 commits March 25, 2025 21:59
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
@jni
Copy link
Member
jni commented Mar 26, 2025

@Czaki why not do it in napari init rather than main so that it works in all cases?

@jni
Copy link
Member
jni commented Mar 26, 2025

(but I like the idea very much)

@Czaki
Copy link
Collaborator Author
Czaki commented Mar 26, 2025

Hm. I need to fix this PR as this code will never be executed. The exception is raised before calling of added function.

Traceback (most recent call last):
  File "/Users/horst/miniconda3/envs/dingens/bin/napari", line 5, in <module>
    from napari.__main__ import main
  File "/Users/horst/Documents/python/napari/napari/__main__.py", line 18, in <module>
    from napari.errors import ReaderPluginError
  File "/Users/horst/Documents/python/napari/napari/errors/__init__.py", line 1, in <module>
    from napari.errors.reader_errors import (
  File "/Users/horst/Documents/python/napari/napari/errors/reader_errors.py", line 1, in <module>
    from napari.types import PathLike
  File "/Users/horst/Documents/python/napari/napari/types.py", line 191, in <module>
    _register_types_with_magicgui()
  File "/Users/horst/Documents/python/napari/napari/types.py", line 158, in _register_types_with_magicgui
    from napari.utils import _magicgui as _mgui
ImportError: cannot import name '_magicgui' from 'napari.utils' (unknown location)

@Czaki why not do it in napari init rather than main so that it works in all cases?

I do not want to be too aggressive. But maybe I should move this check on top of napari.__init__ to be sure that it is always executed?

@jni
Copy link
Member
jni commented Mar 26, 2025

I do not want to be too aggressive. But maybe I should move this check on top of napari.init to be sure that it is always executed?

Understood. Yeah it's a tricky question. But I think it's worth a check, especially if it's cheap.

@Czaki
Copy link
Collaborator Author
Czaki commented Mar 26, 2025

moved

@Czaki Czaki requested a review from jni March 26, 2025 14:36
@Czaki
Copy link
Collaborator Author
Czaki commented May 13, 2025

I will open PR to move to src layout just after 0.6.1 release

@jni
Copy link
Member
jni commented May 13, 2025

I will open PR to move to src layout just after 0.6.1 release

😮

Not opposed just... Lots of emotions 😂

TimMonko added a commit that referenced this pull request May 23, 2025
# References and relevant issues


# Description

This PR moves napari into `src` layout that prevents from multiple
problems from mixing local installation that led to multiple confusion
in the past.

After this, PR `python -m napari` or `import napari` should always use
napari version installed in the current environment.

It should unblock #7745

---------

Co-authored-by: Peter Sobolewski <76622105+psobolewskiPhD@users.noreply.github.com>
Co-authored-by: TimMonko <47310455+TimMonko@users.noreply.github.com>
Co-authored-by: Lorenzo Gaifas <brisvag@gmail.com>
Copy link
Collaborator
@willingc willingc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggesting improved error message for user understanding and comments for maintainability. Marking approved since code works.

Comment on lines +28 to +29
# Skip the check during testing
# we need to move to src layout to fix this
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the comment about src layout?


import numpy as np

site_packages_path = Path(np.__file__).absolute().parent.parent
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
site_packages_path = Path(np.__file__).absolute().parent.parent
# Use numpy location to determine site packages path
site_packages_path = Path(np.__file__).absolute().parent.parent

# numpy is not installed in site-packages
return

problematic_napari_path = site_packages_path / 'napari'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
problematic_napari_path = site_packages_path / 'napari'
napari_site_packages_path = site_packages_path / 'napari'

Comment on lines +44 to +51
if problematic_napari_path.exists():
print( # noqa: T201
f'Found a napari directory: {problematic_napari_path}, '
'but napari is installed in editable mode. '
'Please remove napari directory from site-packages.',
file=sys.stderr,
)
raise RuntimeError('Mix of local and non local installation')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if problematic_napari_path.exists():
print( # noqa: T201
f'Found a napari directory: {problematic_napari_path}, '
'but napari is installed in editable mode. '
'Please remove napari directory from site-packages.',
file=sys.stderr,
)
raise RuntimeError('Mix of local and non local installation')
if napari_site_packages_path.exists():
print( # noqa: T201
f'Found napari installed in a site-packages directory: {napari_site_packages_path}, '
'but napari is also installed in editable mode. '
'To prevent mixing local, editable and non-local, site-packages installation,
' please remove napari directory from site-packages.',
file=sys.stderr,
)
raise RuntimeError('Conflict found where napari is present in local, editable location and non-local site-packages installation')

@TimMonko
Copy link
Contributor

@Czaki does this work now? if so, how can I know/test it? Happy to also stick this in 0.6.2 if its ready

@Czaki
Copy link
Collaborator Author
Czaki commented Jun 24, 2025

@Czaki does this work now? if so, how can I know/test it? Happy to also stick this in 0.6.2 if its ready

Will recreate problematic environments today and report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0