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
phantomjs: command not found
提问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.js
in 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 PATH
really 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 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
.
回答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 \bin
to the end of the PATH that you had for the 1.x.x.
仅供升级到版本 2.0.0 的 Windows 用户使用 - 可执行文件已移动。除了将 PATH 环境变量更改为 2.0.0 之外,您还需要将\bin
PATH添加到 1.xx 的末尾
回答by Trev14
Mac PATH suggested setup:
Mac PATH 建议设置:
- Open Terminal.
- Type
vi ~/.bash_profile
and hit enter (this opens or creates your bash_profile where you can customize Terminal commands). - Press
i
to enter insert/edit mode then typealias 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. - Press
esc
to exit insert/edit mode then type:x
and hit enter to save the file. - Quit and re-open Terminal.
- Type
phantomjs
and hit enter. If you see the promptphantomjs>
then you're all set. - Type
phantom.exit()
to end the PhantomJS program. - 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.
- 打开终端。
- 键入
vi ~/.bash_profile
并回车(这打开或创建.bash_profile中,你可以自定义终端命令)。 - 按
i
进入插入/编辑模式,然后键入alias phantomjs='~/PATH/TO/phantomjs'
并确保替换~/PATH/TO/phantomjs
为类似~/Documents/PhantomJS/bin/phantomsj
文件或文件存在于您机器上的任何位置。 - 按
esc
退出插入/编辑模式,然后键入:x
并按回车键保存文件。 - 退出并重新打开终端。
- 键入
phantomjs
并按回车键。如果您看到提示,phantomjs>
则说明您已准备就绪。 - 键入
phantom.exit()
以结束 PhantomJS 程序。 - 现在您可以导航到任何文件夹并通过简单地输入
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