简体   繁体   English

使用npm安装watson-developer-cloud时出错

[英]Error when using npm to install watson-developer-cloud

I'm following the 'Watson Quickstart for Node.js' found here , but I'm having trouble installing the Watson Developer Cloud Node.js wrapper package using the npm command they provide. 我正在遵循此处找到的“适用于Node.js的Watson快速入门”,但是使用它们提供的npm命令安装Watson Developer Cloud Node.js包装程序包时遇到了麻烦。

Here's the output: cmd output after npm command 输出为: npm命令后的cmd输出

Afterwards, no files appear in the directory in which the command was run. 之后,在运行命令的目录中没有文件出现。 Does anyone have any advice on how to install the Watson Developer Cloud wrapper to begin developing Watson apps with Node.js through Bluemix? 是否有人对如何安装Watson Developer Cloud包装器有任何建议,以开始通过Bluemix使用Node.js开发Watson应用程序?

Peter, 彼得,

The version of the page you're referring to was rewritten entirely more than three months ago. 您所指向的页面版本已在三个多月前完全重写。 The rewrite should address the issues you've encountered. 重写应解决您遇到的问题。 It appears to be available at the same URL: 它似乎可以在同一URL上使用:

http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/getting_started/gs-quick-nodejs.shtml http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/getting_started/gs-quick-nodejs.shtml

I'm not sure why you're seeing such an old version of that page. 我不确定为什么会看到该页面的旧版本。 Perhaps it's a stale version from your cache? 也许这是您缓存中的旧版本? Please try refreshing the page and see whether that helps. 请尝试刷新页面,看看是否有帮助。

Ok, so there are a host of problems with the documentation page. 好的,因此文档页面存在很多问题。 I list them below along with the solutions. 我在下面列出了它们以及解决方案。 I was able to get the example working after working around the below shortcomings. 解决以下缺点后,我就能使示例工作。

  • Machine Translation service does not exist - In the new scheme of things the Machine Translation service is now Language translation service. 机器翻译服务不存在 -在新的方案中,机器翻译服务现在是语言翻译服务。
  • Service credentials are for an incorrect version of the API - The service credential object that you obtained are for the v2 version of the API and not v1 as mentioned within the example source code. 服务凭据用于API的错误版本 -您获得的服务凭据对象用于API的v2版本,而不是示例源代码中提到的v1。
  • The source code in the example uses completely outdated request parameters - Refer to the updated source code below. 示例中的源代码使用了完全过时的请求参数 -请参阅下面的更新后的源代码。

    var watson = require('watson-developer-cloud'); var watson = require('watson-developer-cloud');

     var machine_translation = watson.language_translation({ username: 'user_name', password: 'password', version: 'v2' }); //the attributes from and to in the example provided are actually replaced by source and target machine_translation.translate({ text: 'A sentence must have a verb', source : 'enus', target: 'eses' }, function (err, response) { if (err) console.log('error:', err); else console.log(JSON.stringify(response, null, 2)); }); 

Hopefully this solves your problem. 希望这可以解决您的问题。 Of course, the code shown in the example is only a starter code - in case you want to develop a sophisticated application then you would need to introduce other dependencies such as expressjs, jade etc and then implement these explicitly. 当然,示例中显示的代码只是入门代码-如果您要开发复杂的应用程序,则需要引入其他依赖项,例如expressjs,jade等,然后显式实现这些依赖项。

In case you want to refer to the Github repository example for this service visit this link. 如果您想参考此服务的Github存储库示例,请访问链接。

Peter, 彼得,

The npm command should have created a nodes_module in that directory that contains the Watson wrapper APIs. npm命令应该在包含Watson包装器API的目录中创建了一个nodes_module。 You still need to write a main Node.js file to call the API. 您仍然需要编写一个主要的Node.js文件来调用API。 The example below is a Node.js file that uses the Language Translation Watson service: 下面的示例是使用Language Translation Watson服务的Node.js文件:

var express = require('express');
var app = express();

app.get('/', function (req, res) {
  res.send('Hello World!');
});

var watson = require('watson-developer-cloud');

var language_translation = watson.language_translation({
  username: '<username>',
  password: '<password>',
  version: 'v2'
});

language_translation.translate({
  text: 'A sentence must have a verb', source : 'en', target: 'es' },
  function (err, translation) {
    if (err)
      console.log('error:', err);
    else
      console.log(JSON.stringify(translation, null, 2));
});

language_translation.identify({
  text: 'The language translation service takes text input and identifies the language used.' },
  function (err, language) {
    if (err)
      console.log('error:', err);
    else
      console.log(JSON.stringify(language, null, 2));
});


var server = app.listen(3000, function () {
  var host = server.address().address;
  var port = server.address().port;

  console.log('Example app listening at http://%s:%s', host, port);
});

It requires express, so you have to first install express and run the Node.js application (assuming you save the file above as app.js, also you need to enter the Watson service username and password as explained in the article you are following): 它需要Express,因此您必须首先安装Express并运行Node.js应用程序(假设您将上面的文件另存为app.js,还需要按照以下文章中的说明输入Watson服务的用户名和密码) :

npm install express
node app.js 

The output is similar to this: 输出类似于以下内容:

Example app listening at http://:::3000
{
  "translations": [
    {
      "translation": "Una sentencia debe tener un verbo"
    }
  ],
  "word_count": 6,
  "character_count": 27
}
{
  "languages": [
    {
      "language": "en",
      "confidence": 0.913647
    },
    {
      "language": "id",
      "confidence": 0.0323458
    },
    {
      "language": "sv",
      "confidence": 0.0156442
    },
    {
      "language": "fi",
      "confidence": 0.011028
    },
    {
      "language": "is",
      "confidence": 0.00709899
    },
    {
      "language": "nn",
      "confidence": 0.00553699
    },
    {
      "language": "ht",
      "confidence": 0.00408621
    },
    {
      "language": "et",
      "confidence": 0.00119016
    },
    {
      "language": "lv",
      "confidence": 0.00115617
    },
    {
      "language": "de",
      "confidence": 0.00114441
    },
    {
      "language": "tr",
      "confidence": 0.00111117
    },
    {
      "language": "ro",
      "confidence": 0.000802137
    },
    {
      "language": "lt",
      "confidence": 0.000801177
    },
    {
      "language": "cs",
      "confidence": 0.000613459
    },
    {
      "language": "sq",
      "confidence": 0.000474419
    },
    {
      "language": "ku",
      "confidence": 0.000468358
    },
    {
      "language": "bs",
      "confidence": 0.000452145
    },
    {
      "language": "sk",
      "confidence": 0.000396557
    },
    {
      "language": "nb",
      "confidence": 0.000324082
    },
    {
      "language": "hu",
      "confidence": 0.000292984
    },
    {
      "language": "fr",
      "confidence": 0.000289142
    },
    {
      "language": "da",
      "confidence": 0.000274609
    },
    {
      "language": "eo",
      "confidence": 0.000194707
    },
    {
      "language": "eu",
      "confidence": 0.000167031
    },
    {
      "language": "vi",
      "confidence": 0.000147763
    },
    {
      "language": "az",
      "confidence": 0.000121994
    },
    {
      "language": "af",
      "confidence": 0.000111069
    },
    {
      "language": "nl",
      "confidence": 0.0000278278
    },
    {
      "language": "pl",
      "confidence": 0.0000243381
    },
    {
      "language": "pt",
      "confidence": 0.0000127483
    },
    {
      "language": "es",
      "confidence": 0.0000112067
    },
    {
      "language": "ja",
      "confidence": 0.0000018683
    },
    {
      "language": "it",
      "confidence": 5.87651e-7
    },
    {
      "language": "ko",
      "confidence": 4.27166e-7
    },
    {
      "language": "zh",
      "confidence": 1.33964e-7
    },
    {
      "language": "zh-TW",
      "confidence": 6.36584e-8
    },
    {
      "language": "el",
      "confidence": 3.10395e-8
    },
    {
      "language": "hi",
      "confidence": 1.61209e-8
    },
    {
      "language": "ur",
      "confidence": 3.72468e-9
    },
    {
      "language": "mn",
      "confidence": 3.26788e-9
    },
    {
      "language": "ru",
      "confidence": 2.58127e-9
    },
    {
      "language": "he",
      "confidence": 1.91823e-9
    },
    {
      "language": "km",
      "confidence": 1.60638e-9
    },
    {
      "language": "ar",
      "confidence": 1.18306e-9
    },
    {
      "language": "pa",
      "confidence": 1.16591e-9
    },
    {
      "language": "bn",
      "confidence": 9.64752e-10
    },
    {
      "language": "so",
      "confidence": 9.41827e-10
    },
    {
      "language": "ka",
      "confidence": 7.88174e-10
    },
    {
      "language": "uk",
      "confidence": 5.64222e-10
    },
    {
      "language": "ps",
      "confidence": 3.55452e-10
    },
    {
      "language": "ky",
      "confidence": 3.32569e-10
    },
    {
      "language": "fa",
      "confidence": 2.74777e-10
    },
    {
      "language": "ta",
      "confidence": 2.7293e-10
    },
    {
      "language": "be",
      "confidence": 2.71734e-10
    },
    {
      "language": "bg",
      "confidence": 2.33392e-10
    },
    {
      "language": "te",
      "confidence": 2.0307e-10
    },
    {
      "language": "ml",
      "confidence": 1.92155e-10
    },
    {
      "language": "kk",
      "confidence": 1.67796e-10
    },
    {
      "language": "hy",
      "confidence": 1.42515e-10
    },
    {
      "language": "gu",
      "confidence": 1.21276e-10
    },
    {
      "language": "ba",
      "confidence": 6.74764e-11
    },
    {
      "language": "cv",
      "confidence": 4.22054e-11
    }
  ]
}

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

相关问题 直接在客户端上使用watson-developer-cloud节点SDK? - Using the watson-developer-cloud node SDK directly on the client? 使用watson-developer-cloud模块的Bluemix Node.js Watson关系提取 - Bluemix Node.js Watson Relationship Extraction using watson-developer-cloud module 使用Node.js(watson-developer-cloud模块)发送AlchemyData新闻查询 - Sending an AlchemyData News query using Node.js (watson-developer-cloud module) Bluemix + Node.js-是否有watson-developer-cloud模块的文档? - Bluemix + Node.js - Is there documentation for the watson-developer-cloud module? 使用Watson-Developer-Cloud Node.js SDK删除多个意图 - Deleting multiple intents with watson-developer-cloud nodejs sdk ibm的watson-developer-cloud Node.js sdk的Discovery模块中的updateDocument api坚持一个file参数 - The updateDocument api in the Discovery module of ibm's watson-developer-cloud Node.js sdk insists on a file parameter 我需要帮助来确定watson-developer-cloud Node.js函数的正确语法,以将文档插入Watson的Discovery服务 - I need help figuring out the correct syntax for the watson-developer-cloud Node.js function to insert a document into Watson's Discovery service Watson开发人员云API - Watson Developer Cloud API 使用 npm 安装包时出错 - Getting an error when using npm to install a package 使用 npm install 安装 glup 时出错 - Error when installing glup using npm install
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM