我需要使用 python3 生成/杀死虚拟机器。
有一个名为的模块pyvbox
,但是它不起作用,因为该vboxapi
包与python3不兼容。
如果我尝试导入vboxapi
:
>>> import vboxapi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'vboxapi'
>>> import virtualbox
>>> pool = virtualbox.pool.MachinePool("ubuntu1")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/virtualbox/pool.py", line 76, in __init__
with self._lock() as session:
File "/usr/lib/python3.5/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.5/dist-packages/virtualbox/pool.py", line 85, in _lock
vbox = VirtualBox()
File "/usr/local/lib/python3.5/dist-packages/virtualbox/library_ext/vbox.py", line 21, in __init__
manager = virtualbox.Manager()
File "/usr/local/lib/python3.5/dist-packages/virtualbox/__init__.py", line 103, in __init__
with import_vboxapi() as vboxapi:
File "/usr/lib/python3.5/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.5/dist-packages/virtualbox/__init__.py", line 34, in import_vboxapi
import vboxapi
ImportError: No module named 'vboxapi'
中有一个包/usr/lib/python2.7/dist-packages/vboxapi
,但它与 python3 不兼容,例如因为
File "/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/__init__.py", line 128
except IOError, why:
^
SyntaxError: invalid syntax
有没有办法将 vboxapi 与 python3(Ubuntu 16.06 上的默认 python 版本)一起使用,还是我必须自己编写这样的包?
(可选)什么是xpcom
?
我继续跑Linux Iwillnottellyoumyhostname 4.4.0-38-generic #57-Ubuntu SMP Tue Sep 6 15:42:33 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
。
答案1
有一种方法可以将 vboxapi 与 python3 一起使用。你可以使用这个:vboxapi-py3