earmingol / cell2cell

User-friendly tool to infer cell-cell interactions and communication from gene expression of interacting proteins
BSD 3-Clause "New" or "Revised" License
56 stars 12 forks source link

inability to import cell2cell from within liana compatible environment #59

Closed whitneyt1 closed 3 months ago

whitneyt1 commented 3 months ago

Hi!

I am trying to use cell2cell and liana on a linux cluster but when I try to import cell2cell, I repeatedly get this error:

---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
Cell In[1], line 1
----> 1 import cell2cell as c2c

File [~/.conda/envs/liana_env/lib/python3.8/site-packages/cell2cell/__init__.py:3](http://127.0.0.1:8000/lab/tree/Whitney_Analysis/Liana_Visium/~/.conda/envs/liana_env/lib/python3.8/site-packages/cell2cell/__init__.py#line=2)
      1 # -*- coding: utf-8 -*-
----> 3 from cell2cell import analysis
      4 from cell2cell import clustering
      5 from cell2cell import core

File [~/.conda/envs/liana_env/lib/python3.8/site-packages/cell2cell/analysis/__init__.py:1](http://127.0.0.1:8000/lab/tree/Whitney_Analysis/Liana_Visium/~/.conda/envs/liana_env/lib/python3.8/site-packages/cell2cell/analysis/__init__.py#line=0)
----> 1 from cell2cell.analysis.cell2cell_pipelines import (initialize_interaction_space, BulkInteractions, SingleCellInteractions)
      2 from cell2cell.analysis.tensor_pipelines import (run_tensor_cell2cell_pipeline)
      3 import cell2cell.analysis.tensor_downstream as tensor_downstream

File [~/.conda/envs/liana_env/lib/python3.8/site-packages/cell2cell/analysis/cell2cell_pipelines.py:6](http://127.0.0.1:8000/lab/tree/Whitney_Analysis/Liana_Visium/~/.conda/envs/liana_env/lib/python3.8/site-packages/cell2cell/analysis/cell2cell_pipelines.py#line=5)
      3 from __future__ import absolute_import
      5 import pandas as pd
----> 6 import scanpy
      7 import numpy as np
      8 from tqdm import tqdm

File [~/.conda/envs/liana_env/lib/python3.8/site-packages/scanpy/__init__.py:16](http://127.0.0.1:8000/lab/tree/Whitney_Analysis/Liana_Visium/~/.conda/envs/liana_env/lib/python3.8/site-packages/scanpy/__init__.py#line=15)
     11     except ModuleNotFoundError:
     12         raise RuntimeError(
     13             "scanpy is not correctly installed. Please install it, e.g. with pip."
     14         )
---> 16 from ._utils import check_versions
     18 check_versions()
     19 del check_versions

File [~/.conda/envs/liana_env/lib/python3.8/site-packages/scanpy/_utils/__init__.py:28](http://127.0.0.1:8000/lab/tree/Whitney_Analysis/Liana_Visium/~/.conda/envs/liana_env/lib/python3.8/site-packages/scanpy/_utils/__init__.py#line=27)
     25 from .._settings import settings
     26 from .. import logging as logg
---> 28 from .compute.is_constant import is_constant
     31 class Empty(Enum):
     32     token = 0

File [~/.conda/envs/liana_env/lib/python3.8/site-packages/scanpy/_utils/compute/is_constant.py:5](http://127.0.0.1:8000/lab/tree/Whitney_Analysis/Liana_Visium/~/.conda/envs/liana_env/lib/python3.8/site-packages/scanpy/_utils/compute/is_constant.py#line=4)
      2 from numbers import Integral
      4 import numpy as np
----> 5 from numba import njit
      6 from scipy import sparse
      9 @singledispatch
     10 def is_constant(a, axis=None) -> np.ndarray:

File [~/.conda/envs/liana_env/lib/python3.8/site-packages/numba/__init__.py:42](http://127.0.0.1:8000/lab/tree/Whitney_Analysis/Liana_Visium/~/.conda/envs/liana_env/lib/python3.8/site-packages/numba/__init__.py#line=41)
     38 from numba.core.decorators import (cfunc, generated_jit, jit, njit, stencil,
     39                                    jit_module)
     41 # Re-export vectorize decorators and the thread layer querying function
---> 42 from numba.np.ufunc import (vectorize, guvectorize, threading_layer,
     43                             get_num_threads, set_num_threads)
     45 # Re-export Numpy helpers
     46 from numba.np.numpy_support import carray, farray, from_dtype

File [~/.conda/envs/liana_env/lib/python3.8/site-packages/numba/np/ufunc/__init__.py:3](http://127.0.0.1:8000/lab/tree/Whitney_Analysis/Liana_Visium/~/.conda/envs/liana_env/lib/python3.8/site-packages/numba/np/ufunc/__init__.py#line=2)
      1 # -*- coding: utf-8 -*-
----> 3 from numba.np.ufunc.decorators import Vectorize, GUVectorize, vectorize, guvectorize
      4 from numba.np.ufunc._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One
      5 from numba.np.ufunc import _internal, array_exprs

File [~/.conda/envs/liana_env/lib/python3.8/site-packages/numba/np/ufunc/decorators.py:3](http://127.0.0.1:8000/lab/tree/Whitney_Analysis/Liana_Visium/~/.conda/envs/liana_env/lib/python3.8/site-packages/numba/np/ufunc/decorators.py#line=2)
      1 import inspect
----> 3 from numba.np.ufunc import _internal
      4 from numba.np.ufunc.parallel import ParallelUFuncBuilder, ParallelGUFuncBuilder
      6 from numba.core.registry import DelayedRegistry

SystemError: initialization of _internal failed without raising an exception

If I try to update my numba from 0.55.2 to the most updated version (0.58.1) I get the same error.

Please advise.

Thank you! :)

whitneyt1 commented 3 months ago

liana_env_condalist.txt

Additionally, here are my installed packages accessed by conda list

earmingol commented 3 months ago

I would say this is an issue caused by a newer version of numba that makes scanpy incompatible with it. You can either update scanpy, or try downgrading numba. I would recommend updating scanpy.

earmingol commented 3 months ago

If that doesn't work, try what was commented here: https://github.com/openai/whisper/discussions/1103#discussioncomment-5791748

which is basically running this: python pip install llvnlite --ignore-installed, then reinstall/update numba

whitneyt1 commented 3 months ago

hmm. thank you @earmingol! I was able to successfully install scanpy 1.9.8, install llvmlite (0.41.1) and update numba (0.58.1) but now import cell2cell as c2c kills the kernel, and I receive the error,

Kernel Restarting The kernel for Whitney_Analysis/Liana_Visium/Untitled.ipynb appears to have died. It will restart automatically.

I have also tried updating tensorflow based on some other googling, but to no avail.

Thank you for your advice

dbdimitrov commented 3 months ago

Hi @whitneyt1,

Maybe it's easier if you create a new environment. If you're using liana-py just create a new env and install liana-py with all dependecies: https://liana-py.readthedocs.io/en/latest/installation.html

For R, maybe recreating our tested env as in the protocol is best: https://github.com/saezlab/ccc_protocols/blob/main/env_setup/env_python.yml

Then you can pass this environment as a param when calling cell2cell from R.

Hope this helps!

dbdimitrov commented 3 months ago

PS. I recommend using liana-py - let me know if you need any help converting your object. :)

whitneyt1 commented 3 months ago

Thank you @dbdimitrov I have created a new environment with python 3.7 (as recommended by cell2cell installation page https://github.com/earmingol/cell2cell) on a cluster node with gpu. lianaxcell2cell.txt however, this has led to an inability to read in pickle files created from my previous liana environment on my local.

image

This was solved by reloading my liana_res and rerunning the to_tensor_c2c function.

Thank you!

earmingol commented 3 months ago

Oh, that version was for when I created cell2cell. I forgot that I left it there. I recommend using a newer version, maybe 3.10

Also use this instructions to create an env compatible with cell2cell and lianapy: https://github.com/saezlab/ccc_protocols/tree/main/env_setup

If you have problems loading metadata with pickle, this is because of the version of pandas you are using. Make sure to use the same pandas version you used to save the file.

whitneyt1 commented 3 months ago

thanks @earmingol ! Sounds good. If I have any other issues, i'll update everything in a new python env with python 3.10.

huiyijiangling commented 3 months ago

哦,那个版本是我创建 cell2cell 时用的。我忘了把它放在那里了。我建议使用更新的版本,比如 3.10

还可以使用此说明创建与 cell2cell 和 lianapy 兼容的环境:https://github.com/saezlab/ccc_protocols/tree/main/env_setup

如果您在使用 pickle 加载元数据时遇到问题,这是由于您使用的 pandas 版本所致。请确保使用与保存文件时相同的 pandas 版本。

image Still fails. could you help to put forward a installtion tutorials using pip or conda (liana pytorch cell2cell all-in one)?

earmingol commented 3 months ago

@huiyijiangling this seems related with an issue associated to your OS. See reply here too: https://github.com/saezlab/ccc_protocols/issues/17#issuecomment-2269285591

Could you provide more information?