Javascript phantomjs:找不到命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6448459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 21:46:13  来源:igfitidea点击:

phantomjs: command not found

javascriptdebuggingerror-handlingphantomjs

提问by user730569

I followed these instructions(except for copying the executable to my PATH because I cannot seem to find it and it does not seem necessary). Then I made a file called image_render.js in my public javascripts directory with

我遵循了这些说明(除了将可执行文件复制到我的 PATH 之外,因为我似乎找不到它,而且似乎没有必要)。然后我在我的公共 javascripts 目录中创建了一个名为 image_render.js 的文件

console.log('Hello, world!');
phantom.exit();

inside it, saved it, and ran phantomjs render_image.jsin my terminal. However, my terminal does not recognize the command:

在它里面,保存它,然后phantomjs render_image.js在我的终端中运行。但是,我的终端无法识别该命令:

-bash: phantomjs: command not found

What have I done wrong?

我做错了什么?

回答by icktoofay

The PATHreally is the important part. You can skip it, however, if you specify the absolute path. Try something like this:

PATH确实是重要的组成部分。但是,如果指定绝对路径,则可以跳过它。尝试这样的事情:

/path/to/phantomjs render_image.js

...but that can get tiring. For a quick way to add it to your PATH, from the directory of the phantomjsexecutable, symbolically link it into /usr/local/bin:

……但这会很累。为了快速将它添加到您的PATH,从phantomjs可执行文件的目录中,将其符号链接到/usr/local/bin

sudo ln -s /path/to/phantomjs /usr/local/bin/

/usr/local/binis likely on your PATH.

/usr/local/bin很可能在您的PATH.

回答by Brian Sanchez

add this line to this file /home/optiman2/.bashrc

将此行添加到此文件 /home/optiman2/.bashrc

PATH=/home/optiman2/phantomjs/bin:$PATH

this worked for me.

这对我有用。

and remember to use this command, before test phantomjs: source .bashrc

并记得在测试 phantomjs 之前使用这个命令: source .bashrc

回答by Hyman Collins

FYI to Windows users upgrading to version 2.0.0 - the executable has moved. In addition to changing your PATH environment variable to 2.0.0, you'll need to add \binto the end of the PATH that you had for the 1.x.x.

仅供升级到版本 2.0.0 的 Windows 用户使用 - 可执行文件已移动。除了将 PATH 环境变量更改为 2.0.0 之外,您还需要将\binPATH添加到 1.xx 的末尾

回答by Trev14

Mac PATH suggested setup:

Mac PATH 建议设置:

  1. Open Terminal.
  2. Type vi ~/.bash_profileand hit enter (this opens or creates your bash_profile where you can customize Terminal commands).
  3. Press ito enter insert/edit mode then type alias phantomjs='~/PATH/TO/phantomjs'and be sure to replace ~/PATH/TO/phantomjswith something like ~/Documents/PhantomJS/bin/phantomsjor wherever the file exists on your machine.
  4. Press escto exit insert/edit mode then type :xand hit enter to save the file.
  5. Quit and re-open Terminal.
  6. Type phantomjsand hit enter. If you see the prompt phantomjs>then you're all set.
  7. Type phantom.exit()to end the PhantomJS program.
  8. Now you can navigate to any folder and run PhantomJS by simply typing phantomjs. This is helpful when saving screenshots because the images will be saved inside the folder that's active in your Terminal.
  1. 打开终端。
  2. 键入vi ~/.bash_profile并回车(这打开或创建.bash_profile中,你可以自定义终端命令)。
  3. i进入插入/编辑模式,然后键入alias phantomjs='~/PATH/TO/phantomjs'并确保替换~/PATH/TO/phantomjs为类似~/Documents/PhantomJS/bin/phantomsj文件或文件存在于您机器上的任何位置。
  4. esc退出插入/编辑模式,然后键入:x并按回车键保存文件。
  5. 退出并重新打开终端。
  6. 键入phantomjs并按回车键。如果您看到提示,phantomjs>则说明您已准备就绪。
  7. 键入phantom.exit()以结束 PhantomJS 程序。
  8. 现在您可以导航到任何文件夹并通过简单地输入phantomjs. 这在保存屏幕截图时很有用,因为图像将保存在终端中处于活动状态的文件夹中。

回答by Jennie Ji

Whatever command is just a executable file. To be accessible by type its name directly, you have to put it into a path that system will look for that file directly.
For linux/OSX, it's /usr/binor /usr/local/bin. Which really works? Well, it depends...
So what worked for me is extract the 'phantomjs.tar.bz2' source file to somewhere and copy the executable file to /usr/local/binlike this:

任何命令都只是一个可执行文件。要通过直接键入其名称来访问,您必须将其放入系统将直接查找该文件的路径中。
对于 linux/OSX,它是/usr/bin/usr/local/bin。哪个真的有效?好吧,这取决于...
所以对我有用的是将“phantomjs.tar.bz2”源文件提取到某个地方并将可执行文件复制到/usr/local/bin,如下所示:

cp path-of-extracted-phantomjs/bin/phantomjs /usr/local/bin

cp path-of-extracted-phantomjs/bin/phantomjs /usr/local/bin