I have already correctly installed Lua, LuaJIT and Luarocks (I can run each of them in the terminal without any errors too). I'm trying to run the command luarocks install luaffi but it is returning an error
Error: No results matching query were found for Lua 5.4
To check if it is available for other Lua versions, use --check-lua-versions.
So I tried running luarocks install luaffi --check-lua-versions which also returns the following:
Checking if available for other Lua versions...
Checking for Lua 5.1...
Checking for Lua 5.2...
Checking for Lua 5.3...
Error: No results matching query were found for Lua 5.4.
luaffi is not available for any Lua versions. "
I'm completely lost, I cannot use ffi in my code because of this (It returns module "ffi" not found).
After the build (See: https://github.com/zhaozg/lua-ffi ) you can use Lua 5.1 to test it.
€ cat luajit_sleep.lua
--[[
Lua JIT ffi Example - Implementing a Lua sleep() function from C
]]
local ffi = require("ffi")
ffi.cdef[[void Sleep(int ms); int poll(struct pollfd *fds, unsigned long nfds, int timeout);]]
local sleep
if ffi.os == "Windows" then
function sleep(s) ffi.C.Sleep(s*1000) end
else
function sleep(s) ffi.C.poll(nil, 0, s*1000) end
end
return sleep
€ /bin/lua
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> sleep = require('luajit_sleep')
> sleep(1) -- CPU friendly sleep() function :-)
It uses (lsof | grep lua)...
/usr/local/lib/lua/5.1/ffi.so
EDIT - Found the Command to install: https://luarocks.org/modules/colesbury/luaffi
Do: luarocks install --server=https://luarocks.org/dev luaffi --verbose
Also goes to...
os.execute: chmod '0755' '/usr/local/lib/lua/5.1/ffi.so'
Results: 1
1 (number): 0
luaffi scm-1 is now installed in /usr/local (license: BSD)
Related
Using string.format() (which supposedly defers to C's sprintf())) to format a number in LuaJIT rounds differently than every other Lua interpreter I've tried:
$ lua -v
Lua 5.4.1 Copyright (C) 1994-2020 Lua.org, PUC-Rio
$ lua -e 'print(string.format("%.4f", 32.90625))'
32.9062
$ luajit -v
LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2020 Mike Pall. http://luajit.org/
$ luajit -e 'print(string.format("%.4f", 32.90625))'
32.9063
Why does this happen and how can I make it stop? I'd like to tell LuaJIT to round the same direction every other Lua interpreter does.
I'm new to luarocks and I just tried to install luarepl.
The installation apparently went fine:
$ luarocks install luarepl
Installing https://luarocks.org/luarepl-0.8-1.rockspec...
Using https://luarocks.org/luarepl-0.8-1.rockspec... switching to 'build' mode
Updating manifest for /Users/me/.luarocks/lib/luarocks/rocks-5.1
luarepl 0.8-1 is now built and installed in /Users/me/.luarocks (license: MIT/X11)
but if I try to launch the executable, it seems that the installation is broken:
$ ~/.luarocks/bin/rep.lua
/usr/local/bin/lua5.1: ...cks/lib/luarocks/rocks-5.1/luarepl/0.8-1/bin/rep.lua:23: module 'repl.console' not found:
no field package.preload['repl.console']
no file './repl/console.lua'
no file '/usr/local/share/lua/5.1/repl/console.lua'
no file '/usr/local/share/lua/5.1/repl/console/init.lua'
no file '/usr/local/lib/lua/5.1/repl/console.lua'
no file '/usr/local/lib/lua/5.1/repl/console/init.lua'
no file './repl/console.so'
no file '/usr/local/lib/lua/5.1/repl/console.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './repl.so'
no file '/usr/local/lib/lua/5.1/repl.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
...cks/lib/luarocks/rocks-5.1/luarepl/0.8-1/bin/rep.lua:23: in main chunk
[C]: ?
I look into the ~/.luarocks dir:
$ cd ~ ; find .luarocks
.luarocks
.luarocks/bin
.luarocks/bin/rep.lua
.luarocks/config.lua
.luarocks/lib
.luarocks/lib/luarocks
.luarocks/lib/luarocks/rocks-5.1
.luarocks/lib/luarocks/rocks-5.1/luarepl
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/bin
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/bin/rep.lua
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc/COPYING
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc/IDEAS.md
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc/plugins.md
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc/README.md
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc/Roadmap.md
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/luarepl-0.8-1.rockspec
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/rock_manifest
.luarocks/lib/luarocks/rocks-5.1/manifest
.luarocks/share
.luarocks/share/lua
.luarocks/share/lua/5.1
.luarocks/share/lua/5.1/repl
.luarocks/share/lua/5.1/repl/console.lua
.luarocks/share/lua/5.1/repl/init.lua
.luarocks/share/lua/5.1/repl/plugins
.luarocks/share/lua/5.1/repl/plugins/autoreturn.lua
.luarocks/share/lua/5.1/repl/plugins/completion.lua
.luarocks/share/lua/5.1/repl/plugins/example.lua
.luarocks/share/lua/5.1/repl/plugins/filename_completion.lua
.luarocks/share/lua/5.1/repl/plugins/history.lua
.luarocks/share/lua/5.1/repl/plugins/keep_last_eval.lua
.luarocks/share/lua/5.1/repl/plugins/linenoise.lua
.luarocks/share/lua/5.1/repl/plugins/pretty_print.lua
.luarocks/share/lua/5.1/repl/plugins/rcfile.lua
.luarocks/share/lua/5.1/repl/plugins/rlwrap.lua
.luarocks/share/lua/5.1/repl/plugins/semicolon_suppress_output.lua
.luarocks/share/lua/5.1/repl/sync.lua
.luarocks/share/lua/5.1/repl/utils.lua
and I can find that stuff.
I tried adding a line to config.lua to load packages from local installation to no avail:
$ cat ~/.luarocks/config.lua
local_by_default=true
(removing it has no effect)
did I miss some obvious step?
running luarocks with no arguments gives me:
CONFIGURATION
Lua version: 5.1
Configuration files:
System: /usr/local/etc/luarocks51/config-5.1.lua (ok)
User : /Users/me/.luarocks/config.lua (ok)
Rocks trees in use:
/Users/me/.luarocks ("user")
/usr/local ("system")
it seems that the user rock tree is not in the package path:
$ lua
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> print(package.path)
./?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua
why?
From https://github.com/luarocks/luarocks/wiki/Using-LuaRocks:
Most LuaRocks installations will feature two rocks trees:
"system" rock tree (used by default)
"user" rock tree
To be able to use the module, we need to make sure that Lua can find that dkjson.lua file when we run require("dkjson"). You can check your Lua paths from the Lua environment, using
print(package.path)
print(package.cpath)
These variables can be pre-configured from outside Lua, using the LUA_PATH and LUA_CPATH environment variables.
If you installed both Lua and LuaRocks in their default directories (/usr/local on Linux and Mac OSX), then the "system" tree is /usr/local and it will work by default. However, the "user" tree (for installing rocks without admin privileges) is not detected by Lua by default. For that we'll need to configure these environment variables.
LuaRocks offers a semi-automated way to do this. If you type the following command:
luarocks path --bin
it will print commands suitable for your platform for setting up your environment. On typical Unix terminal environments, you can type this:
eval $(luarocks path --bin)
and it apply the changes, temporarily, to your shell. To have these variables set permanently, you have to configure the environment variables to your shell configuration (for example, by adding the above line to your .bashrc file if your shell is Bash).
I have installed lua image according to this - link. I also tested my install with luajit -limage -e "image.test()" and it says 0 errors and 0 warnings. Also, when I try
> require 'image'
> l = image.lena()
There are no errors. However, when I try image.display(l), I get the following errors:
/home/srilatha/torch/install/share/lua/5.1/trepl/init.lua:384: module 'qt' not found:No LuaRocks module found for qt
no field package.preload['qt']
no file '/home/srilatha/.luarocks/share/lua/5.1/qt.lua'
no file '/home/srilatha/.luarocks/share/lua/5.1/qt/init.lua'
no file '/home/srilatha/torch/install/share/lua/5.1/qt.lua'
no file '/home/srilatha/torch/install/share/lua/5.1/qt/init.lua'
no file './qt.lua'
no file '/home/srilatha/torch/install/share/luajit-2.1.0-beta1/qt.lua'
no file '/usr/local/share/lua/5.1/qt.lua'
no file '/usr/local/share/lua/5.1/qt/init.lua'
no file '/home/srilatha/.luarocks/lib/lua/5.1/qt.so'
no file '/home/srilatha/torch/install/lib/lua/5.1/qt.so'
no file '/home/srilatha/torch/install/lib/qt.so'
no file './qt.so'
no file '/usr/local/lib/lua/5.1/qt.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'error'
/home/srilatha/torch/install/share/lua/5.1/trepl/init.lua:384: in function 'require'
/home/srilatha/torch/install/share/lua/5.1/image/init.lua:1363: in function 'display'
[string "_RESULT={image.display(l)}"]:1: in main chunk
[C]: in function 'xpcall'
/home/srilatha/torch/install/share/lua/5.1/trepl/init.lua:651: in function 'repl'
...atha/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:199: in main chunk
[C]: at 0x00406670
I have torch running properly so I don't know what the problem would be with qt. How can I fix this?
Did you read this by any chance?
https://github.com/torch/image/blob/master/doc/gui.md
image.display among other functions can only be accessed via the qlua Lua interpreter.
Calling that function from LuaJit will result in the errors you're facing.
Just to add to Piglet's answer - read about qlua:
https://github.com/torch/qtlua/blob/master/doc/qt.md#qlua
At first I thought: "Oh dear, I'm using luajit, in a torch installation, I have no time and motivation to install another interpreter, configure luarocks to work with it, and then install everything from scratch". Good news: I was wrong.
qlua is an interpreter, but it gets installed in your existing Lua + Torch directory.
$ luarocks install qtlua
$ luarocks install qttorch
$ which qlua
/home/me/torch/install/bin/qlua
$ qlua
Lua 5.1 Copyright (...)
> require('image')
> l = image.lena()
> image.display(l)
>
.. a window pops up, and the prompt returns immediately.
This is because qlua has a background GUI thread to display your images and react to events (closing, and resizing the window, upon which the image will be scaled - with no aspect preservation: W & H independent).
I try to load a .lc file that I compiled with luac beforehand:
print("Hello World!")
and
luac -o helloworld.lc helloworld.lua
in order to get the compilation. However, as I am importing that module I am getting:
\lua\ai\helloworld.lc too new: read version 1280.1; expected at most 80.1
This is my luac -v
E:\lua\lua-5.0.3\bin>luac -v
Lua 5.0.3 Copyright (C) 1994-2006 Tecgraf, PUC-Rio
The game I am modding is actually using Lua 5.0 which is why I don't really understand why I am seeing this error..
Has anyone tried to install opencv for python3?. As stated here http://opencv.willowgarage.com/wiki/InstallGuide its support status is unknown. So I want to try it:
I have downloaded the sources for OpenCV-2.3.1. But cmake reports.
-- Python interpreter: /Library/Frameworks/Python.framework/Versions/3.2/bin/python3 -B (ver
3.2)
-- Python numpy: NO (Python wrappers will not be generated)
I do have numpy (version 1.6.0) installed in python3 but cmake does not find it. I am using Mac OSX 10.6 Any ideas?
Update
I just saw one more thing of the cmake output that might be helpful
-- Found PythonInterp: /Library/Frameworks/Python.framework/Versions/3.2/bin/python3 (found
version "3.2")
-- Found PythonLibs: /usr/lib/libpython2.6.dylib File "", line 1
from distutils.sysconfig import *; print get_python_lib()
^
SyntaxError: invalid syntax File "", line 1
import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print
numpy.distutils.misc_util.get_numpy_include_dirs()[0]
^
SyntaxError: invalid syntax File "", line 1
import sphinx; print sphinx.__version__
^ SyntaxError: invalid syntax
Notice that it found 3.2 but then libpython2.6 ??
Any ideas?
At the moment OpenCV supports Python 2.x only. OpenCV (including OpenCV 2.4) does not compiles with Python 3.x.
Python3 support is already in wishlist for future versions of OpenCV. But currently there are no activities in this direction and you are welcome to create and contribute a patch resolving the compatibility issues.
Use the pip application.
On ubuntu:
sudo apt install python3-pip
and so, on command line:
pip3 install --upgrade pip
pip3 install opencv-python
I got the thing to at least build and install. It can load the cv2 module just fine. Haven't tested too much though.
Details:
https://stackoverflow.com/a/21212023/3075814