anndata icon indicating copy to clipboard operation
anndata copied to clipboard

from anndata import AnnData fails with flit

Open falexwolf opened this issue 3 years ago • 8 comments

In one instance of treating anndata as a dependency within flit, I now get:

from anndata import AnnData
-> ImportError: cannot import name 'AnnData' from 'anndata'

When I replace the import as follows

from anndata._core.anndata import AnnData

it all works fine again.

I vaguely remember we had these name resolution errors many years ago. I post this mostly for reference if someone else needs this workaround.

No action is necessary.

falexwolf avatar Mar 15 '22 22:03 falexwolf

In one instance of treating anndata as a dependency within flit

I'm not sure what you mean here. Could you clarify?

ivirshup avatar Mar 16 '22 13:03 ivirshup

Oh, I have a package that I install with flit, and anndata is a dependency. It all worked fine until yesterday, until this error started to appearing, either due to updates in pip, flit, or anndata. I can't really imagine that anndata is the only package that has their re-export not equal the original definition of the class, but I wouldn't know which other aspect of anndata triggers the error. A 100 other dependencies are installed fine.

If I understand more, I'll update here.

falexwolf avatar Mar 16 '22 14:03 falexwolf

Ah, yeah I vaguely recall something like this. I think @grst ran into it.

I think this could ultimately be solved with a more robust versioning system, but also that's a big wormhole.

Is there a reason you install with flit directly and not pip? pip install -e should be mostly working now.

ivirshup avatar Mar 16 '22 14:03 ivirshup

might be, but I don't remember at all, sorry!

On Wed, 16 Mar 2022 at 15:48, Isaac Virshup @.***> wrote:

Ah, yeah I vaguely recall something like this. I think @grst https://github.com/grst ran into it.

I think this could ultimately be solved with a more robust versioning system, but also that's a big wormhole.

Is there a reason you install with flit directly and not pip? pip install -e should be mostly working now.

— Reply to this email directly, view it on GitHub https://github.com/theislab/anndata/issues/733#issuecomment-1069209472, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABVZRV35F7XIWLGIKK3LZ7LVAHYCHANCNFSM5Q2EKEFQ . You are receiving this because you were mentioned.Message ID: @.***>

grst avatar Mar 16 '22 14:03 grst

I think pip install -e doesn't recognize extras like doc, test when they're in pyproject.toml. Or am I getting something wrong?

pip install -e .[doc]

This also fails here on anndata despite being defined in https://github.com/theislab/anndata/blob/master/pyproject.toml.

falexwolf avatar Mar 16 '22 16:03 falexwolf

That works for me. What's particularly weird for me is that it doesn't fail when the "extras" doesn't exist.

Maybe a newer pip is needed?

ivirshup avatar Mar 18 '22 17:03 ivirshup

pip install -e .[doc]

this should work. If you use zsh (default on macOS), [ is shell syntax though. What if you try:

pip install -e '.[doc]'

flying-sheep avatar Mar 20 '22 13:03 flying-sheep

Thank you, Phil! I think it was indeed just a lack of escaping [.

pip now works for me.

falexwolf avatar Mar 28 '22 11:03 falexwolf

This issue has been automatically marked as stale because it has not had recent activity. Please add a comment if you want to keep the issue open. Thank you for your contributions!

github-actions[bot] avatar Aug 14 '23 02:08 github-actions[bot]