简体   繁体   English

如何在Windows上安装节点js canvas

[英]how to install node js canvas on windows

I'm trying to get working canvas on node js. 我正在尝试在节点js上使用canvas。 I'm using Windows Vista. 我正在使用Windows Vista。 After basic approach npm install canvas failed (see error below), I have looked up some tutorials, here is what I have tried: 在基本方法npm install canvas失败后(见下面的错误),我查了一些教程,这是我尝试过的:

sources: 来源:
installing-node-canvas-for-windows 安装节点帆布换窗户
LearnBoost/node-canvas/wiki/Installation---Windows LearnBoost /节点帆布/维基/安装的Windows ---

log in console (after running npm install canvas in cmd): 登录控制台(在cmd中运行npm install canvas之后):
log contains several warnings, I don't thing these are the problem - it is mostly something like 'conversion from double to float', and one error marked in red color: log包含几个警告,我不是这些问题 - 它主要是'从double转换为float',以及一个标记为红色的错误:

init.cc
d:\pathToApp\node_modules\canvas\src\PNG.h(5): fatal error C1083: Cannot
open include file: 'cairo.h': No such file or directory [d:\pathToApp\n
ode_modules\canvas\build\canvas.vcxproj]

And at the very end of log there is: 在日志的最后有:

gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\
npm\node_modules\node-gyp\lib\build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:
12)
gyp ERR! System Windows_NT 6.0.6002
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modu
les\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd d:\pathToApp\node_modules\canvas
gyp ERR! node -v v0.10.16
gyp ERR! node-gyp -v v0.10.9
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0

After that, nothing appeared in node-module folder (no canvas subdirectory, npm after unsuccessful installation removed the subdirectory). 之后,node-module文件夹中没有出现任何内容(没有canvas子目录,安装失败后npm删除了子目录)。

So I have also tried to download canvas module manually from github, unzip it in node-modules and then run node-gyp configure in node-modules/canvas with success, and node-gyp build , which unfortunatelly gave me the same error Cannot open include file: 'cairo.h' . 所以我也尝试从github手动下载canvas模块,在node-modules中解压缩然后在node-modules / canvas中运行node-gyp configure成功,以及node-gyp build ,这不幸地给了我同样的错误Cannot open include file: 'cairo.h'

I have read everything that I found on this carefully. 我仔细阅读了我在此发现的所有内容。 If you can suggest any help, please do it. 如果您能提出任何帮助,请执行此操作。

I have managed to get it working on my new Windows 8 machine, so I want to share some details that can be helpful to others. 我已经设法让它在我的新Windows 8机器上工作,所以我想分享一些对其他人有帮助的细节。

I am using: 我在用:

Procedure 程序

Be sure to have Python 2 and GTK\\bin in your path. 确保路径中包含Python 2GTK \\ bin

I have downloaded files manualy from https://github.com/Automattic/node-canvas and saved it to node_modules/canvas . 我已经从https://github.com/Automattic/node-canvas 手动下载了文件并将其保存到node_modules / canvas

Then I run node-gyp configure build in canvas directory. 然后我在canvas目录中运行node-gyp configure build Errors occured. 发生错误。 I had to edit binding.gyp ( https://github.com/Automattic/node-canvas/blob/master/binding.gyp ) in order to match actual files in GTK folder. 我必须编辑binding.gyphttps://github.com/Automattic/node-canvas/blob/master/binding.gyp )以匹配GTK文件夹中的实际文件。

For example: 例如:

  • line 59: "(GTK_Root)/lib/libpng.lib" -> "(GTK_Root)/lib/libpng.dll.a" 第59行:“(GTK_Root)/lib/libpng.lib” - >“(GTK_Root)/lib/libpng.dll.a”
  • line 34: "(GTK_Root)/bin/libpng14-14.dll" -> "(GTK_Root)/bin/libpng15-15.dll" 第34行:“(GTK_Root)/bin/libpng14-14.dll” - >“(GTK_Root)/bin/libpng15-15.dll”
  • ... ...

There can be more, you should be able to read which files are making problems from error log and then edit the names to match files in GTK folder. 可以有更多,您应该能够从错误日志中读取哪些文件出现问题,然后编辑名称以匹配GTK文件夹中的文件。

After editing binding.gyp, command node-gyp configure build finished successfuly. 在编辑binding.gyp之后,命令node-gyp configure build成功完成。 Although I am not able to work with some jpg files in Canvas (I have not tested it properly), png files work fine. 虽然我无法在Canvas中使用一些jpg文件(我还没有正确测试),但png文件工作正常。

If node-gyp fails 如果node-gyp失败

It can happen to you, that every node-gyp command fails with message (possibly marked in red) similar to: 你可能会发现,每个node-gyp命令都会失败并显示消息(可能标记为红色),类似于:

"...bcrypt_lib.vcxproj(47,46): error MSB4025: Could not load file project. An invalid character for the specified encoding., Line 47, position 46." “... bcrypt_lib.vcxproj(47,46):错误MSB4025:无法加载文件项目。指定编码的无效字符。第47行,第46位。”

It it most probably because you have special character in the name of your user folder. 这很可能是因为您的用户文件夹名称中包含特殊字符。 (The fact, that Windows 8 automatically creates the name of your user folder from your first name is the lamest thing about Win 8). (事实上​​,Windows 8自动从您的名字创建用户文件夹的名称是关于Win 8的最糟糕的事情)。

2 quick solutions: 2快速解决方案:

Hope this helps. 希望这可以帮助。

I managed to get this working on windows after a long arduous process. 经过漫长的艰苦过程,我设法在windows上工作。 I have a last couple of suggestions that you might try that I had on my list. 我有最后几条建议,你可能会尝试我在我的清单上。

Copy all the dll files from c:\\GTK to the canvas\\build\\Release folder. 将所有dll文件从c:\\ GTK复制到canvas \\ build \\ Release文件夹。

Copy IEShims.dll from c:\\program files(x86)\\Internet Explorer to the canvas\\build\\Release folder. 将IEShims.dll从c:\\ program files(x86)\\ Internet Explorer复制到canvas \\ build \\ Release文件夹。

Then run node-gyp build. 然后运行node-gyp build。

Best of luck. 祝你好运。

I ran into trouble with canvas while trying to install paperjs . 在尝试安装paperjs时,我遇到了问题。

Here's what worked for me. 这对我有用。

My specifics 我的具体细节

GTK GTK

Make sure you read the README. 请务必阅读自述文件。 There are necessary instructions here that I overlooked the first time around. 这里有必要的说明我第一次忽略了。 For instance: 例如:

Run: pkg-config --cflags gtk+-2.0 运行: pkg-config --cflags gtk+-2.0

Run: gtk-demo and verify that it works 运行: gtk-demo并验证它是否有效

Running pkg-config let me know that I needed to have <GTK Directory>\\lib\\pkgconfig in the PKG_CONFIG_PATH environment variable. 运行pkg-config让我知道我需要在PKG_CONFIG_PATH环境变量中有<GTK Directory>\\lib\\pkgconfig

canvas 帆布

I used this as a guide: https://github.com/LearnBoost/node-canvas/wiki/Installation---Windows 我用这个作为指南: https//github.com/LearnBoost/node-canvas/wiki/Installation---Windows

NOTE: I have Visual Studio 2010, 2012 and 2013 installed on my machine, so I didn't have to deal with MSVC dependencies. 注意:我的计算机上安装了Visual Studio 2010,2012和2013,因此我不必处理MSVC依赖项。

npm install canvas was always failing - and cleaning up after itself (the jerk) - so I grabbed the cached version from the npm-cache: %USERPROFILE%\\AppData\\Roaming\\npm-cache\\canvas\\1.1.3\\package . npm install canvas总是失败 - 并且自行清理(混蛋) - 所以我从npm-cache抓取了缓存版本: %USERPROFILE%\\AppData\\Roaming\\npm-cache\\canvas\\1.1.3\\package Copy this directory to your project's node_modules directory and rename it canvas . 将此目录复制到项目的node_modules目录并将其重命名为canvas Enter the newly created canvas directory on the command line. 在命令行中输入新创建的canvas目录。

Run npm install nan . 运行npm install nan

Before you you can run node-gyp configure successfully, you need to verify your GTK path in binding.gyp 在您成功运行node-gyp configure ,您需要在binding.gyp验证您的GTK路径

On line 5: 第5行:

'GTK_Root%': 'C:/GTK', # Set the location of GTK all-in-one bundle 'GTK_Root%':'C:/ GTK',#设置GTK一体化捆绑包的位置

Now you can try node-gyp configure . 现在您可以尝试node-gyp configure If this is successful, awesome! 如果这是成功的,真棒! Now you can build it: node-gyp build . 现在你可以构建它: node-gyp build

That should do it. 应该这样做。 If you were trying to install paper, now you can. 如果您正在尝试安装纸张,现在就可以。 Hooray! 万岁!

If this doesn't work, or you have something to add, don't be shy! 如果这不起作用,或者你有东西需要添加,不要害羞! Please comment so we can all benefit. 请评论,以便我们都能受益。

您将需要捆绑在GTK中的cairo库

Here is the most up-to-date information I've found on how to install the components required to run node-gyp which is in turn required to compile the code for canvas (and jsdom). 这是我发现的关于如何安装运行node-gyp所需的组件的最新信息 ,而这些组件又需要编译canvas(和jsdom)的代码。 I'm going to replicate it here in case the link dies. 我将在这里复制它以防链接死亡。 I have tested these instructions on my Win7 x64 machine and it worked first time. 我已经在Win7 x64机器上测试了这些说明,并且它第一次运行。


On Windows XP/Vista/7, node-gyp requires Python 2.7 and Visual Studio 2010 在Windows XP / Vista / 7上, node-gyp需要Python 2.7和Visual Studio 2010

According to the readme file in Microsoft Visual C++ 2010 Service Pack 1 Compiler Update for the Windows SDK 7.1 , to ensure that your system has a supported configuration, uninstall the following products and then reinstall them in the order listed : 根据Windows SDK 7.1的Microsoft Visual C ++ 2010 Service Pack 1编译器更新中的自述文件, 要确保您的系统具有受支持的配置,请卸载以下产品,然后按所列顺序重新安装

  1. Visual Studio 2010 Visual Studio 2010
  2. Windows SDK 7.1 Note: If you get error on installation, maybe this link will help you. Windows SDK 7.1注意:如果您在安装时遇到错误,也许此链接可以帮助您。
  3. Visual Studio 2010 SP1 Visual Studio 2010 SP1
  4. Visual C++ 2010 SP1 Compiler Update for the Windows SDK 7.1 Windows SDK 7.1的Visual C ++ 2010 SP1编译器更新

On x64 environments, the last update in the list fixes errors about missing compilers and error MSB4019: The imported project "C:\\Microsoft.Cpp.Default.props" was not found. 在x64环境中,列表中的最后一次更新修复了有关缺少编译器的error MSB4019: The imported project "C:\\Microsoft.Cpp.Default.props" was not found.error MSB4019: The imported project "C:\\Microsoft.Cpp.Default.props" was not found.

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

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