rstudio / reticulate

R Interface to Python
https://rstudio.github.io/reticulate
Apache License 2.0
1.67k stars 327 forks source link

"OSError: [WinError 6] The handle is invalid" when importing arviz #511

Open poppymiller opened 5 years ago

poppymiller commented 5 years ago

I am trying to install arviz (within a conda environment) and use it within an rmarkdown file. It installs fine, but gives an error when I import it: OSError: [WinError 6] The handle is invalid (see below for details). The package is stored on a shared drive.

Could this be because the arviz filename (returned using py_discover_config) is incorrect? I think it should end with .py not .p (\GFS\myusername$\Profile\appdata\Python\Python36\site-packages\arviz__init__.p)

> conda_install("testpymc3", "arviz")
> py_discover_config(required_module = "arviz")
python:         C:/ProgramData/Anaconda3/envs/testpymc3/python.exe
libpython:      C:/ProgramData/Anaconda3/envs/testpymc3/python36.dll
pythonhome:     C:\PROGRA~3\ANACON~1\envs\TESTPY~1
version:        3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 11:27:44) [MSC v.1900 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:\PROGRA~3\ANACON~1\envs\TESTPY~1\lib\site-packages\numpy
numpy_version:  1.15.4
arviz:          \\GFS\myusername$\Profile\appdata\Python\Python36\site-packages\arviz\__init__.p

NOTE: Python version was forced by RETICULATE_PYTHON
> import("arviz")
Error in py_module_import(module, convert = convert) : 
  OSError: [WinError 6] The handle is invalid

Detailed traceback: 
  File "\\GFS\myusername$\Profile\appdata\Python\Python36\site-packages\arviz\__init__.py", line 25, in <module>
    from .plots import *
  File "\\GFS\myusername$\Profile\appdata\Python\Python36\site-packages\arviz\plots\__init__.py", line 14, in <module>
    from .ppcplot import plot_ppc
  File "\\GFS\myusername$\Profile\appdata\Python\Python36\site-packages\arviz\plots\ppcplot.py", line 6, in <module>
    from matplotlib import animation
  File "C:\PROGRA~3\ANACON~1\envs\TESTPY~1\lib\site-packages\matplotlib\animation.py", line 625, in <module>
    class FFMpegWriter(FFMpegBase, MovieWriter):
  File "C:\PROGRA~3\ANACON~1\envs\TESTPY~1\lib\site-packages\matplotlib\animation.py", line 120, in wrapper
    if writerClass.isAvailable():
  File "C:\PROGRA~3\ANACON~1\envs\TESTPY~1\lib\site-packages\matplotlib\animation.py", line 620, in isAvailable
    stdout=subprocess.DEVNULL, stderr=subprocess.PIPE).stderr)
  File "C:\PR

Possibly related to this bug: https://github.com/KrishnaswamyLab/MAGIC/issues/148

kevinushey commented 5 years ago

Can you please provide a reproducible example? It's not clear to me how you initialized your conda environment.

fdetsch commented 4 years ago

Same here. Note that Das Handle ist ungültig is German for The handle is invalid.

reticulate::import("arviz")
Error in py_module_import(module, convert = convert) : 
  OSError: [WinError 6] Das Handle ist ungültig

Detailed traceback: 
  File "C:\ProgramData\Anaconda3\lib\site-packages\arviz\__init__.py", line 28, in <module>
    from .plots import *
  File "C:\ProgramData\Anaconda3\lib\site-packages\arviz\plots\__init__.py", line 19, in <module>
    from .ppcplot import plot_ppc
  File "C:\ProgramData\Anaconda3\lib\site-packages\arviz\plots\ppcplot.py", line 6, in <module>
    from matplotlib import animation
  File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\animation.py", line 625, in <module>
    class FFMpegWriter(FFMpegBase, MovieWriter):
  File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\animation.py", line 120, in wrapper
    if writerClass.isAvailable():
  File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\animation.py", line 620, in isAvailable
    stdout=subprocess.DEVNULL, stderr=subprocess.PIPE).stderr)
  File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 488, in run
    with Popen(*popenarg

reticulate::py_discover_config("arviz") returns the following:

python:         C:/ProgramData/Anaconda3/python.exe
libpython:      C:/ProgramData/Anaconda3/python37.dll
pythonhome:     C:/ProgramData/Anaconda3
version:        3.7.5 (default, Oct 31 2019, 15:18:51) [MSC v.1916 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:/ProgramData/Anaconda3/Lib/site-packages/numpy
numpy_version:  1.17.3
arviz:          C:\PROGRA~3\Anaconda3\lib\site-packages\arviz\__init__.p

NOTE: Python version was forced by RETICULATE_PYTHON

Ideas to make this reproducible are highly appreciated. Here's my sessionInfo():

R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

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

other attached packages:
 [1] reticulate_1.13.0-9004 data.table_1.12.6      patchwork_0.0.1        lattice_0.20-38       
 [5] ggplot2_3.2.1          gamlss_5.1-5           nlme_3.1-142           gamlss.dist_5.1-5     
 [9] MASS_7.3-51.4          gamlss.data_5.1-4      BAS_1.5.3             

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3        pillar_1.4.2      compiler_3.6.1    tools_3.6.1       jsonlite_1.6     
 [6] tibble_2.1.3      gtable_0.3.0      png_0.1-7         pkgconfig_2.0.3   rlang_0.4.1      
[11] Matrix_1.2-17     rstudioapi_0.10   xfun_0.10         withr_2.1.2       dplyr_0.8.3      
[16] knitr_1.25        rappdirs_0.3.1    grid_3.6.1        prompt_1.0.0      tidyselect_0.2.5 
[21] glue_1.3.1        R6_2.4.0          survival_2.44-1.1 purrr_0.3.3       magrittr_1.5     
[26] scales_1.0.0      clisymbols_1.2.0  assertthat_0.2.1  colorspace_1.4-1  lazyeval_0.2.2   
[31] munsell_0.5.0     crayon_1.3.4