sethmlarson / virtualbox-python

Complete implementation of VirtualBox's COM API with a Pythonic interface.
https://pypi.org/project/virtualbox
Apache License 2.0
354 stars 75 forks source link

Dynamic module does not define module export function (PyInit_VBoxPython3_5m) #102

Closed vxed closed 1 year ago

vxed commented 6 years ago
ENVIRONMENT
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)

sethmlarson commented 6 years ago

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 commented 6 years ago

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.

vxed commented 6 years ago

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

sethmlarson commented 6 years ago

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.

vxed commented 6 years ago

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 ?

sethmlarson commented 6 years ago

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 commented 6 years ago

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.

vxed commented 6 years ago

am have same issue with vboxapi

import vboxapi
vboxapi.VirtualBoxManager()
sethmlarson commented 6 years ago

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

import virtualbox
v = virtualbox.VirtualBox()
v.find_machine('MACHINE NAME')
vxed commented 6 years ago

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)
sethmlarson commented 6 years ago

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 commented 6 years ago

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

vxed commented 6 years ago

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)
sethmlarson commented 6 years ago

My guess here is that for some reason the VBoxPython3_m.so modules don't actually define `PyInitVBoxPython3m()function, they may only definePyInit_VBoxPython()`?

vxed commented 6 years ago

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

sethmlarson commented 6 years ago

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

vxed commented 6 years ago

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)

sethmlarson commented 6 years ago

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

vxed commented 6 years ago

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 commented 6 years ago

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>
sethmlarson commented 6 years ago

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.

vxed commented 6 years ago

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
sethmlarson commented 6 years ago

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

sethmlarson commented 6 years ago

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

AdriwanKenoby commented 3 years ago

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)
WhyNotPal commented 1 year ago

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
sethmlarson commented 1 year ago

I no longer have time to maintain this library, so am closing this issue.