ImportError: cannot import name 'ssl' from 'urllib3.util.ssl when running gensim in R via reticulate

ImportError: cannot import name 'ssl' from 'urllib3.util.ssl when running gensim in R via reticulate

我正在尝试通过带网状结构的 R 从 conda 环境中导入 gensim。 conda 环境本身可以很好地导入 gensim,只有当我使用 reticulate 进行接口时才会出现问题。下面的代码准确地显示了我正在 运行ning、输出和环境(它是 Mint 19.1,即 Ubuntu 18.04)

虽然我也运行:

搜索过与此相关的任何内容,但我徒劳无功

sudo apt install python-dev libffi-dev libssl-dev

因为我读过这可能有帮助。我也运行:

conda install urllib3 并被告知它已经安装。

更让我沮丧的是,它 运行 在我的 Mint 18.3 盒子上没问题,但我终究无法理解其中的区别。

library(reticulate)

use_condaenv("hello", required = TRUE)

py_run_string("import gensim")

这会产生以下错误:

Error in py_run_string_impl(code, local, convert) : 
  ImportError: cannot import name 'ssl' from 'urllib3.util.ssl_' (/home/chris/anaconda3/envs/hello/lib/python3.7/site-packages/urllib3/util/ssl_.py)

sessionInfo() 的输出:

R version 3.6.0 (2019-04-26)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 19.1

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /home/chris/anaconda3/envs/hello/lib/libmkl_rt.so

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

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

other attached packages:
[1] reticulate_1.12

loaded via a namespace (and not attached):
[1] compiler_3.6.0  Matrix_1.2-17   tools_3.6.0     Rcpp_1.0.1      grid_3.6.0      jsonlite_1.6    lattice_0.20-38

py_discover_config()

python:         /home/chris/anaconda3/envs/hello/bin/python

libpython:      /home/chris/anaconda3/envs/hello/lib/libpython3.7m.so

pythonhome:     /home/chris/anaconda3/envs/hello:/home/chris/anaconda3/envs/hello

version:        3.7.3 (default, Mar 27 2019, 22:11:17)  [GCC 7.3.0]

numpy:          /home/chris/anaconda3/envs/hello/lib/python3.7/site-packages/numpy

numpy_version:  1.16.3

NOTE: Python version was forced by use_python function

当 运行 来自 RStudio 的代码时,我遇到了同样的错误。事实证明,在conda环境中安装RStudio时,它起作用了。但是当使用作为 deb 包安装的 RStudio (/usr/bin/rstudio) 时,它失败了。因此,您可能希望在用于 gensim 的相同 conda 环境中安装 R。