Using Python and R within the same environment

Post author
Michelle Hulke

I work with scRNA data and frequently work in both python and R, depending on the packages I want to use. Unfortunately, igraph is the bane of my existence, even though it was supposedly updated to avoid the conflict between python and R. If I start an environment in python with Scanpy and later move to R with MAST and other related packages, I won't able to move back into python and use Scanpy. I have to delete my environment and redownload Scanpy to get the package working. Does anyone know, can I use a conda environment or something similar to keep my R and python packages separate and avoid the igraph conflict? Or is there another way to get around this issue?

Comments

6 comments

  • Comment author
    Jason Cerrato

    Hi Michelle,

    Thanks for writing in. We'll take a look at your inquiry and get back to you as soon as we can!

    Kind regards,

    Jason

    0
  • Comment author
    Jason Cerrato

    Hey Michelle,

    Can you provide us with some details to help us in troubleshooting your issue?

    • Screenshot of your cloud environment configuration (open with gear icon at the top-right of workspace)

    • What version of scanpy and igraph are you using?

    • What version of igraph is meant to have this issue resolved?

    Many thanks,

    Jason

    0
  • Comment author
    Michelle Hulke

    Here is my cloud configuration:

     

    I am currently using Scanpy 1.8.1. I am not manually installing igraph for python or R. The default packages that are installed with other software are python-igraph = 0.9.6 and igraph (used in R) = 1.2.6. 

     

    If I have R packages installed and try to return to a python notebook, I receive the following error:

    import scanpy as sc

    AttributeError                            Traceback (most recent call last)
    /tmp/ipykernel_247/912249142.py in <module>
    ----> 1 import scanpy as sc
    
    ~/notebooks/packages/scanpy/__init__.py in <module>
         12     # (start with settings as several tools are using it)
         13     from ._settings import settings, Verbosity
    ---> 14     from . import tools as tl
         15     from . import preprocessing as pp
         16     from . import plotting as pl
    
    ~/notebooks/packages/scanpy/tools/__init__.py in <module>
         13 from ._rank_genes_groups import rank_genes_groups, filter_rank_genes_groups
         14 from ._dpt import dpt
    ---> 15 from ._leiden import leiden
         16 from ._louvain import louvain
         17 from ._sim import sim
    
    ~/notebooks/packages/scanpy/tools/_leiden.py in <module>
         13 
         14 try:
    ---> 15     from leidenalg.VertexPartition import MutableVertexPartition
         16 except ImportError:
         17 
    
    ~/notebooks/packages/leidenalg/__init__.py in <module>
         33 not immediately available in :func:`leidenalg.find_partition`.
         34 """
    ---> 35 from .functions import ALL_COMMS
         36 from .functions import ALL_NEIGH_COMMS
         37 from .functions import RAND_COMM
    
    ~/notebooks/packages/leidenalg/functions.py in <module>
         16   return graph.__graph_as_capsule()
         17 
    ---> 18 from .VertexPartition import *
         19 from .Optimiser import *
         20 
    
    ~/notebooks/packages/leidenalg/VertexPartition.py in <module>
          3 from .functions import _get_py_capsule
          4 
    ----> 5 class MutableVertexPartition(_ig.VertexClustering):
          6   """ Contains a partition of graph, derives from :class:`ig.VertexClustering`.
          7 
    
    AttributeError: module 'igraph' has no attribute 'VertexClustering'

    This has been an issue for awhile now, and I haven't been able to find a solution online to get R and Python packages to play well with each other. So instead I'm just trying to separate them to avoid the conflict.

    0
  • Comment author
    Jason Cerrato

    Hi Michelle,

    Thanks for that information. While our support forum is limited in our ability to support package incompatibility issues, I'm happy to give this a shot to see if I can help find a solution here. Do you have a notebook that you can share that shows the sequence of commands you run to get to this result? If so, can you share the workspace for that notebook with GROUP_FireCloud-Support@firecloud.org and provide a link to the notebook directly so I can take a closer look and try to reproduce the issue?

    Kind regards,

    Jason

    0
  • Comment author
    Michelle Hulke

    Hi Jason,

    So it seems the issue has resolved itself, possibly due to the release of python-igraph 0.9.7. I've been trying to replicate the conflict, and haven't been able to since Thursday. Thanks for taking time to look into this though.

    All best,

    Michelle

    0
  • Comment author
    Jason Cerrato

    Hey Michelle,

    Thank you for reaching out with that update! I'm glad to hear it seems to be working.

    If we can help with anything else, please let us know.

    Kind regards,

    Jason

    0

Please sign in to leave a comment.