Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3.6 compatibility #6

Closed
5up3rD4n1 opened this issue Dec 21, 2017 · 6 comments
Closed

Python3.6 compatibility #6

5up3rD4n1 opened this issue Dec 21, 2017 · 6 comments

Comments

@5up3rD4n1
Copy link

Hi Baiter, I'm trying to import chdkptp with python 3.6 (I know it is not supported yet) but maybe you can help me out wit this.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sd/.pyenv/versions/3.6.0/lib/python3.6/site-packages/chdkptp/__init__.py", line 1, in <module>
    from chdkptp.device import ChdkDevice, list_devices, DeviceInfo
  File "/home/sd/.pyenv/versions/3.6.0/lib/python3.6/site-packages/chdkptp/device.py", line 3, in <module>
    import StringIO
ModuleNotFoundError: No module named 'StringIO'

So, StringIO is deprecated on Python3.6 so I try to 'hack' the system modules with

>>> import sys, io
>>> sys.modules['StringIO'] = io

and I'm getting now the following Traceback when I import chdkptp

>>> import sys, io
>>> sys.modules['StringIO'] = io
>>> import chdkptp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sd/.pyenv/versions/3.6.0/lib/python3.6/site-packages/chdkptp/__init__.py", line 1, in <module>
    from chdkptp.device import ChdkDevice, list_devices, DeviceInfo
  File "/home/sd/.pyenv/versions/3.6.0/lib/python3.6/site-packages/chdkptp/device.py", line 8, in <module>
    from chdkptp.lua import LuaContext, global_lua, parse_table
  File "/home/sd/.pyenv/versions/3.6.0/lib/python3.6/site-packages/chdkptp/lua.py", line 141, in <module>
    global_lua = LuaContext()
  File "/home/sd/.pyenv/versions/3.6.0/lib/python3.6/site-packages/chdkptp/lua.py", line 92, in __init__
    self._setup_runtime()
  File "/home/sd/.pyenv/versions/3.6.0/lib/python3.6/site-packages/chdkptp/lua.py", line 100, in _setup_runtime
    """)
  File "lupa/_lupa.pyx", line 262, in lupa._lupa.LuaRuntime.execute
  File "lupa/_lupa.pyx", line 1279, in lupa._lupa.run_lua
  File "lupa/_lupa.pyx", line 1288, in lupa._lupa.call_lua
  File "lupa/_lupa.pyx", line 1314, in lupa._lupa.execute_lua_call
  File "lupa/_lupa.pyx", line 1250, in lupa._lupa.raise_lua_error
lupa._lupa.LuaError: [string "<python>"]:3: attempt to concatenate global 'CHDKPTP_PATH' (a userdata value)
stack traceback:
	[string "<python>"]:3: in main chunk

Do you have an idea how can I solve this?

@5up3rD4n1
Copy link
Author

I found that the encode=None at the lua runtime was the cause of the issue, but now I can't install the package.

lupa._lupa.LuaError: [string "<python>"]:2: module 'chdkptp' not found:
	no field package.preload['chdkptp']
	no file '/home/sd/Documents/HACKPLACE/chdkptp.py/chdkptp/vendor/chdkptp/lua/chdkptp.lua'
	no file '/usr/local/share/lua/5.2/chdkptp.lua'
	no file '/usr/local/share/lua/5.2/chdkptp/init.lua'
	no file '/usr/local/lib/lua/5.2/chdkptp.lua'
	no file '/usr/local/lib/lua/5.2/chdkptp/init.lua'
	no file '/usr/share/lua/5.2/chdkptp.lua'
	no file '/usr/share/lua/5.2/chdkptp/init.lua'
	no file './chdkptp.lua'
	no file '/home/sd/Documents/HACKPLACE/chdkptp.py/chdkptp/vendor/chdkptp/chdkptp.so'
	no file '/home/sd/Documents/HACKPLACE/chdkptp.py/chdkptp/vendor/chdkptp/lua/chdkptp.lua'
	no file '/usr/local/share/lua/5.2/chdkptp.lua'
	no file '/usr/local/share/lua/5.2/chdkptp/init.lua'
	no file '/usr/local/lib/lua/5.2/chdkptp.lua'
	no file '/usr/local/lib/lua/5.2/chdkptp/init.lua'
	no file '/usr/share/lua/5.2/chdkptp.lua'
	no file '/usr/share/lua/5.2/chdkptp/init.lua'
	no file './chdkptp.lua'
stack traceback:
	[C]: in function 'require'
	[string "<python>"]:2: in main chunk

Looks like the package is looking for the lua files at my relative path not inside the chdkptp installation path.

@5up3rD4n1
Copy link
Author

So... I forked the repo and made it compatible with python3

Just if someone find it useful, here is the repo:

https://github.com/5up3rD4n1/chdkptp.py

I'm closing the issue. Thanks! :) 👍

@jbaiter
Copy link
Owner

jbaiter commented Jan 1, 2018

Could you submit a pull request with your changes? I'd love to add Python 3 support, but I haven't used the library in a a long time and no longer have access to a camera that can run chdk :/

@5up3rD4n1
Copy link
Author

Sure, no problem!

@emanuelelaface
Copy link

Hi, I am using the Python3 fork of @5up3rD4n1 but after the installation I have the error
dynamic libraries not enabled; check your Lua installation
I see on some other group that you had the same issue, did you find a way to fix it?

@R-ay
Copy link

R-ay commented Sep 26, 2019

Hello,
I used the python3.7.4 fork @5up3rD4n1 also and did the installation.
Also I have lupa 1.8.
Everything worked except when I launch the test.py file.

I have a "Segmentation fault (coredumped)"
So I tried to debug this with gdb :

#0 0x00007ffff69b1421 in ?? () from /usr/lib/liblua5.2.so.5.2
#1 0x00007ffff69aea89 in lua_error () from /usr/lib/liblua5.2.so.5.2
#2 0x00007ffff69bfc88 in luaL_error () from /usr/lib/liblua5.2.so.5.2
#3 0x00007ffff69c11ed in luaL_checkversion_ () from /usr/lib/liblua5.2.so.5.2
#4 0x00007ffff69c12b4 in luaL_setfuncs () from /usr/lib/liblua5.2.so.5.2
#5 0x00007ffff6ac1466 in luaopen_lfs (L=0x5555556a3c68) at lfs.c:886
#6 0x00007ffff6acbc80 in luaopen_chdkptp (L=0x5555556a3c68) at chdkptp.c:2202
#7 0x00007ffff6a71ac7 in ?? () from /usr/lib/liblua.so.5.3
#8 0x00007ffff6a71cf3 in ?? () from /usr/lib/liblua.so.5.3
#9 0x00007ffff6a71d51 in ?? () from /usr/lib/liblua.so.5.3
#10 0x00007ffff6a6d7bc in lua_callk () from /usr/lib/liblua.so.5.3

I don't think it's relevant, so I used pycharm to debug test.py.
Seems like the segfault come when I import chdkptp, so I went deep, and found that this line is causing the segfault :

 self._rt.execute("""
            require('chdkptp')
            util = require('util')
            util:import()
            varsubst = require('varsubst')
            chdku = require('chdku')
            exposure = require('exposure')
            dng = require('dng')
            prefs = require('prefs')
            fsutil = require('fsutil')
        """.format(CHDKPTP_PATH))

Specially the require('chdkptp'), because when I remove it (I know it's a must have line), I have this error (no more segfault):

lupa._lupa.LuaError: ../chdkptp.py/chdkptp/vendor/chdkptp/lua/chdku.lua:23: attempt to index a nil value (global 'sys')

Next solution I tried, I removed the modification done by @5up3rD4n1, which was :
self._rt = LuaRuntime(unpack_returned_tuples=True, encoding='latin-1')
So I put encoding = None
self._rt = LuaRuntime(unpack_returned_tuples=True, encoding=None)
But I have this issue :

lupa._lupa.LuaError: [string ""]:3: attempt to concatenate a POBJECT value (global 'CHDKPTP_PATH')

I tried the chdkptp.py python2.7, it works.

To sump up, the segfault is caused by "require('chdkptp')" when the encoding is set to 'latin-1', but when there is no encoding we have the problem with the POBJECT.

I would like to make it fully compatible with 3.7 and with the last chdkptp, but this segfault issue is really annoying, do you have any idea?

Thank you! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants