bioFAM / MOFA

Multi-Omics Factor Analysis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: module 'mofapy' has no attribute 'core.entry_point'

dfermin opened this issue · comments

Hi

This is a weird problem.
I've installed MOFA and I'm trying to work through the CLL example but can't execute the runMOFA(MOFAObject) command.

I keep getting this error:

x <- runMOFA(MOFAObject)                                                                                                                                                                          
[1] "No output file provided, using a temporary file..."  
Error in py_get_attr_impl(x, name, silent) : 
  AttributeError: module 'mofapy' has no attribute 'core.entry_point'

I'm using an Anaconda environment running Python 3.6.
It seems that reticulate has detected the correct instance and sees the mofapy package:

> py_config()
python:         /home/dfermin/anaconda3/envs/py36/bin/python
libpython:      /home/dfermin/anaconda3/envs/py36/lib/libpython3.6m.so
pythonhome:     /home/dfermin/anaconda3/envs/py36:/home/dfermin/anaconda3/envs/py36
version:        3.6.7 | packaged by conda-forge | (default, Jul  2 2019, 02:18:42)  [GCC 7.3.0]
numpy:          /home/dfermin/anaconda3/envs/py36/lib/python3.6/site-packages/numpy
numpy_version:  1.17.0
mofapy:         /home/dfermin/anaconda3/envs/py36/lib/python3.6/site-packages/mofapy

When I go to the site-packages directory I see mofapy and the entry_point.py script is there:

ls /home/dfermin/anaconda3/envs/py36/lib/python3.6/site-packages/mofapy/core/
BayesNet.py
build_model.py
distributions.py
entry_point.py
init_nodes.py
__init__.py
mixed_nodes.py
multiview_nodes.py
nodes.py
nongaussian_nodes.py
__pycache__
simulate.py
updates.py
utils.py
variational_nodes.py

I can import the library in python without any issues.
I'm not using Rstudio, this is all on the terminal on an instance of RHEL.
I've tried multiple versions of R and I'm currently using a freshly compiled version of 3.6.1.
Does anyone have a suggestion for a work around?

The R sessionInfo outptu is given below in case it helps.

 > sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Workstation 7.7 (Maipo)

Matrix products: default
BLAS/LAPACK: /home/dfermin/apps/openBLAS.libs/lib/libopenblas_haswellp-r0.3.6.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] reticulate_1.13 MOFAdata_1.1.0  MOFA_1.1.1

loaded via a namespace (and not attached):
 [1] SummarizedExperiment_1.14.1 beeswarm_0.2.3
 [3] tidyselect_0.2.5            purrr_0.3.3
 [5] reshape2_1.4.3              corrplot_0.84
 [7] rhdf5_2.28.1                lattice_0.20-38
 [9] colorspace_1.4-1            stats4_3.6.1
[11] rlang_0.4.1                 pillar_1.4.2
[13] glue_1.3.1                  BiocParallel_1.18.1
[15] BiocGenerics_0.30.0         RColorBrewer_1.1-2
[17] matrixStats_0.55.0          GenomeInfoDbData_1.2.1
[19] foreach_1.4.7               plyr_1.8.4
[21] stringr_1.4.0               zlibbioc_1.30.0
[23] munsell_0.5.0               gtable_0.3.0
[25] codetools_0.2-16            Biobase_2.44.0
[27] IRanges_2.18.3              doParallel_1.0.15
[29] MultiAssayExperiment_1.10.4 GenomeInfoDb_1.20.0
[31] vipor_0.4.5                 parallel_3.6.1
[33] Rcpp_1.0.2                  scales_1.0.0
[35] DelayedArray_0.10.0         S4Vectors_0.22.1
[37] jsonlite_1.6                XVector_0.24.0
[39] ggplot2_3.2.1               stringi_1.4.3
[41] dplyr_0.8.3                 ggrepel_0.8.1
[43] cowplot_1.0.0               GenomicRanges_1.36.1
[45] grid_3.6.1                  tools_3.6.1
[47] bitops_1.0-6                magrittr_1.5
[49] RCurl_1.95-4.12             lazyeval_0.2.2
[51] tibble_2.1.3                crayon_1.3.4
[53] pkgconfig_2.0.3             pheatmap_1.0.12
[55] Matrix_1.2-17               ggbeeswarm_0.6.0
[57] assertthat_0.2.1            iterators_1.0.12
[59] Rhdf5lib_1.6.3              R6_2.4.0
[61] compiler_3.6.1

I've been trying to debug this and found this inconsistency. I don't know if it will help
When I try to access the data in the mofa.core module from within R I cannot see any of the functions:

> library(reticulate)
> use_condaenv(condaenv="py36", required=TRUE)

> mofa <- import("mofapy")
> py_list_attributes(mofa$core)
[1] "__builtins__" "__cached__"   "__doc__"      "__file__"     
[5] "__loader__"   "__name__"     "__package__"  "__path__"     "__spec__"

> dir("/home/dfermin/anaconda3/envs/py36/lib/python3.6/site-packages/mofapy/core")
[1] "__init__.py"          "__pycache__"          "BayesNet.py"          "build_model.py"       
[5] "distributions.py"     "entry_point.py"       "init_nodes.py"        "mixed_nodes.py"
[8] "multiview_nodes.py"   "nodes.py"   "nongaussian_nodes.py"   "simulate.py" 
[12] "updates.py"           "utils.py"             "variational_nodes.py"

If I load a different python module the functions are visible and correspond to the python scripts for the module:

> vcf <- import("vcf") ## importing the PyVCF module
> py_list_attributes(vcf)
[1] "Filter"          "RESERVED_FORMAT" "RESERVED_INFO"   "Reader"
[5] "SampleFilter"    "VCFReader"       "VCFWriter"       "VERSION"
[9] "Writer"          "__builtins__"    "__cached__"      "__doc__"
[13] "__file__"        "__loader__"      "__name__"        "__package__"
[17] "__path__"        "__spec__"        "filters"         "model"
[21] "parser"          "sample_filter"

>dir("home/dfermin/anaconda3/envs/py36/lib/python3.6/site-packages/vcf/")
[1] "__init__.py"      "__pycache__"      "cparse.pyx"       "filters.py" 
[5] "model.py"         "parser.py"        "sample_filter.py" "test"
[9] "utils.py"

If I switch over to python I have the same error that I observe in R:

$ conda activate py36
$ python
>>> from mofapy import core
>>> core
<module 'mofapy.core' from '/home/dfermin/anaconda3/envs/py36/lib/python3.6/site-packages/mofapy/core/__init__.py'>
>>> core.entry_point
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'mofapy.core' has no attribute 'entry_point'

This doesn't happen with the vcf module I tested earlier.
I don't know if this is because the vcf module doesn't contain a core subdirectory or not but I thought someone with a better understanding of python might be able to suggest a fix.

commented

if somebody is still interested:
I had the same problem when installing mofapy directly in my conda-environment. After a long trial and error an installation from R helped to solve the problem, but I still do not know why:

run in R:

library(reticulate)
py_install("mofapy", envname = "mofa_env", method="conda",
  conda = "/opt/anaconda/3-5.0.1/bin/conda", pip=TRUE)

additionally restart the R session afterwards

I had the same issue running MOFA2 on RStudio Server. The error message said also: "AttributeError: module 'mofapy' has no attribute 'core.entry_point'" I noticed that r-reticulate generated a conda env by itself.

So, I did not changed the conda_env for my MOFA run and installed mofapy2 by first accessing the r-reticulate env:
conda activate /home/XXX/.local/share/r-miniconda/envs/r-reticulate

And install mofapy2:
pip install mofapy2

That solved the problem for me. Hope it is helpful.

Been running into this as well today, and I found the following helpful to debug (using MOFA2 and use_basilisk=FALSE):

  • Check reticulate::py_config() which python installation is used
  • Open this python in your terminal and try to import the module from mofapy2.run import entry_point

The error message you get will be more helpful than what run_mofa displays