ventolab / CellphoneDB

CellPhoneDB can be used to search for a particular ligand/receptor, or interrogate your own HUMAN single-cell transcriptomics data.
https://www.cellphonedb.org/
MIT License
320 stars 51 forks source link

raise RuntimeError in spawn.py #167

Open mmuuyyii opened 8 months ago

mmuuyyii commented 8 months ago

Hi, I'm trying to run example data in db5.0 with PyCharm and python 3.11.7 as the notebook guides:

import cellphonedb import pandas as pd import sys import os

cpdb_file_path = 'cellphonedb.zip' meta_file_path = 'test_meta.txt' counts_file_path = 'test_counts.txt' # I also try h5ad from cellphonedb.src.core.methods import cpdb_statistical_analysis_method deconvoluted, means, pvalues, significant_means = cpdb_statistical_analysis_method.call( cpdb_file_path = cpdb_file_path, meta_file_path = meta_file_path, counts_file_path = counts_file_path, counts_data = 'ensembl', output_path = "cpdb")

When I run the code, the program goes to endless loop. When I debug the code, I get the error in "spawn.py":

def _check_not_importing_main(): if getattr(process.current_process(), '_inheriting', False): raise RuntimeError(''' An attempt has been made to start a new process before the current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

    To fix this issue, refer to the "Safe importing of main module"
    section in https://docs.python.org/3/library/multiprocessing.html
    ''')

Could you please teach me what should I do? Thanks a million.

datasome commented 8 months ago

Hi mmuuyyii,

I suggest you run the statistical method in jupyter instead (following instructions in https://github.com/ventolab/CellphoneDB/blob/master/notebooks/T1_Method2.ipynb). However, if you prefer to play around with the code in PyCharm first I think you need to set threads=1 in cpdb_statistical_analysis_method.call(). That parameter defaults to 4 if not specified and this is I think what is causing your error. Please see https://stackoverflow.com/questions/74644040/pycharm-multiprocessing-error-what-can-i-do and https://youtrack.jetbrains.com/issue/PY-50116 for more information.

Hope that helps.

Best,

Robert.