virtualbox-python icon indicating copy to clipboard operation
virtualbox-python copied to clipboard

Dynamic module does not define module export function (PyInit_VBoxPython3_5m)

Open vxed opened this issue 6 years ago • 25 comments

ENVIRONMENT
  • Operating System: Debian GNU/Linux 9.3 (stretch)
  • Python version: Python 3.5.3
  • VirtualBox version: 5.2.4r119785
  • VirtualBox SDK version: 5.2.4r119785
  • Location where VirtualBox SDK is installed: /usr/lib/virtualbox/sdk
  • pyvbox version: 1.2.0
SUMMARY

could not use python3.5 with pyvbox (but this is donot issue of pyvbox, am have same error with pure vboxapi) am have not any problem with use python2.7 on same host maybe you could help with this ?

STEPS TO REPRODUCE

import virtualbox virtualbox.VirtualBox()

EXPECTED RESULTS

<virtualbox.library_ext.vbox.IVirtualBox object at 0x7f6e3219a210>

ACTUAL RESULTS

m=VBoxPython3_5m x=dynamic module does not define module export function (PyInit_VBoxPython3_5m) m=VBoxPython3m x=No module named 'VBoxPython3m' m=VBoxPython x=/usr/lib/virtualbox/VBoxPython.so: undefined symbol: _Py_ZeroStruct Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.5/dist-packages/virtualbox/library_ext/vbox.py", line 22, in init manager = virtualbox.Manager() File "/usr/local/lib/python3.5/dist-packages/virtualbox/init.py", line 137, in init self.manager = vboxapi.VirtualBoxManager(mtype, mparams) File "/usr/local/lib/python3.5/dist-packages/vboxapi/init.py", line 989, in init self.platform = PlatformXPCOM(dPlatformParams) File "/usr/local/lib/python3.5/dist-packages/vboxapi/init.py", line 750, in init import xpcom.vboxxpcom File "/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/vboxxpcom.py", line 78, in raise Exception('Cannot find VBoxPython module (tried: %s)' % (', '.join(_asVBoxPythons),)) Exception: Cannot find VBoxPython module (tried: VBoxPython3_5m, VBoxPython3m, VBoxPython)

vxed avatar Jan 10 '18 14:01 vxed

Thanks for opening this issue, I'll take a quick look at the 5.2.4 SDK. Could you describe how you're running these commands (virtualenv, system Python?) and how you installed your SDK?

sethmlarson avatar Jan 10 '18 14:01 sethmlarson

It looks like it's finding VBoxPython, when you installed your SDK did you use Python 3.5 or Python 2.7? You should install it with the Python version you want to use it with.

sethmlarson avatar Jan 10 '18 14:01 sethmlarson

thank you for answer

am not use virtualenv, Debian 9.3 already have python3 3.5.3 version, but system version is Python 2.7.13, am want use python3 for virtualbox management

am install virtualbox from deb package which am get from official virtualbox repository, then am download and unzip to /tmp VirtualBox sdk cd /tmp/sdk/installer export VBOX_INSTALL_PATH=/usr/lib/virtualbox (which contains VBoxPython.so, VBoxPython2_7.so, VBoxPython3_5m.so) python3 vboxapisetup.py install pip3 install pyvbox

vxed avatar Jan 10 '18 14:01 vxed

Thanks for the setup steps. I'll take a look at this later as I don't have Debian 9.3 in front of me.

sethmlarson avatar Jan 10 '18 15:01 sethmlarson

am have same issue with ubuntu 16.04 (looks same but maybe different in details if needed am could install ubuntu 16.04 and open new issue)

maybe you could provide information about linux distro which already tested with python3.5+ and virtualbox ?

vxed avatar Jan 10 '18 15:01 vxed

Well I develop VirtualBox using 3.5 and 3.6 on Windows and Ubuntu so Ubuntu should work properly. I'll install a fresh environment and try it out. :)

If you could provide the exact steps you took for the Ubuntu environment as well that would be appreciated!

sethmlarson avatar Jan 10 '18 15:01 sethmlarson

Also: try installing pyvbox with pip3 install -U --pre pyvbox to upgrade to the beta version for 5.2.* support. I need to probably tag a non-beta version for 5.2 by now.

sethmlarson avatar Jan 10 '18 15:01 sethmlarson

am have same issue with vboxapi

import vboxapi
vboxapi.VirtualBoxManager()

vxed avatar Jan 10 '18 15:01 vxed

What does this print out after you install 1.3.0b1 of pyvbox?

import virtualbox
v = virtualbox.VirtualBox()
v.find_machine('MACHINE NAME')

sethmlarson avatar Jan 10 '18 15:01 sethmlarson

steps for clean 14.04 wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add - echo "deb http://download.virtualbox.org/virtualbox/debian trusty contrib" > /etc/apt/sources.list.d/virtualbox.list apt update apt install unzip apt install libpython3.4 apt install virtualbox-5.2 wget http://download.virtualbox.org/virtualbox/5.2.4/VirtualBoxSDK-5.2.4-119785.zip unzip VirtualBoxSDK-5.2.4-119785.zip cd sdk/installer/ export VBOX_INSTALL_PATH=/usr/lib/virtualbox/ python3 vboxapisetup.py install python3

>>> import vboxapi
>>> vboxapi.VirtualBoxManager()
m=VBoxPython3_4m x=dynamic module does not define init function (PyInit_VBoxPython3_4m)
m=VBoxPython3m x=No module named 'VBoxPython3m'
m=VBoxPython x=/usr/lib/virtualbox/VBoxPython.so: undefined symbol: _Py_ZeroStruct
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/sdk/installer/vboxapi/__init__.py", line 989, in __init__
    self.platform = PlatformXPCOM(dPlatformParams)
  File "/root/sdk/installer/vboxapi/__init__.py", line 750, in __init__
    import xpcom.vboxxpcom
  File "/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/vboxxpcom.py", line 78, in <module>
    raise Exception('Cannot find VBoxPython module (tried: %s)' % (', '.join(_asVBoxPythons),))
Exception: Cannot find VBoxPython module (tried: VBoxPython3_4m, VBoxPython3m, VBoxPython)

vxed avatar Jan 10 '18 15:01 vxed

So it's finding your VBoxPython3_4m installation it's just erroring out when it tries to import it with this message:

dynamic module does not define init function (PyInit_VBoxPython3_4m)

sethmlarson avatar Jan 10 '18 15:01 sethmlarson

Can you try uninstalling your Python 2.7 install of VBoxPython and installing only 3.*?

sethmlarson avatar Jan 10 '18 15:01 sethmlarson

yeap am have same issue with 3.5 at debian 9.3

>>> import vboxapi
>>> vboxapi.VirtualBoxManager()
m=VBoxPython3_5m x=dynamic module does not define module export function (PyInit_VBoxPython3_5m)
m=VBoxPython3m x=No module named 'VBoxPython3m'
m=VBoxPython x=/usr/lib/virtualbox/VBoxPython.so: undefined symbol: _Py_ZeroStruct
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/vboxapi/__init__.py", line 989, in __init__
    self.platform = PlatformXPCOM(dPlatformParams)
  File "/usr/local/lib/python3.5/dist-packages/vboxapi/__init__.py", line 750, in __init__
    import xpcom.vboxxpcom
  File "/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/vboxxpcom.py", line 78, in <module>
    raise Exception('Cannot find VBoxPython module (tried: %s)' % (', '.join(_asVBoxPythons),))
Exception: Cannot find VBoxPython module (tried: VBoxPython3_5m, VBoxPython3m, VBoxPython)

vxed avatar Jan 10 '18 15:01 vxed

My guess here is that for some reason the VBoxPython3_*m.so modules don't actually define PyInit_VBoxPython3_*m() function, they may only define PyInit_VBoxPython()?

sethmlarson avatar Jan 10 '18 15:01 sethmlarson

which version of ubuntu you use ? am try it right now .)

vxed avatar Jan 10 '18 15:01 vxed

Can you run nm -D /usr/lib/virtualbox/VBoxPython3_*m.so | grep PyInit on your machine and give me the output?

sethmlarson avatar Jan 10 '18 15:01 sethmlarson

debian 9.3

# nm -D /usr/lib/virtualbox/VBoxPython3_*m.so | grep PyInit
0000000000012562 T PyInit_VBoxPython3_5

ubuntu 14.04

# nm -D /usr/lib/virtualbox/VBoxPython3_*m.so | grep PyInit

(nothing)

vxed avatar Jan 10 '18 15:01 vxed

So it does define it... hm... I'll have to take a look at this more later. Thanks for helping out.

sethmlarson avatar Jan 10 '18 15:01 sethmlarson

debian 9.3 exception contains

m=VBoxPython3_5m x=dynamic module does not define module export function (PyInit_VBoxPython3_5m)

but in file another name of function (needed PyInit_VBoxPython3_5m but it contains PyInit_VBoxPython3_5)

#nm -D /usr/lib/virtualbox/VBoxPython3_*m.so | grep PyInit
0000000000012562 T PyInit_VBoxPython3_5

vxed avatar Jan 10 '18 15:01 vxed

khm am try this dirty hack

# cp /usr/lib/virtualbox/VBoxPython3_5m.so /usr/lib/virtualbox/VBoxPython3_5.so

# diff sdk/bindings/xpcom/python/xpcom/vboxxpcom.py sdk/bindings/xpcom/python/xpcom/vboxxpcom.py.source
39,47c39,47
< #if sys.hexversion >= 0x030200f0 and sys.abiflags:
< #    _asNew = []
< #    for sCandidate in _asVBoxPythons:
< #        if sCandidate[-1:].isdigit():
< #            _asNew.append(sCandidate + sys.abiflags)
< #        else:
< #            _asNew.append(sCandidate)
< #    _asVBoxPythons = _asNew
< #    del _asNew
---
> if sys.hexversion >= 0x030200f0 and sys.abiflags:
>     _asNew = []
>     for sCandidate in _asVBoxPythons:
>         if sCandidate[-1:].isdigit():
>             _asNew.append(sCandidate + sys.abiflags)
>         else:
>             _asNew.append(sCandidate)
>     _asVBoxPythons = _asNew
>     del _asNew

and it works for me in same env (debian 9.3 + python 3.5.3 + virtualbox 5.2.4r119785 and virtualbox sdk 5.2.4r119785)

>>> import virtualbox
>>> virtualbox.VirtualBox()
<virtualbox.library_ext.vbox.IVirtualBox object at 0x7f0cae54fef0>

vxed avatar Jan 10 '18 16:01 vxed

Hey nice catch! Looks like Virtualbox named the .so module wrong somewhere? Maybe I'll investigate being able to package all of these together so that this doesn't happen in the future.

Looks like the sys.abiflags() is being added but there's no corresponding PyInit_* function for all the different abi flags.

sethmlarson avatar Jan 10 '18 18:01 sethmlarson

yes, am think so https://www.virtualbox.org/svn/vbox/trunk/src/libs/xpcom18a4/python/src/module/_xpcom.cpp

# ifdef VBOX_PYXPCOM_VERSIONED
#  if   PY_VERSION_HEX >= 0x03080000 && PY_VERSION_HEX < 0x03090000
#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_8")
#   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_8)

#  elif PY_VERSION_HEX >= 0x03070000 && PY_VERSION_HEX < 0x03080000
#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_7")
#   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_7)

#  elif PY_VERSION_HEX >= 0x03060000 && PY_VERSION_HEX < 0x03070000
#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_6")
#   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_6)

#  elif PY_VERSION_HEX >= 0x03050000 && PY_VERSION_HEX < 0x03060000
#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_5")
#   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_5)

#  elif PY_VERSION_HEX >= 0x03040000 && PY_VERSION_HEX < 0x03050000
#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_4")
#   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_4)

#  elif PY_VERSION_HEX >= 0x03030000 && PY_VERSION_HEX < 0x03040000
#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_3")
#   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_3)

#  elif PY_VERSION_HEX >= 0x03020000 && PY_VERSION_HEX < 0x03030000
#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_2")
#   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_2)

#  elif PY_VERSION_HEX >= 0x03010000 && PY_VERSION_HEX < 0x03020000
#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_1")
#   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_1)

#  elif PY_VERSION_HEX >= 0x02080000 && PY_VERSION_HEX < 0x02090000
#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython2_8")
#   define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_8)

#  elif PY_VERSION_HEX >= 0x02070000 && PY_VERSION_HEX < 0x02080000
#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython2_7")
#   define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_7)

#  elif PY_VERSION_HEX >= 0x02060000 && PY_VERSION_HEX < 0x02070000
#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython2_6")
#   define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_6)
#  else
#   error "Fix module versioning. This Python version is not recognized."
#  endif
# else
#  define MODULE_NAME 	  MANGLE_MODULE_NAME("VBoxPython")
#  if PY_MAJOR_VERSION <= 2
#   define initVBoxPython  MANGLE_MODULE_INIT(initVBoxPython)
#  else
#   define initVBoxPython  MANGLE_MODULE_INIT(PyInit_VBoxPython)
#  endif
# endif

vxed avatar Jan 10 '18 20:01 vxed

That's a good source. We can maybe work around this by packaging VBoxPython or emitting a better error.

sethmlarson avatar Jan 10 '18 20:01 sethmlarson

I opened a defect with VirtualBox: https://www.virtualbox.org/ticket/17448

sethmlarson avatar Jan 10 '18 21:01 sethmlarson

Same issue on Ubuntu 20.04 with python 3.8.10 VirtualBox 6.1-22

m=VBoxPython3_8 x=No module named 'VBoxPython3_8'
m=VBoxPython3 x=No module named 'VBoxPython3'
m=VBoxPython x=/usr/lib/virtualbox/VBoxPython.so: undefined symbol: _Py_ZeroStruct
Traceback (most recent call last):
  File "./dynamicInventory/vbox.py", line 4, in <module>
    vbox = virtualbox.VirtualBox()
  File "/home/adrien/.local/lib/python3.8/site-packages/virtualbox/library_ext/vbox.py", line 22, in __init__
    manager = virtualbox.Manager()
  File "/home/adrien/.local/lib/python3.8/site-packages/virtualbox/__init__.py", line 163, in __init__
    self.manager = vboxapi.VirtualBoxManager(mtype, mparams)
  File "/usr/local/lib/python3.8/dist-packages/vboxapi/__init__.py", line 989, in __init__
    self.platform = PlatformXPCOM(dPlatformParams)
  File "/usr/local/lib/python3.8/dist-packages/vboxapi/__init__.py", line 750, in __init__
    import xpcom.vboxxpcom
  File "/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/vboxxpcom.py", line 78, in <module>
    raise Exception('Cannot find VBoxPython module (tried: %s)' % (', '.join(_asVBoxPythons),))
Exception: Cannot find VBoxPython module (tried: VBoxPython3_8, VBoxPython3, VBoxPython)

AdriwanKenoby avatar Jul 07 '21 09:07 AdriwanKenoby

Same issue on Ubuntu 20.04.5 LTS with python 3.9.13 VirtualBox 6.1.40

>>> vb = virtualbox.VirtualBox()
m=VBoxPython3_9 x=No module named 'VBoxPython3_9'
m=VBoxPython3 x=No module named 'VBoxPython3'
m=VBoxPython x=/usr/lib/virtualbox/VBoxPython.so: undefined symbol: _Py_ZeroStruct
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/paloma/anaconda3/envs/metaGymOldNoVBox/lib/python3.9/site-packages/virtualbox/library_ext/vbox.py", line 22, in __init__
    manager = virtualbox.Manager()
  File "/home/paloma/anaconda3/envs/metaGymOldNoVBox/lib/python3.9/site-packages/virtualbox/__init__.py", line 163, in __init__
    self.manager = vboxapi.VirtualBoxManager(mtype, mparams)
  File "/home/paloma/anaconda3/envs/metaGymOldNoVBox/lib/python3.9/site-packages/vboxapi-1.0-py3.9.egg/vboxapi/__init__.py", line 999, in __init__
  File "/home/paloma/anaconda3/envs/metaGymOldNoVBox/lib/python3.9/site-packages/vboxapi-1.0-py3.9.egg/vboxapi/__init__.py", line 760, in __init__
  File "/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/vboxxpcom.py", line 82, in <module>
    raise Exception('Cannot find VBoxPython module (tried: %s)' % (', '.join(_asVBoxPythons),))
Exception: Cannot find VBoxPython module (tried: VBoxPython3_9, VBoxPython3, VBoxPython)

And result of

$ nm -D /usr/lib/virtualbox/VBoxPython*.so | grep PyInit
00000000000127ff T PyInit_VBoxPython3_6m

WhyNotPal avatar Nov 25 '22 12:11 WhyNotPal