Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

casperjs does not find phantomjs

I've downloaded the latest version of casperjs (1.03) and phantomjs (1.9.2).

So I took this little simple script from the casper page:

var casper = require('casper').create({
    verbose: true,
    logLevel: "debug"
});
var casper = new require('casper').Casper();

and when I try to run it I get the following error:

noname:phantomjs-1.9.2 Tom$ casperjs/bin/casperjs tipico2.js 
Fatal: [Errno 2] No such file or directory; did you install phantomjs?

So, this is my directory structure:

phantomjs-1.9.2/ <-- the folder containing phantomjs
phantomjs-1.9.2/casperjs/ <-- a subfolder containting casperjs

Why does it not work?

like image 515
toom Avatar asked Oct 20 '13 11:10

toom


4 Answers

The solution is actually very simple. Just export the path where the binary of phantomjs is. In my case this is /Users/Tom/Downloads/phantomjs-1.9.2/bin, hence

export PATH=$PATH:/Users/Tom/Downloads/phantomjs-1.9.2/bin
like image 145
toom Avatar answered Sep 21 '22 20:09

toom


Faced the same problem when installed casper with npm globally on osx. At first I've set environment variable PHANTOMJS_EXECUTABLE to path where phantomjs was installed (it's usually /usr/local/lib/node_modules/casperjs/node_modules/phantomjs/lib/phantom/bin/phantomjs phantomjs) with

export PHANTOMJS_EXECUTABLE=/usr/local/lib/node_modules/casperjs/node_modules/phantomjs/lib/phantom/bin/phantomjs phantomjs

this helped only partially as I still got an error like there's no file nor folder /usr/local/bin/phantomjs, so I've just created symlink and pointed it to real binary folder with

ln -s /usr/local/lib/node_modules/casperjs/node_modules/phantomjs/lib/phantom/bin/phantomjs /usr/local/bin/phantomjs

hope this will help someone :)

like image 21
Egor Litvinchuk Avatar answered Sep 25 '22 20:09

Egor Litvinchuk


For OS X:

brew install casperjs --devel

brew install phantomjs

and it will works

like image 22
h0x91B Avatar answered Sep 21 '22 20:09

h0x91B


If you are getting this error in PHP, place this above your exec:

<?php
    putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs");
?>

Where path /usr/local/bin/phantomjs is the path to your phantomjs install. You can get this by typing which phantomjs into terminal for example.

like image 21
digout Avatar answered Sep 21 '22 20:09

digout