【问题标题】:Installing PhantomJS on Mac在 Mac 上安装 PhantomJS
【发布时间】:2016-08-27 21:33:34
【问题描述】:

我正在尝试在我的 Mac (Yosemite) 上安装 PhantomJS。

我做了以下事情:

npm install phantomjs

然后我做了:

npm install phantomjs-prebuilt

这两个都出现在我的 node_modules 中。但是当我尝试运行 phantomjs --version我得到 ​​p>

   -bash: phantomjs: command not found

还尝试从下载网站安装二进制文件,但没有。我错过了什么?最终目标是使用 casperjs,但目前 casper 正在询问

Fatal: [Errno 2] No such file or directory; did you install phantomjs?

我以为我做到了....?

【问题讨论】:

    标签: installation phantomjs casperjs


    【解决方案1】:

    接受的答案已过时。在 Mac 上,使用 Homebrew,键入:

    brew tap homebrew/cask
    brew cask install phantomjs
    

    某些 MacOS 版本可能不需要第一步。

    对于较新版本的木桶(2021 及更高版本),请使用

    brew install --cask phantomjs
    

    【讨论】:

    • 首先它要求 > brew tap homebrew/cask > 然后是你的答案。至少对于 High Sierra 和 Mojave。
    • 这里是木桶的更新版本。 brew install --cask phantomjs
    【解决方案2】:

    适用于 Mac BigSur

    brew tap homebrew/cask
    brew install --cask phantomjs
    

    【讨论】:

      【解决方案3】:

      如果您使用的是Homebrew,您可以输入:

      brew tap homebrew/cask
      brew cask install phantomjs
      

      【讨论】:

      • 它已从 homebrew/core 迁移到 homebrew/cask。您可以通过运行再次访问它: brew tap homebrew/cask 然后您可以通过运行来安装它: brew cask install phantomjs
      • 它提醒我使用brew install --cask phantomjs
      【解决方案4】:

      经过大量挖掘,我在 High-Sierra 旧版本的 phantomjs (would not work 上发现了这一点。

      另外,phantomjs download page 的 zip 文件有问题。

      如果您需要新的 phantom,只需转到 this 页面并下载 phantomjs 2.1.1(或更高版本)。

      【讨论】:

        【解决方案5】:

        您不应该在全球范围内安装phantomjs 吗?

        npm install -g phantomjs

        由于是在本地安装,命令-

        phantomjs -v

        不会在任何地方都有效。

        您可以在此处查看本地安装和全局安装之间的区别:https://docs.npmjs.com/cli/install

        【讨论】:

          【解决方案6】:
          1. http://phantomjs.org/download.html下载phantomjs最新版本(例如:phantomjs-2.1.1-macosx.zip)
          2. 解压到某个路径(例如:~/Desktop/phantomjs-2.1.1-macosx)
          3. 在终端上运行此命令 - sudo ln -n ~/Desktop/phantomjs-2.1.1-macosx/bin/phantomjs /usr/local/bin/
          4. 通过命令从终端启动 phantomjs:phantomjs
          5. 通过命令检查 phantomjs 版本:phantomjs -v
          6. 通过命令检查phantomjs路径:which phantomjs

          【讨论】:

          • 你救了我。
          【解决方案7】:

          您需要将 phantomjs 二进制文件添加到 PATH。您可以通过修改环境变量或将二进制文件符号链接到例如/usr/local/bin

          例如,如果您想对二进制文件进行符号链接:

          cd $HOME
          curl -O https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-macosx.zip
          ln -s $HOME/phantomjs-2.1.1-macosx/bin/phantomjs /usr/bin/phantomjs
          

          或者如果你想修改PATH环境变量:

          cd $HOME
          curl -O https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-macosx.zip
          

          并将这一行添加到该文件中:~/.bash_profile:

          export PATH=$HOME/phantomjs-2.1.1-macosx/bin:$PATH
          

          然后运行:

          source ~/.bash_profile
          

          【讨论】:

          • 他们为什么不做一个合适的安装程序?
          • windows 也一样。适合新手的 PITA
          • 我无法解压缩phantomjs-2.1.1-macosx.zip。 @Godraude
          • 有人下载并解压了最新的macosx phantomjs包吗?
          猜你喜欢
          • 2016-02-26
          • 1970-01-01
          • 2014-05-31
          • 1970-01-01
          • 1970-01-01
          • 2014-05-20
          • 2018-10-12
          • 2014-06-05
          • 2013-02-18
          相关资源
          最近更新 更多