Skip to content

Cannot run python in lua with python 2.7.13 #56

Open

Description

@ingojahn

I am having a similar issue. I am working on MacOsX with python 2.7.13 and Lua 5.2.
I am trying to call python from within lua.

If I try
py = require 'python'
I get the error:
no field package.preload['python']
no file '/Users/name/dgdinst/lib/python.lua'
no file '/Users/name/dgdinst/lib/python.so'

Similarly when I try
py = require 'lua-python'
I get the error message:
dlopen(/Users/TOM/name/lib/lua-python.so, 2): Symbol not found: _PyCFunction_Type
Referenced from: /Users/name/dgdinst/lib/lua-python.so
Expected in: flat namespace
in /Users/name/dgdinst/lib/lua-python.so

Any suggestions?
Thanks

Activity

  1. greatwolf commented on May 7, 2017

    @greatwolf
    Collaborator

    Where did you put the compiled python.so lua module?

  2. ingojahn commented on May 7, 2017

    @ingojahn
    Author

    Good question.
    No idea. Do you mean the python.lua file that is included in the lunatic-python (v1.0) repository?
    This python.lua file is called by > require 'python' and has suitable syntax to load the lua-python.so library.

    I have been able to do some more digging, and I believe the issue is caused by differences between RTLD_NOW and RTLD_GLOBAL. See comment Gustavo Niemeyers comment

    It's just a matter of replacing the flag RTLD_NOW in the loadlib.c file of the Lua distribution by the or'ed version RTLD_NOW|RTLD_GLOBAL.

    However this proofing difficult. If I get lua from homebrew, it comes pre-compiled and I can't modify loadlib.c. If I install lua from source I don't seem to get the correct lua dynanic libraries liblua.5.2.dylib

    Has anyone else succeeded with lunatic-python on a mac?

  3. greatwolf commented on May 7, 2017

    @greatwolf
    Collaborator

    No, python.lua has been removed a long time ago. The lua-python.so binary has been renamed to python.so and lua.so for loading into lua and python vm respectively.

    Can you show the output of the CMake build? If building with CMake->gnu make, you can add VERBOSE=1 to the make command to see the full invocation.

  4. ingojahn commented on May 7, 2017

    @ingojahn
    Author

    In that case I am very confused. I have downloaded a copy of the repository zip and it correctly builds the two file lua-python.so and lua.so.

    At no stage is it building a python.sp

    Here is the code
    $ gmake VERBOSE=1
    python setup.py build
    running build
    running build_ext
    building 'lua-python' extension
    creating build
    creating build/temp.macosx-10.12-x86_64-2.7
    creating build/temp.macosx-10.12-x86_64-2.7/src
    clang -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/pythoninlua.c -o build/temp.macosx-10.12-x86_64-2.7/src/pythoninlua.o -I/usr/include/lua5.2
    clang -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/luainpython.c -o build/temp.macosx-10.12-x86_64-2.7/src/luainpython.o -I/usr/include/lua5.2
    creating build/lib.macosx-10.12-x86_64-2.7
    clang -bundle -undefined dynamic_lookup build/temp.macosx-10.12-x86_64-2.7/src/pythoninlua.o build/temp.macosx-10.12-x86_64-2.7/src/luainpython.o -L/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib -L/usr/local/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/sqlite/lib -lpython2.7 -o build/lib.macosx-10.12-x86_64-2.7/lua-python.so
    building 'lua' extension
    clang -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/pythoninlua.c -o build/temp.macosx-10.12-x86_64-2.7/src/pythoninlua.o -I/usr/include/lua5.2
    clang -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/luainpython.c -o build/temp.macosx-10.12-x86_64-2.7/src/luainpython.o -I/usr/include/lua5.2
    clang -bundle -undefined dynamic_lookup build/temp.macosx-10.12-x86_64-2.7/src/pythoninlua.o build/temp.macosx-10.12-x86_64-2.7/src/luainpython.o -L/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib -L/usr/local/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/sqlite/lib -lpython2.7 -o build/lib.macosx-10.12-x86_64-2.7/lua.so

    $gmake VERBOSE=1 install
    python setup.py install
    --root=/
    --prefix=/usr/local
    --install-scripts=/usr/local/bin
    running install
    running build
    running build_ext
    running install_lib
    copying build/lib.macosx-10.12-x86_64-2.7/lua-python.so -> /usr/local/lib/python2.7/site-packages
    copying build/lib.macosx-10.12-x86_64-2.7/lua.so -> /usr/local/lib/python2.7/site-packages
    running install_egg_info
    Writing /usr/local/lib/python2.7/site-packages/lunatic_python-1.0-py2.7.egg-info

  5. greatwolf commented on May 8, 2017

    @greatwolf
    Collaborator

    Can you run ldd on lua-python.so followed with which on the lua and python runtime libraries to get their locations.

  6. ingojahn commented on May 8, 2017

    @ingojahn
    Author

    For macosx the command isotool -L lua-python.so

    The output is:
    lua-python.so:
    /usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.51.1)

    which lua
    /usr/local/bin/lua

    which python
    /usr/local/bin/python

  7. greatwolf commented on May 8, 2017

    @greatwolf
    Collaborator

    The second error message, it could be related to this maybe http://stackoverflow.com/questions/35006614/what-does-symbol-not-found-expected-in-flat-namespace-actually-mean.

    I don't have an Mac OSX to test this on so not sure how much help I can provide.

  8. aisurfer commented on Jul 19, 2017

    @aisurfer

    Hey! I have the same issue.
    Firstly i've got repo copy and ran 'sudo make install' (using Ubuntu 14)
    Next ran make
    $ make VERBOSE=1 python setup.py build running build running build_ext building 'lua-python' extension creating build/temp.linux-x86_64-2.7 creating build/temp.linux-x86_64-2.7/src x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/lua5.2 -I/usr/include/python2.7 -c src/pythoninlua.c -o build/temp.linux-x86_64-2.7/src/pythoninlua.o -I/usr/include/lua5.2 x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/lua5.2 -I/usr/include/python2.7 -c src/luainpython.c -o build/temp.linux-x86_64-2.7/src/luainpython.o -I/usr/include/lua5.2 creating build/lib.linux-x86_64-2.7 x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/src/pythoninlua.o build/temp.linux-x86_64-2.7/src/luainpython.o -llua5.2 -o build/lib.linux-x86_64-2.7/lua-python.so building 'lua' extension x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/lua5.2 -I/usr/include/python2.7 -c src/pythoninlua.c -o build/temp.linux-x86_64-2.7/src/pythoninlua.o -I/usr/include/lua5.2 x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/lua5.2 -I/usr/include/python2.7 -c src/luainpython.c -o build/temp.linux-x86_64-2.7/src/luainpython.o -I/usr/include/lua5.2 x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/src/pythoninlua.o build/temp.linux-x86_64-2.7/src/luainpython.o -llua5.2 -o build/lib.linux-x86_64-2.7/lua.so Press any key to continue...
    Next install
    $ sudo make install python setup.py install \ --root=/ \ --prefix=/usr \ --install-scripts=/usr/bin running install running build running build_ext running install_lib copying build/lib.linux-x86_64-2.7/lua-python.so -> /usr/lib/python2.7/site-packages copying build/lib.linux-x86_64-2.7/lua.so -> /usr/lib/python2.7/site-packages running install_egg_info Removing /usr/lib/python2.7/site-packages/lunatic_python-1.0-py2.7.egg-info Writing /usr/lib/python2.7/site-packages/lunatic_python-1.0-py2.7.egg-info Press any key to continue...

    Next I go to test and get the error
    /tests$ lua test_py.lua lua: test_py.lua:1: module 'python' not found: no field package.preload['python'] no file '/usr/local/share/lua/5.2/python.lua' no file '/usr/local/share/lua/5.2/python/init.lua' no file '/usr/local/lib/lua/5.2/python.lua' no file '/usr/local/lib/lua/5.2/python/init.lua' no file '/usr/share/lua/5.2/python.lua' no file '/usr/share/lua/5.2/python/init.lua' no file './python.lua' no file '/usr/local/lib/lua/5.2/python.so' no file '/usr/lib/x86_64-linux-gnu/lua/5.2/python.so' no file '/usr/lib/lua/5.2/python.so' no file '/usr/local/lib/lua/5.2/loadall.so' no file './python.so' stack traceback: [C]: in function 'require' test_py.lua:1: in main chunk [C]: in ? Press any key to continue...

    Well, set LUA_CPATH as I see libs copied to site-packages
    export LUA_CPATH="/usr/lib/python2.7/site-packages/?.so;;"
    also change 'python' -> 'lua-python'
    $ lua test_py.lua lua: error loading module 'lua-python' from file '/usr/lib/python2.7/site-packages/lua-python.so': /usr/lib/python2.7/site-packages/lua-python.so: undefined symbol: _Py_ZeroStruct stack traceback: [C]: in ? [C]: in function 'require' test_py.lua:1: in main chunk [C]: in ? Press any key to continue...

    Weee new issue:) What does it mean? Is "lua-python.so" the right lib to use in lua scripts? Why it is installed in python2.7/site-packages ?
    What should I do to fix?

    Thanks in advance!

  9. cross10 commented on Jan 1, 2020

    @cross10

    将编译好的lua-python.so改名成python.so,放到/usr/lib64/lua/5.1/python.so即可

  10. bastibe commented on Jan 6, 2020

    @bastibe
    Owner

    @cross10 could you repeat that in English?

  11. cross10 commented on Jan 12, 2020

    @cross10

    @cross10 could you repeat that in English?

    Change the compiled lua-python.so to python.so, and put it in /usr/lib64/lua/5.1/python.so
    If u used was centos7.4 ,and lua's version is 5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions