1

I've been trying to install pdf-extract as a gem in my Rails app. When I go to build, I get this error because it uses sqlite as a dependency:

Fetching sqlite3 1.3.13
Installing sqlite3 1.3.13 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sqlite3-1.3.13/ext/sqlite3
/home/vagrant/.rbenv/versions/2.3.0/bin/ruby -r ./siteconf20180425-3298-14ft47q.rb extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'brew install sqlite3',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/home/vagrant/.rbenv/versions/2.3.0/bin/$(RUBY_BASE_NAME)
    --with-sqlite3-config
    --without-sqlite3-config
    --with-pkg-config
    --without-pkg-config
    --with-sqlite3-dir
    --without-sqlite3-dir
    --with-sqlite3-include
    --without-sqlite3-include=${sqlite3-dir}/include
    --with-sqlite3-lib
    --without-sqlite3-lib=${sqlite3-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0-static/sqlite3-1.3.13/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/sqlite3-1.3.13 for inspection.
Results logged to /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0-static/sqlite3-1.3.13/gem_make.out

An error occurred while installing sqlite3 (1.3.13), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.13'` succeeds before bundling.

In Gemfile:
  pdf-extract was resolved to 0.1.1, which depends on
    sqlite3

Is there anyway I can still use pdf-extract? Heroku doesn't allow sqlite in production.

Any help is greatly appreciated.

EDIT:

For those who encounter this issue in the future: I attempted to hack the gem to get it to work with postgres--this seemed to work though it caused the gem's performance to tank. Ultimately, I created an entirely separate api-only app, deployed directly to AWS using Elastic Beanstalk rather than through Heroku so that app could use sqlite3, and called the api-app to implement the gem functionality in my original app.

This approach would likely work well for any gems that cause dependency issues in a preexisting Rails app.

  • "Heroku doesn't allow sqlite in production." Do you have a reference for that? Its ephemeral filesystem would seriously limit the utility of file-based databases, but SQLite can operate in memory. I'm not sure how `pdf-extract` uses SQLite, though. – ChrisGPT was on strike Apr 25 '18 at 14:10
  • https://stackoverflow.com/questions/7963561/heroku-cannot-run-git-push-heroku-master – Noah Finberg Apr 25 '18 at 14:27

2 Answers2

2

There is no way to use a gem that has a dependency if you cannot install that dependency. Your options are to

  • Use a different PDF Gem
  • Use an alternative to Heroku
  • Find a way to implement the functionality you need from Pdf-extract yourself without using any gems
  • Go through the gem's code to see where it uses sqlite and try to get rid of that code without breaking the gem
chevybow
  • 9,959
  • 6
  • 24
  • 39
0

I would save yourself the time and trouble involved with getting this to work and look at alternative libraries. There is a PDF text extraction gem called HyPDF that is also a Heroku add-on.

R.F. Nelson
  • 2,254
  • 2
  • 12
  • 24
  • The issue is HyPDF doesn't do what I need it to do. Pdf-extract did it perfectly when I tested it in a ruby script. Is there anyway to remove a dependency from a ruby gem or replace sqlite with pg as a dependency instead? I'm looking to extract the references from a PDF document (e.g. pdf-extract extract --references --titles myfile.pdf). – Noah Finberg Apr 25 '18 at 14:32
  • @NoahFinberg If you must use this gem, then you cannot deploy to Heroku. Hacking the gem to use Postgres instead of SQLite would probably be more work than finding an alternative to Heroku. – R.F. Nelson Apr 25 '18 at 14:39