spacyr
spacyr copied to clipboard
Spacy initialize error
I have followed the thread for this by another user, and have found that the options are not working for me as a mac user. I have tried leaving all arguments blank in the "space_initialize()" command, and R crashes and restarts the moment I have hit the enter key on space_parse(). Spacyr is recognizing the condo environment, but the crash still happens.
library(spacyr) spacy_initialize() Found 'spacy_condaenv'. spacyr will use this environment successfully initialized (spaCy Version: 2.0.16, language model: en) (python options: type = "condaenv", value = "spacy_condaenv") txt <- "This is love." space_parse(txt) "R session aborted. R encountered a fatal error. The session was terminated."
Hi - We need your sessionInfo()
output before we can help.
I have included my session info below:

Strange, I use the same OS and R version and it works fine for me. Suggest you try
spacy_uninstall()
spacy_install()
and then give it another go.
I reattempted and the session aborted, but I did receive some information in red. Please see the screenshot below. Can you make any sense of the comments in red? I appreciate your help, Ken!

Suggest you look at:
- https://github.com/dmlc/xgboost/issues/1715
Seems to be a similar issue - and clearly something to do with OpenMP. spacyr is built on the same platform as reticulate so it's likely to be an issue raised in the use of that package.
Should be all solved in current master
.
We refreshed spacyr on CRAN last week, so if you uninstall it, and reinstall it, it should work fine now. Have you tried that?
I have the same problem. Whenever spacy_parse is launched, R session aborted.
It's a moving target since both R and spaCy (the Python library) are constantly undergoing updates. Please try:
update.packages("spacyr")
library("spacyr")
spacy_uninstall()
spacy_install()
We need to know a bit more about the issue to identify the cause.
Could you provide the following?
-
sessionInfo()
-
spacy_initialize()
- Error message displayed on the screen (if any)
Or as @kbenoit suggested, try:
spacy_uninstall()
spacy_install()
spacy_initialize(refresh_settings = TRUE)
Hi! I am having the same issue here... I have tried with
spacy_uninstall()
spacy_install()
spacy_initialize(refresh_settings = TRUE)
but it doesn't fix it...
sessionInfo():
R version 3.6.3 (2020-02-29) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Catalina 10.15.4
Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages: [1] spacyr_1.2.1 quanteda_2.0.1
loaded via a namespace (and not attached): [1] Rcpp_1.0.4.6 rstudioapi_0.11 magrittr_1.5 usethis_1.6.1
[5] stopwords_2.0 tidyselect_1.0.0 munsell_0.5.0 colorspace_1.4-1
[9] lattice_0.20-41 R6_2.4.1 rlang_0.4.6 fastmatch_1.1-0
[13] dplyr_0.8.5 tools_3.6.3 grid_3.6.3 packrat_0.5.0
[17] data.table_1.12.8 gtable_0.3.0 ellipsis_0.3.0 RcppParallel_5.0.0 [21] assertthat_0.2.1 tibble_3.0.1 lifecycle_0.2.0 crayon_1.3.4
[25] Matrix_1.2-18 purrr_0.3.4 ggplot2_3.3.0 fs_1.4.1
[29] vctrs_0.2.4 glue_1.4.0 stringi_1.4.6 compiler_3.6.3
[33] pillar_1.4.3 scales_1.1.0 jsonlite_1.6.1 reticulate_1.15
[37] pkgconfig_2.0.3
spacy_initialize(refresh_settings = TRUE):
Found 'spacy_condaenv'. spacyr will use this environment successfully initialized (spaCy Version: 2.0.16, language model: en_core_web_sm) (python options: type = "condaenv", value = "spacy_condaenv")
Thanks for your help!!
Adding to my previous post, not sure if this might help, but I just tried the same thing with a different machine and it works fine in here...:
R version 3.5.2 (2018-12-20) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Debian GNU/Linux 9 (stretch)
Thanks - it appears to be a macOS issue. @amatsuo I'm having the same thing on my desktop, after updating to R 4.0 and then reinstalling a new version of Python. I think we need a new step-by-step install guide for macOS 10.15.x and R 4.0.
Thanks for suggesting this. I finally abandoned working on my mac for spacyr work. The package installs perfectly for windows OS.
Thanks again,
Mario
Are you able to launch spacy in python environment?
You can try the following in terminal
First start conda environment:
conda activate spacy_condaenv
Then type python
in the terminal to start python
In the python console, run the following lines:
import spacy
nlp = spacy.load('en_core_web_sm')
nlp('hello world')
@kbenoit do you think it's an issue of Catalina or R4.0 or combination of both? At the moment, I don't have either :)
I can run some tests on another machine but it's almost certainly a Python issue. macOS still stubbornly puts 2.7 in a system folder, and there are (of course) multiple ways to install 3.x Pythons. I think this is the issue. Thinking about how difficult it is to integrate R and Java on macOS, I'm worried - let's hope that's not the direction. But I'm thinking any problems we face, reticulate/keras etc will also face.
If it's a python issue, you can generate error using the code in my comment above (activate the conda environment then run python/spacy).
Hello - I am also having issues with this at the moment! It crashes shortly after I hit enter on spacy_initialize.
Grateful for any advice!!
Can you provide more information about your system, e.g. output from sessionInfo()
?
Consider reinstalling spaCy using spacy_install()
.
Session info is below - I've also installed and uninstalled spacy twice with no luck once I get to initialize. It all seemed to start when I tried to tokenize/tag my corpus.
R version 3.6.3 (2020-02-29) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: OS X El Capitan 10.11.6
Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale: [1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
attached base packages: [1] stats graphics grDevices utils datasets [6] methods base
loaded via a namespace (and not attached): [1] compiler_3.6.3 tools_3.6.3 yaml_2.2.1
I was trying to boot up spacyr
just yesterday on a mac, and was having similar crashing issues. Trying to set it up outside of Rstudio, I was given this error in the R console: OMP: Error #15: Initializing libomp.dylib, but found libomp.dylib already initialized.
That led me to this Stack Overflow article, which suggested that I install the conda package nomkl
, which disables Intel MKL optimizations, as OpenMP optimizations are already enabled on mac. That worked for me, and I got spacyr
to initialize successfully. But I had to set it up in conda
first, then point to it with spacyr::spacy_initialize(condaenv = '<spacy env location>')
. I couldn't get it to work just using spacyr
functions nor with reticulate
, but I didn't try very hard with reticulate
.
This is my full setup:
conda create -n spacy_env
conda install -n spacy_env nomkl
conda install -n spacy_env spacy
conda run -n spacy_env python -m spacy download en_core_web_sm
spacyr::spacy_initialize(condaenv = "<location of spacy conda environment>")
Not sure if this is your problem, but I think it's worth checking out.
PS: This is the full text of the error from the R console after running spacyr::spacy_initialize()
with default args:
OMP: Error #15: Initializing libomp.dylib, but found libomp.dylib already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program.
That is dangerous, since it can degrade performance or cause incorrect results.
The best thing to do is to ensure that only a single OpenMP runtime is linked into the process,
e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported,
undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE
to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results.
For more information, please see http://openmp.llvm.org/
zsh: abort R
Hi there, I am having trouble with this as well. The work around provided by @jabortell did not work for me. Thanks!
sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.6.1 tools_3.6.1
I did test spacy in terminal without any issue.
(spacy_condaenv) XOG-91W56H2FB:~ mynamehere$ python
Python 3.6.13 | packaged by conda-forge | (default, Feb 19 2021, 05:36:16)
[GCC Clang 11.0.1] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import spacy
nlp = spacy.load('en_core_web_sm')
doc = nlp('help, helped, helping')
print([(w.text, w.pos_) for w in doc])
[('help', 'NOUN'), (',', 'PUNCT'), ('helped', 'VERB'), (',', 'PUNCT'), ('helping', 'VERB')]
On running the code
spacyr::spacy_initialize(condaenv = "/Users/mynamehere/opt/miniconda3/envs/spacy_condaenv/bin/python3.6")
I am met with the following error:
spacy python option is already set, spacyr will use:
condaenv = "/Users/mynamehere//opt/miniconda3/envs/spacy_condaenv/bin/python"
Error in reticulate::use_condaenv(settings$val, required = TRUE) :
Unable to locate conda environment '/Users/mynamehere//opt/miniconda3/envs/spacy_condaenv/bin/python3.6'.
Looking at finder python3.6 does exist in the bin folder as a document; python also exists as an alias.
Hi, was this issue ever resolved? I am encountering the same problem trying to use Spacy with R Studio on a Mac. It crashes (R has a fatal error) each time I run spacy_inititalize()
- Thanks for any help.
We're going to close this issue since reinstalling should help and since we are updating the installation functions to support newer (newest?) Python installations.