是的,你可以,这是可能的,非常棘手的设置,但它现在对我来说很好(ubuntu18.04/python3.6/virtualbox6.0)。在
错误:ModuleNotFoundError: No module named 'vboxapi'
意味着python3找不到vboxapi模块,现在有两种方法可以将vboxapi包“强制安装”到python3:
第一种方法[简单]:假设pyvbox已经安装并且可以与python2.7一起工作,在这种情况下,您只需使用以下命令将包从python2.7 dist包复制到python3 dist包:
^{pr2}$
使用Python3和以下命令解压缩存档文件并运行vboxapisetup.py文件:sudo python3 vboxapisetup.py install
您将得到这个问题:Traceback (most recent call last):
File "vboxapisetup.py", line 90, in
main(sys.argv)
File "vboxapisetup.py", line 63, in main
raise Exception("No VBOX_INSTALL_PATH defined, exiting")
Exception: No VBOX_INSTALL_PATH defined, exiting
您可以直接编辑当前文件vboxapisetup.py,并将第57行从vboxDest = os.environ.get("VBOX_MSI_INSTALL_PATH", None)替换为vboxDest = "/usr/lib/virtualbox"
然后继续运行:sudo python3 vboxapisetup.py install
现在你会得到这样的结果:running install
running build
running build_py
copying vboxapi/__init__.py -> build/lib/vboxapi
running install_lib
creating /usr/local/lib/python3.6/dist-packages/vboxapi
copying build/lib/vboxapi/__init__.py -> /usr/local/lib/python3.6/dist-packages/vboxapi
copying build/lib/vboxapi/VirtualBox_constants.py -> /usr/local/lib/python3.6/dist-packages/vboxapi
byte-compiling /usr/local/lib/python3.6/dist-packages/vboxapi/__init__.py to __init__.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/vboxapi/VirtualBox_constants.py to VirtualBox_constants.cpython-36.pyc
running install_egg_info
Removing /usr/local/lib/python3.6/dist-packages/vboxapi-1.0.egg-info
Writing /usr/local/lib/python3.6/dist-packages/vboxapi-1.0.egg-info
这意味着我们可以安装vboxapi软件包!在
现在再次尝试在pytholbox()中加载:from virtualbox import VirtualBox, Session, Manager, WebServiceManager
box = VirtualBox()
这可能会引发一个新问题:Traceback (most recent call last):
File "virtualbox_python3_test.py", line XX, in
vbox = virtualbox.VirtualBox()
File "/usr/local/lib/python3.6/dist-packages/virtualbox/library_ext/vbox.py", line 22, in __init__
manager = virtualbox.Manager()
File "/usr/local/lib/python3.6/dist-packages/virtualbox/__init__.py", line 143, in __init__
self.manager = vboxapi.VirtualBoxManager(mtype, mparams)
File "/usr/local/lib/python3.6/dist-packages/vboxapi/__init__.py", line 989, in __init__
self.platform = PlatformXPCOM(dPlatformParams)
File "/usr/local/lib/python3.6/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_6m, VBoxPython3m, VBoxPython)
但根据我的调查和研究,如果你幸运(并且有一个由python3原生支持构建的虚拟箱),你可以尝试:cd /usr/lib/virtualbox/
sudo cp VBoxPython3_5m.so VBoxPython3_6m.so
但如果您遇到以下错误:cp: cannot stat 'VBoxPython3_5m.so': No such file or directory
这意味着您在Virtualbox中没有原生python3支持。。。在
可以这样解决:
现在打开python3-virtualbox-5.2.16-lp150.4.11.1.x86_64.rpm存档,浏览到/./usr/lib/virtualbox/,然后提取文件VBoxPython3_6m.so,然后将此文件放到当前工作目录中,然后从该目录中执行以下操作:sudo cp VBoxPython3_6m.so /usr/lib/virtualbox/
现在,您可以将python3绑定用于virtualbox!在