简体   繁体   English

phantomjs:找不到命令

[英]phantomjs: command not found

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).我遵循了这些说明(除了将可执行文件复制到我的 PATH 之外,因为我似乎找不到它,而且似乎没有必要)。 Then I made a file called image_render.js in my public javascripts directory with然后我在我的公共 javascripts 目录中创建了一个名为 image_render.js 的文件

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

inside it, saved it, and ran phantomjs render_image.js in my terminal.在它里面,保存它,并在我的终端中运行phantomjs render_image.js However, my terminal does not recognize the command:但是,我的终端无法识别该命令:

-bash: phantomjs: command not found

What have I done wrong?我做错了什么?

The PATH really is the important part. PATH确实是重要的部分。 You can skip it, however, if you specify the absolute path.但是,如果指定绝对路径,则可以跳过它。 Try something like this:尝试这样的事情:

/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 phantomjs executable, symbolically link it into /usr/local/bin :为了快速将其添加到您的PATH ,从phantomjs可执行文件的目录中,以符号方式将其链接到/usr/local/bin

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

/usr/local/bin is likely on your PATH . /usr/local/bin可能在您的PATH

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

FYI to Windows users upgrading to version 2.0.0 - the executable has moved.仅供升级到版本 2.0.0 的 Windows 用户使用 - 可执行文件已移动。 In addition to changing your PATH environment variable to 2.0.0, you'll need to add \\bin to the end of the PATH that you had for the 1.xx除了将 PATH 环境变量更改为 2.0.0,您还需要将\\bin添加到 1.xx 的 PATH 末尾

Mac PATH suggested setup: Mac PATH 建议设置:

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

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/bin or /usr/local/bin .对于 linux/OSX,它是/usr/bin/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/bin like this:所以对我有用的是将 'phantomjs.tar.bz2' 源文件提取到某个地方,然后将可执行文件复制到/usr/local/bin ,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM