Can't import Python module using reticulate

Dear all,
I had a fully working R and Python environment under Windows 10 and recently upgraded to a new computer with Windows 11 . I run into issues with the Python piece since.

I have installed a Python package named "ib_insync" through pip, I can see it with py_list_packages() but can't import it, it raises error.

If I list installed packages:

py_list_packages():
package version requirement channel
....
6 ib-insync 0.9.86 ib-insync=0.9.86 pypi

However:

py_module_available("ib_insync"):
FALSE

I have installed latest version of RStudio : 2023.09.0 Build 463 on Windows 11. I installed miniconda through reticulate, and
py_config() returns:

python: C:/Users/aldoh/AppData/Local/r-miniconda/envs/r-reticulate/python.exe
libpython: C:/Users/aldoh/AppData/Local/r-miniconda/envs/r-reticulate/python39.dll
pythonhome: C:/Users/aldoh/AppData/Local/r-miniconda/envs/r-reticulate
version: 3.9.18 (main, Sep 11 2023, 14:09:26) [MSC v.1916 64 bit (AMD64)]
Architecture: 64bit
numpy: C:/Users/aldoh/AppData/Local/r-miniconda/envs/r-reticulate/Lib/site-packages/numpy
numpy_version: 1.26.0
NOTE: Python version was forced by use_python() function

SessionInfo() returns:

sessionInfo()
R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)

Matrix products: default

locale:
[1] LC_COLLATE=French_Switzerland.utf8 LC_CTYPE=French_Switzerland.utf8
[3] LC_MONETARY=French_Switzerland.utf8 LC_NUMERIC=C
[5] LC_TIME=French_Switzerland.utf8

time zone: Europe/Zurich
tzcode source: internal

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

other attached packages:
[1] reticulate_1.32.0

loaded via a namespace (and not attached):
[1] utf8_1.2.3 Matrix_1.5-4.1 lattice_0.21-8 rappdirs_0.3.3
[5] glue_1.6.2 png_0.1-8 lifecycle_1.0.3 cli_3.6.1
[9] fansi_1.0.4 vctrs_0.6.3 grid_4.3.1 withr_2.5.1
[13] compiler_4.3.1 rstudioapi_0.15.0 tools_4.3.1 pillar_1.9.0
[17] Rcpp_1.0.11 rlang_1.1.1 jsonlite_1.8.7

If I try to import this module in a repl_python() session I get an error :
"NameError: name 'base_events' is not defined"
Any help would be greatly appreciated

Best regards,
Alexis

I did some progress - but still it is not working:

  • I re-created a new r-reticulate conda environment with python version=3.11, adding conda-forge as channel
  • Using pip, I installed ib_insync module in this environment
    => Now using IDLE I am able to import ib_insync in Python interactive session, and to launch Python scripts that call ib_insync module functions.
    But still does not work with reticulate

So my latest py_config is now:

python: C:/Users/aldoh/miniconda3/envs/r-reticulate/python.exe
libpython: C:/Users/aldoh/miniconda3/envs/r-reticulate/python311.dll
pythonhome: C:/Users/aldoh/miniconda3/envs/r-reticulate
version: 3.11.6 | packaged by conda-forge | (main, Oct 3 2023, 10:29:11) [MSC v.1935 64 bit (AMD64)]
Architecture: 64bit
numpy: C:/Users/aldoh/miniconda3/envs/r-reticulate/Lib/site-packages/numpy
numpy_version: 1.26.0

The error I get when trying to import ib_insync is still:
NameError: name 'base_events' is not defined

Thanks for your help
Alexis

If I fix the issue found in config.py -see this topic, then error is still there but becomes:
TypeError: the first argument must be callable

Still not working - but different behaviour...

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.