billgreenwald / Pubmed-Batch-Download

Batch download articles based on PMID (Pubmed ID)
MIT License
110 stars 45 forks source link

Error with pubmedid2pdf.rb #1

Closed joannadiong closed 8 years ago

joannadiong commented 8 years ago

Hi, I'm new to Bash (working on Linux Mint 17.2) and not a Ruby user. I installed Ruby 2.1.2 via RVM and the installation went fine. I ran bash setup.sh and the pubmedid2pdf.rb script, but obtained the error below:

[12:33] ~/.../Pubmed-Batch-Download$ ruby pubmedid2pdf.rb 26830047,26728431
/home/joanna/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- camping (LoadError)
    from /home/joanna/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /home/joanna/Dropbox/Sketchbook/ruby/Pubmed-Batch-Download/pdfetch.rb:27:in `<top (required)>'
    from /home/joanna/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /home/joanna/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from pubmedid2pdf.rb:37:in `<main>'

Would appreciate if you could suggest how this could be fixed or if I made a mistake somewhere. This is a great tool, and many thanks in advance.

billgreenwald commented 8 years ago

It seems that the setup script didn't install camping properly.

can you try running sudo gem install camping

and try it again assuming that works?

joannadiong commented 8 years ago

Tried but didn't work. This is the version of camping that installed:

[17:34] ~$ sudo gem install camping
[sudo] password for joanna: 
Successfully installed camping-2.1.532
1 gem installed
Installing ri documentation for camping-2.1.532...
Installing RDoc documentation for camping-2.1.532...

Running script produced same error, reproduced here for completeness:

[17:34] ~/.../Pubmed-Batch-Download$ ruby pubmedid2pdf.rb 26830047,26728431
/home/joanna/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- camping (LoadError)
    from /home/joanna/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /home/joanna/Dropbox/Sketchbook/ruby/Pubmed-Batch-Download/pdfetch.rb:27:in `<top (required)>'
    from /home/joanna/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /home/joanna/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from pubmedid2pdf.rb:37:in `<main>'
billgreenwald commented 8 years ago

I just installed it on another computer fresh to test, and I couldn't replicate the error. I'm having trouble figuring out what is causing it. Did you have ruby installed before you began? The only thing I could think of is that it may be running 2.1.0 after you installed camping for 2.1.2 as you have

/site_ruby/2.1.0

in your file path.

Perhaps try

rvm use ruby2.1.2

or the appropriate version

joannadiong commented 8 years ago

Thanks Bill. I also tried installation on another computer and still got the load error. Here are my installation steps/ hitches along the way, if it helps show the problem and for new users too:

Install RVM from instructions here:

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -sSL https://get.rvm.io | bash -s stable --ruby

Received error:

curl: (77) error setting certificate verify locations:
  CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none

From here, the issue is that curl expected the certificate to be at the path /etc/pki/tls/certs/ca-bundle.crt but could not find it because it was at the path /etc/ssl/certs/ca-certificates.crt.

Copy certificate to the expected destination by running:

sudo mkdir -p /etc/pki/tls/certs
sudo cp /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt

Re-run RVM install command:

\curl -sSL https://get.rvm.io | bash -s stable --ruby

source /home/joanna/.rvm/scripts/rvm
rvm install 2.1.2
rvm use 2.1.2

cd /home/joanna/Dropbox/Sketchbook/ruby/Pubmed-Batch-Download/
bash setup.sh
ruby pubmedid2pdf.rb 26830047,26728431 

Please let me know if you spot grievous mistakes in the process, and/or itemise how you installed it on a fresh computer. Otherwise I will work on this a little longer before trying elsewhere. Thanks

billgreenwald commented 8 years ago

The certfile error is probably a property of Mint--it shouldn't be from this program.

What was the problem with your final ruby run with the line below?

ruby pubmedid2pdf.rb 26830047,26728431

joannadiong commented 8 years ago

Received same error:

[16:33] ~/.../Pubmed-Batch-Download$ ruby pubmedid2pdf.rb 26830047,26728431 
/home/joanna/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- camping (LoadError)
    from /home/joanna/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /home/joanna/Dropbox/Sketchbook/ruby/Pubmed-Batch-Download/pdfetch.rb:27:in `<top (required)>'
    from /home/joanna/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /home/joanna/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from pubmedid2pdf.rb:37:in `<main>'
billgreenwald commented 8 years ago

Try cloning the CampingFix branch and see if it works now--I tried a fix I found from some searching online

Alternatively if that still doesn't work, check if your apache is being run from the same user (suggested from here )

It's also worth a quick check that if you launch the ruby shell and load camping, if the error comes up. This can be done via

ruby
require 'rubygems'
require 'camping'

and seeing if any errors pop up

joannadiong commented 8 years ago

Tried a different route. I also chatted with Andy Shen about the problem. He worked out that the ruby that is in the $PATH is not the same one that installed camping rubygem. Ie. camping did not install in the rvm gem:

[09:34] ~$ rvm use 2.1.2
Using /home/joanna/.rvm/gems/ruby-2.1.2
[09:34] ~$ which ruby
/home/joanna/.rvm/rubies/ruby-2.1.2/bin/ruby
[09:34] ~$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
[09:35] ~$ which gem
/home/joanna/.rvm/rubies/ruby-2.1.2/bin/gem
[09:35] ~$ gem list camping

*** LOCAL GEMS ***

The solution was to install camping (and also mechanize) in the rvm gem:

rvm use 2.1.2
which gem
gem list camping mechanize
gem install camping
gem install mechanize
gem list camping mechanize

Subsequently, the pubmedid2pdf script ran, except that it failed to fetch PDFs of records that have PDFs, but that might be another issue...

[12:03] ~/.../Pubmed-Batch-Download$ ruby pubmedid2pdf.rb 26830047,26728431
Trying to fetch 26830047
Trying blackwell_synergy
Trying cell_press
Trying choose_science_direct
Trying coldspringharbour
Trying direct_pdf_link
Trying humana_press
Trying ingenta_connect
Trying jbc
Trying nature
Trying nature_reviews
Trying pnas
Trying pubmed_central
Trying science_direct
Trying springer_link
Trying unknown
Trying wiley
Trying zeneric
Trying zframe
** fetching of reprint 26830047 failed
Trying to fetch 26728431
Trying blackwell_synergy
Trying cell_press
Trying choose_science_direct
Trying coldspringharbour
Trying direct_pdf_link
Trying humana_press
Trying ingenta_connect
Trying jbc
Trying nature
Trying nature_reviews
Trying pnas
Trying pubmed_central
Trying science_direct
Trying springer_link
Trying unknown
Trying wiley
Trying zeneric
Trying zframe
** fetching of reprint 26728431 failed
billgreenwald commented 8 years ago

As far as the actual script itself failing, I've found it's mainly from not being on a network that has access to the articles. Otherwise, I'm not sure how to fix the html parser--I only updated the dependencies and syntax for Ruby 2.0. Let me know if there are any more questions, otherwise I will close this soon.

joannadiong commented 8 years ago

I ran the script on a university computer on the ethernet for PubMed IDs with or without "Free full text" but could not retrieve PDFs. But in relation to the installation issue, happy to close. Thank you.