我正在尝试通过 R 和 reticulate 从 conda 环境导入 gensim。 conda 环境本身导入 gensim 很好,只有当我使用 reticulate 进行接口(interface)时才会出现问题。下面的代码准确地显示了我正在运行的内容、输出和环境(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。
关于python - 通过网状结构在 R 中运行 gensim 时出现 ImportError : cannot import name 'ssl' from 'urllib3. util.ssl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56108856/