bnosac / pattern.nlp

R package to perform sentiment analysis and Parts of Speech tagging for Dutch/French/English/German/Spanish/Italian
Other
67 stars 17 forks source link

Installation error #8

Closed Zaletio closed 5 years ago

Zaletio commented 5 years ago

Even after reading the other installation issues in regarding this package, I cannot get it to work; unfortunately. After installing the pattern package, I used the following commands:

remove.packages('pattern.nlp')
library(findpython)
can_find_python_cmd(required_modules = "pattern.db")
devtools::install_github("bnosac/pattern.nlp", args = "--no-multiarch")
library(pattern.nlp)

This led to the following chuck of response:

> library(findpython)
> can_find_python_cmd(required_modules = "pattern.db")
[1] TRUE
attr(,"python_cmd")
[1] "C:\\Python27\\python.exe"
> devtools::install_github("bnosac/pattern.nlp", args = "--no-multiarch")
Downloading GitHub repo bnosac/pattern.nlp@master
√  checking for file 'C:\Users\Max\AppData\Local\Temp\Rtmps1aWZc\remotes1e58403b698\bnosac-pattern.nlp-91a459f/DESCRIPTION' ... 
-  preparing 'pattern.nlp':
√  checking DESCRIPTION meta-information ... 
-  checking for LF line-endings in source and make files and shell scripts
-  checking for empty or unneeded directories
-  looking to see if a 'data/datalist' file should be added
-  building 'pattern.nlp_1.0.tar.gz'

Installing package into ‘C:/Users/.../Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
* installing *source* package 'pattern.nlp' ...
** R
** data
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
  converting help for package 'pattern.nlp'
    finding HTML links ... done
    pattern.nlp-package                     html  
    pattern_pos                             html  
    pattern_sentiment                       html  
    penn_treebank_postags                   html  
** building package indices
** testing if installed package can be loaded
*** arch - i386
Traceback (most recent call last):

  File "<string>", line 1, in <module>

  File "C:\Python27\lib\site-packages\pattern\text\en\__init__.py", line 61, in <module>

from pattern.text.en.inflect import (

  File "C:\Python27\lib\site-packages\pattern\text\en\__init__.py", line 80, in <module>

from pattern.text.en import wordnet

  File "C:\Python27\lib\site-packages\pattern\text\en\wordnet\__init__.py", line 48, in <module>

import nltk

ImportError
: 
No module named nltk
Error: package or namespace load failed for 'pattern.nlp':
 .onAttach failed in attachNamespace() for 'pattern.nlp', details:
  call: PythonInR::pyExec("from pattern.en import sentiment as sentiment_en")
  error: An error has occured while executing Python code. See traceback above.
Error: loading failed
Execution halted
*** arch - x64
Error: package or namespace load failed for 'pattern.nlp':
 .onAttach failed in attachNamespace() for 'pattern.nlp', details:
  call: autodetectPython(pythonExePath)
  error: Python 32bit can't be connected with R 64bit!
Error: loading failed
Execution halted
ERROR: loading failed for 'i386', 'x64'
* removing 'C:/Users/Max/Documents/R/win-library/3.5/pattern.nlp'
In R CMD INSTALL
Error in i.p(...) : 
  (converted from warning) installation of package ‘C:/Users/Max/AppData/Local/Temp/Rtmps1aWZc/file1e584b3d676c/pattern.nlp_1.0.tar.gz’ had non-zero exit status
In addition: Warning messages:
1: In untar2(tarfile, files, list, exdir) :
  skipping pax global extended headers
2: In untar2(tarfile, files, list, exdir) :
  skipping pax global extended headers
> library(pattern.nlp)
Error in library(pattern.nlp) : there is no package called ‘pattern.nlp’

As the pattern.db returns "TRUE", I guess that the issue seem to be somewhere related to the Pattern.nlp package. Would it be possible to support me, so I can use this package? It even shows the error explaining how Python 32bit can't be connected with R 64bit, but I am using R 32 bit.

Support would be very welcome!

jwijffels commented 5 years ago

Start R in 32 bit as you seem to have python 32 bit. If you can't get it to work an this is for a commercial project, you can contact us at www.bnosac.be

Zaletio commented 5 years ago

Thanks for the reply! I want to execute a Dutch sentiment analysis as part of my master's thesis, hence it is not a commercial project.

Unfortunately, I already ran the R 32 bit version. Hence, my surprise when this error showed.

Do you have another suggestion, where it could've gone wrong?

I uninstalled Python 32 bits and installed the 64 bits variant. Then, I used the cd c:\Python27\scripts and pip install pattern again. After starting R (64 bits) and running the commands following commands:

 remove.packages('pattern.nlp')
library(findpython)
can_find_python_cmd(required_modules = "pattern.db")
devtools::install_github("bnosac/pattern.nlp", args = "--no-multiarch")
library(pattern.nlp) 

This led to the following output (the same as above):

> library(findpython)
> can_find_python_cmd(required_modules = "pattern.db")
[1] TRUE
attr(,"python_cmd")
[1] "C:\\Python27\\python.exe"
> devtools::install_github("bnosac/pattern.nlp", args = "--no-multiarch")
Downloading GitHub repo bnosac/pattern.nlp@master

   checking for file 'C:\Users\Max\AppData\Local\Temp\RtmpUxH6eT\remotes19543d9e3bf\bnosac-pattern.nlp-91a459f/DESCRIPTION' ...

   checking for file 'C:\Users\Max\AppData\Local\Temp\RtmpUxH6eT\remotes19543d9e3bf\bnosac-pattern.nlp-91a459f/DESCRIPTION' ... 

√  checking for file 'C:\Users\Max\AppData\Local\Temp\RtmpUxH6eT\remotes19543d9e3bf\bnosac-pattern.nlp-91a459f/DESCRIPTION'

-  preparing 'pattern.nlp':
   checking DESCRIPTION meta-information ...

   checking DESCRIPTION meta-information ... 

√  checking DESCRIPTION meta-information

-  checking for LF line-endings in source and make files and shell scripts

-  checking for empty or unneeded directories

-  looking to see if a 'data/datalist' file should be added

-  building 'pattern.nlp_1.0.tar.gz'

Installing package into ‘C:/Users/Max/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
* installing *source* package 'pattern.nlp' ...
** R
** data
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
  converting help for package 'pattern.nlp'
    finding HTML links ... done
    pattern.nlp-package                     html  
    pattern_pos                             html  
    pattern_sentiment                       html  
    penn_treebank_postags                   html  
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error: package or namespace load failed for 'pattern.nlp':
 .onAttach failed in attachNamespace() for 'pattern.nlp', details:
  call: autodetectPython(pythonExePath)
  error: Python 64bit can't be connected with R 32bit!
Error: loading failed
Execution halted
*** arch - x64
Traceback (most recent call last):

  File "<string>", line 1, in <module>

  File "C:\Python27\lib\site-packages\pattern\text\en\__init__.py", line 61, in <module>

    from pattern.text.en.inflect import (

  File "C:\Python27\lib\site-packages\pattern\text\en\__init__.py", line 80, in <module>

from pattern.text.en import wordnet

  File "C:\Python27\lib\site-packages\pattern\text\en\wordnet\__init__.py", line 48, in <module>

import nltk

ImportError
: 
No module named nltk
Error: package or namespace load failed for 'pattern.nlp':
 .onAttach failed in attachNamespace() for 'pattern.nlp', details:
  call: PythonInR::pyExec("from pattern.en import sentiment as sentiment_en")
  error: An error has occured while executing Python code. See traceback above.
Error: loading failed
Execution halted
ERROR: loading failed for 'i386', 'x64'
* removing 'C:/Users/Max/Documents/R/win-library/3.5/pattern.nlp'
In R CMD INSTALL
Error in i.p(...) : 
  (converted from warning) installation of package ‘C:/Users/Max/AppData/Local/Temp/RtmpUxH6eT/file1954409c31e3/pattern.nlp_1.0.tar.gz’ had non-zero exit status
> can_find_python_cmd(required_modules = "pattern.db")

Surprisingly, even though I am running R in 64 bit, this time the error indicates that I am running Python in 64 bit and R in 32 bit.

jwijffels commented 5 years ago

Maybe install both python 32 as 64 bit as well as pattern for these 2

jwijffels commented 5 years ago

The error message about nltk seems like the python pattern package has been updated. As it seems now to need nltk. So either you will have to do also pip install nltk hoping that the update pattern did, did not break this r package or just install pattern version 2.6 which was used to develop this r package

Zaletio commented 5 years ago

Installing both Python versions (as well as the pattern module) did not do the trick as the same error occured.

Thus, following your tip, I deinstalled both Python variants and reinstalled Python 2.7.13 64 bit. Next, I downloaded pattern version 2.6 from https://www.clips.uantwerpen.be/pattern.

Then, I ran the commands C:\Users\...\Downloads\pattern-2.6\pattern-2.6 and python setup.py install. This seemed to complete the installation of the pattern package.

So, I started R (64 bit). To be sure, I entered the following commands:

library(xml2)
library(Rcpp)
library(devtools)
library(PythonInR)
library(findpython)
library(digest)
library(data.table)

 remove.packages('pattern.nlp')
library(findpython)
can_find_python_cmd(required_modules = "pattern.db")
devtools::install_github("bnosac/pattern.nlp", args = "--no-multiarch")
library(pattern.nlp)

This led to the following output:


library(findpython)
> can_find_python_cmd(required_modules = "pattern.db")
[1] TRUE
attr(,"python_cmd")
[1] "C:\\Python27\\python.exe"
> devtools::install_github("bnosac/pattern.nlp", args = "--no-multiarch")
Downloading GitHub repo bnosac/pattern.nlp@master

   checking for file 'C:\Users\Max\AppData\Local\Temp\Rtmpuaktzg\remotes147471d263e8\bnosac-pattern.nlp-91a459f/DESCRIPTION' ...

   checking for file 'C:\Users\Max\AppData\Local\Temp\Rtmpuaktzg\remotes147471d263e8\bnosac-pattern.nlp-91a459f/DESCRIPTION' ... 

√  checking for file 'C:\Users\Max\AppData\Local\Temp\Rtmpuaktzg\remotes147471d263e8\bnosac-pattern.nlp-91a459f/DESCRIPTION'

-  preparing 'pattern.nlp':
   checking DESCRIPTION meta-information ...

   checking DESCRIPTION meta-information ... 

√  checking DESCRIPTION meta-information

-  checking for LF line-endings in source and make files and shell scripts

-  checking for empty or unneeded directories

-  looking to see if a 'data/datalist' file should be added

-  building 'pattern.nlp_1.0.tar.gz'

Installing package into ‘C:/Users/Max/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
* installing *source* package 'pattern.nlp' ...
** R
** data
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
  converting help for package 'pattern.nlp'
    finding HTML links ... done
    pattern.nlp-package                     html  
    pattern_pos                             html  
    pattern_sentiment                       html  
    penn_treebank_postags                   html  
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error: package or namespace load failed for 'pattern.nlp':
 .onAttach failed in attachNamespace() for 'pattern.nlp', details:
  call: autodetectPython(pythonExePath)
  error: Python 64bit can't be connected with R 32bit!
Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'
* removing 'C:/Users/Max/Documents/R/win-library/3.5/pattern.nlp'
In R CMD INSTALL
Error in i.p(...) : 
  (converted from warning) installation of package ‘C:/Users/Max/AppData/Local/Temp/Rtmpuaktzg/file14744d8c3a78/pattern.nlp_1.0.tar.gz’ had non-zero exit status

> library(pattern.nlp)> 
Error in library(pattern.nlp) : there is no package called ‘pattern.nlp’

If it was possible, I would've included a screenshot to support that I am actually using R 64 bit (contrary to the error). Moreover, the fact that can_find_python_cmd(required_modules = "pattern.db") returns [1] TRUE already indicates that I am using the correct bit-version (otherwise the connection with Python could not've been made, right?).

Do you have another suggestion? I'm becoming desperate...

EDIT: I even installed R 3.3.0, hoping that would help. Running the same commands then, let to the following (similar) error:

Downloading GitHub repo bnosac/pattern.nlp@master

   checking for file 'C:\Users\Max\AppData\Local\Temp\RtmpygySK0\remotes25cc722e44af\bnosac-pattern.nlp-91a459f/DESCRIPTION' ...

   checking for file 'C:\Users\Max\AppData\Local\Temp\RtmpygySK0\remotes25cc722e44af\bnosac-pattern.nlp-91a459f/DESCRIPTION' ... 

√  checking for file 'C:\Users\Max\AppData\Local\Temp\RtmpygySK0\remotes25cc722e44af\bnosac-pattern.nlp-91a459f/DESCRIPTION'

-  preparing 'pattern.nlp':
   checking DESCRIPTION meta-information ...

   checking DESCRIPTION meta-information ... 

√  checking DESCRIPTION meta-information

-  checking for LF line-endings in source and make files

-  checking for empty or unneeded directories

-  looking to see if a 'data/datalist' file should be added

-  building 'pattern.nlp_1.0.tar.gz'

Installing package into ‘C:/Users/Max/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
* installing *source* package 'pattern.nlp' ...
** R
** data
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error : .onAttach failed in attachNamespace() for 'pattern.nlp', details:
  call: autodetectPython(pythonExePath)
  error: Python 64bit can't be connected with R 32bit!
Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'
* removing 'C:/Users/Max/Documents/R/win-library/3.3/pattern.nlp'
Error: (converted from warning) running command '"C:/PROGRA~1/R/R-33~1.0/bin/x64/R" CMD INSTALL -l "C:\Users\Max\Documents\R\win-library\3.3" "C:/Users/Max/AppData/Local/Temp/RtmpygySK0/file25cc403760bb/pattern.nlp_1.0.tar.gz"' had status 1

Therefore, I am running out of possibilities to try. Does anyone have an adequate suggestion?

jwijffels commented 5 years ago

Show a screenshot that you are now using 64bit r as it now connects to a 64 bit of python. Use rgui instead of rstudio if you want to be sure.

Zaletio commented 5 years ago

r 64 bit errror

As requested, the screenshot from the Rgui.

EDIT: I also uploaded the screenshot from the R 3.3.0 variant I tried:

r 3 3 0 error

jwijffels commented 5 years ago

Maybe use the argument args = “--no-test-load --no-multi-arch”

Zaletio commented 5 years ago

Same error, unfortunately. Would the version of R matter in this case; i.e. if I would try variant 3.0 could that help?

Moreover; is Rtools necessary to run Pattern.nlp? Looking at the warning 1 error, perhaps it indicates a lack of Rtools? EDIT: NVM, running find_rtools() returns TRUE

Zaletio commented 5 years ago

After almost three days, I got it to work by using the following:

remove.packages('pattern.nlp')
library(findpython)
can_find_python_cmd(required_modules = "pattern.db")
devtools::install_github("bnosac/pattern.nlp", INSTALL_opts = "--no-multiarch")
library(pattern.nlp)

Appartenly, the difference between INSTALL_Opts and args was crucial. Hope this saves time for others and thanks @jwijffels for the quick responses yesterday!

One final question: can pattern_sentiment only be applied to characters put into the console (i.e. test <- pattern_sentiment("hello", language = "english")?

Or is it also possible to apply it to a dataframe or table column, as I receive the error stating Error in data.table::setDF(score) : All elements in argument 'x' to 'setDF' must be of same length?

Zaletio commented 5 years ago

Nvm, I fixed it through the apply function to execute pattern_sentiment to every row of my df. Great package, thanks again to @jwijffels !

hack-r commented 5 years ago

@Zaletio @jwijffels Yes I can confirm it is INSTALL_Opts not args. I would suggest to publish this in the installation instructions.

jwijffels commented 5 years ago

@Zaletio thank you for the note about the usage of INSTALL_opts. Apparently devtools has changed the argument which allows to pass things to R CMD INSTALL. It was previously called args, now you need to pass that argument directly to the INSTALL_opts argument of install.packages. Hence giving you the installation trouble. You should really have bugged the author of the devtools package for this as the updates made on the devtools package ecosystem are not backwards-compatible with the previous releases of devtools.