LuaJit找不到通过“ luarocks”安装的库“ lua-vips”

时间:2019-06-23 08:15:59

标签: lua luajit luarocks

我有这个lua文件:

-- test1.lua 


--require "luarocks.loader"
vips = require "vips"
--vips = require "lua-vips"



local img = vips.Image.new_from_file("img1.jpg")
-- [...................]

找不到通过“ luarocks”安装的库“ lua-vips”:

$ luajit test1.lua 
luajit: error loading module 'vips' from file '/usr/local/lib/luarocks/rocks-5.3/':
  cannot read /usr/local/lib/luarocks/rocks-5.3/: Is a directory
stack traceback:
  [C]: at 0x0102caa660
  [C]: in function 'require'
  test1.lua:2: in main chunk
  [C]: at 0x0102c3b8a0

即使我添加了

export LUA_PATH="/usr/local/lib/luarocks/rocks-5.3/"

~/.profile,不会。

目录luarocks-lua-vips的内容存在:

  ls /usr/local/lib/luarocks/rocks-5.3/

  lua-vips  manifest

如何解决此问题?

$ luarocks path
export LUA_PATH='/Users/my_user/.luarocks/share/lua/5.3/?.lua;/Users/my_user/.luarocks/share/lua/5.3/?/init.lua;/usr/local/share/lua/5.3/?.lua;/usr/local/share/lua/5.3/?/init.lua;/usr/local/Cellar/luarocks/3.0.1/share/lua/5.3/?.lua;/usr/local/lib/lua/5.3/?.lua;/usr/local/lib/lua/5.3/?/init.lua;./?.lua;./?/init.lua'
export LUA_CPATH='/Users/my_user/.luarocks/lib/lua/5.3/?.so;/usr/local/lib/lua/5.3/?.so;/usr/local/lib/lua/5.3/loadall.so;./?.so'
export PATH='/Users/my_user/.luarocks/bin:/usr/local/bin:/Users/my_user/.yarn/bin:/Users/my_user/.config/yarn/global/node_modules/.bin:/Users/my_user/.nix-profile/bin:/Users/my_user/.nvm/versions/node/v8.14.0/bin:/Users/my_user/.cargo/bin:/Users/my_user/.gem/ruby/2.5.1/bin:/Users/my_user/.rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/bin:/Users/my_user/.rubies/ruby-2.5.1/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/my_user/go/bin'

1 个答案:

答案 0 :(得分:0)

您的问题是LUA_PATH与PATH通常无法正常工作。

您没有给它提供目录,而是给它提供了一个模板字符串,其中带有?表示要加载的库的名称。

例如,如果要在/path/to/libs/目录中查找文件,则将"/path/to/libs/?.lua;/path/to/libs/?/init.lua"写入路径。

如果从字面上添加"/usr/local/lib/luarocks/rocks-5.3/",Lua会尝试将该目录作为Lua文件加载,这会导致您的错误。

删除该环境变量,并告诉我们您遇到什么错误。

还请记住,向.profile添加内容需要注销并重新登录,以使更改生效(或在您打开的每个新Shell中使source ~/.profile生效)