casperjs does not find phantomjs
Asked Answered
P

7

24

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?

Pluralism answered 20/10, 2013 at 11:43 Comment(0)
P
23

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
Pluralism answered 20/10, 2013 at 12:6 Comment(3)
You can also set an environment variable, instead of modifying your PATH. PHANTOMJS_EXECUTABLE=/Users/Tom/Downloads/phantomjs-1.9.2/bin/phantomjsKilometer
how can I use this evnriontemtnal variable then?Isolating
You need both PATH and PHANTOMJS_EXECUTABLE (as @Brian mentioned) to get this working.Vortex
C
17

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 :)

Chelate answered 1/7, 2015 at 17:42 Comment(3)
how do I use that variable then? this PHANTOMJS_EXECTUABLE - how do I use it?Isolating
@Isolating you just need to set locate phantomjs binary and then set it to PHANTOMJS_EXECUTABLE in the console. then it will be used by casper to locate phantom and work properlyChelate
For folks trying to use CasperJS with slimerjs (instead of phantomjs): I've gotten it to run, much like the above, by setting an equivalent environment variable SLIMERJS_EXECUTABLE=/path/to/slimerjs but also I had to pass --engine=slimerjs as an argument to the casperjs executable.Mihrab
U
5

For OS X:

brew install casperjs --devel

brew install phantomjs

and it will works

Uxorious answered 14/3, 2016 at 13:52 Comment(1)
--devel flag doesn't seem to work, but other than that, this works on High SierraNoctiluca
I
3

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.

Inglenook answered 10/6, 2018 at 9:2 Comment(0)
A
0

Solution For Windows

STEP 1 - Go to Environment Variables

Start -> Environment Variables -> Environment Variables or My PC -> Properties -> Advanced System Settings -> Environment Variables


STEP 2 - Set new PATH to your PhantomJS/bin folder

Select PATH (User or System) -> Edit

New -> Browse -> find your BIN folder in PhantomJS installation on your HDD Accept


STEP 3 - Test Your Work

Open CMD -> Type "phantomjs -v"

You should get phantomJS version number as answer in any folder in your tree.

Axiomatic answered 10/12, 2017 at 9:5 Comment(0)
C
0

I had this problem. Tried on 2 different windows machines.

Deleted all npm installed versions from node_modules folders and AppData / Roaming....

Deleted phantom and casper from c:/ where initially installed.

Downloaded phantom and extracted to Program Files folder from https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-windows.zip

Downloaded casper and extracted to Program Files folder from https://github.com/casperjs/casperjs/zipball/1.1.0

Set System Environment Variable C:\Program Files\phantomjs-2.1.1-windows\bin

Set System Environment Variable C:\Program Files\casperjs-casperjs-b5c59e1\bin

I DIDN'T set PHANTOMJS_EXECUTABLE as some other posts have mentioned. Not sure whether it would make a difference, but 100% working with above steps on Windows 10 with Phantom 2.1.1 and casper 1.1.0

Cowbird answered 13/11, 2018 at 10:44 Comment(0)
U
0

Faced the same problem after installing casperjs with npm globally on osx. The solution is actually very simple. You have to include these lines at the top of your script to connect casperjs with phantomjs.

phantom.casperPath = "/path_to/casperjs/";
phantom.injectJs(phantom.casperPath + "/bin/bootstrap.js");
Unmeant answered 26/7, 2019 at 9:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.