如何在 Mac 上安装 VirtualBox SDK

发布于 2024-12-14 05:52:00 字数 176 浏览 5 评论 0原文

似乎没有任何关于如何执行此操作的文档。我进入 /sdk/installer 并运行 vboxsetup.py 脚本,但它引发了以下异常:

Exception: No VBOX_INSTALL_PATH defined, exiting

There does not seem to be any documentation on how to do it. I went into /sdk/installer and ran the vboxsetup.py script but it raised the following exception:

Exception: No VBOX_INSTALL_PATH defined, exiting

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

红颜悴 2024-12-21 05:52:00

他们没有充分解释如何安装它,这真的很烦人,而且很奇怪的是,virtualbox 安装本身没有创建 VBOX_INSTALL_PATH 变量。
无论如何,这对我有用:

export VBOX_INSTALL_PATH=/usr/lib/virtualbox
sudo -E python vboxapisetup.py install

It is really annoying that they don't adequately explain how to install it and it's weird that the virtualbox installation does not create the VBOX_INSTALL_PATH variable by itself.
Anyways, This is what worked for me:

export VBOX_INSTALL_PATH=/usr/lib/virtualbox
sudo -E python vboxapisetup.py install
三生殊途 2024-12-21 05:52:00

这是一个通过 Python 面向对象 Web 服务从 VirtualBox SDK 运行 Python 演示脚本 vboxshell.py 的最小示例。

测试环境:

  • 系统:macOS 10.15.2

  • VirtualBox 版本:6.0.14

说明:

cd $HOME/vboxtest
virtualenv venv_vbox -p python2
source venv_vbox/bin/activate
  • 将依赖项安装到venv中:
wget https://netix.dl.sourceforge.net/project/pyxml/pyxml/0.8.4/PyXML-0.8.4.tar.gz
pip install PyXML-0.8.4.tar.gz
pip install ZSI
  • 禁用身份验证(用于测试):VBoxManage setproperty websrvauthlibrary null

  • 安装 SDK python 模块:

cd $HOME/vboxtest/sdk/installer
export VBOX_INSTALL_PATH=/usr/local/bin/virtualbox
export VBOX_SDK_PATH=$HOME/vboxtest/sdk
python vboxapisetup.py install
  • 启动 API Webserver: /Applications/VirtualBox.app/Contents/MacOS/vboxwebsrv -t 0

  • 启动实际的演示脚本:

cd $HOME/vboxtest
source venv_vbox/bin/activate
cd $HOME/vboxtest/sdk/bindings/glue/python/sample
export VBOX_INSTALL_PATH=/usr/local/bin/virtualbox
export VBOX_SDK_PATH=$HOME/vboxtest/sdk
python vboxshell.py -w

您应该获得一个 virtualbox shell,您可以在其中列出所有虚拟机:

$ python vboxshell.py -w
Running VirtualBox version 6.0.14
vbox>
vbox>list
    Machine 'tmp_default_1572559409192_87222' [32844f81-f971-42f8-99d8-f3edbf0bf637], machineState=PoweredOff, sessionState=Unlocked
    Machine 'c4-2' [891a3509-fbc5-44be-816d-5045dd626157], machineState=PoweredOff, sessionState=Unlocked
vbox>

有关更多信息,请检查 SDK文档: https://download.virtualbox.org/virtualbox/SDKRef.pdf

(恕我直言,应谨慎使用,因为 Python2 和 ZSI 均已停产)。

this is a minimal example for running the Python demo script vboxshell.py from the VirtualBox SDK via the Object Oriented Web Service for Python.

Tested with:

  • System: macOS 10.15.2

  • VirtualBox version: 6.0.14

Instructions:

cd $HOME/vboxtest
virtualenv venv_vbox -p python2
source venv_vbox/bin/activate
  • install dependencies into the venv:
wget https://netix.dl.sourceforge.net/project/pyxml/pyxml/0.8.4/PyXML-0.8.4.tar.gz
pip install PyXML-0.8.4.tar.gz
pip install ZSI
  • disable auth (for testing): VBoxManage setproperty websrvauthlibrary null

  • install SDK python module:

cd $HOME/vboxtest/sdk/installer
export VBOX_INSTALL_PATH=/usr/local/bin/virtualbox
export VBOX_SDK_PATH=$HOME/vboxtest/sdk
python vboxapisetup.py install
  • start API webserver: /Applications/VirtualBox.app/Contents/MacOS/vboxwebsrv -t 0

  • start the actual demo script:

cd $HOME/vboxtest
source venv_vbox/bin/activate
cd $HOME/vboxtest/sdk/bindings/glue/python/sample
export VBOX_INSTALL_PATH=/usr/local/bin/virtualbox
export VBOX_SDK_PATH=$HOME/vboxtest/sdk
python vboxshell.py -w

You should be getting a virtualbox shell, in which you can i.e. list all vms:

$ python vboxshell.py -w
Running VirtualBox version 6.0.14
vbox>
vbox>list
    Machine 'tmp_default_1572559409192_87222' [32844f81-f971-42f8-99d8-f3edbf0bf637], machineState=PoweredOff, sessionState=Unlocked
    Machine 'c4-2' [891a3509-fbc5-44be-816d-5045dd626157], machineState=PoweredOff, sessionState=Unlocked
vbox>

For more infos check the SDK docs: https://download.virtualbox.org/virtualbox/SDKRef.pdf

(IMHO should be used with caution as both Python2 and ZSI are EOL).

林空鹿饮溪 2024-12-21 05:52:00

五年过去了,事情似乎并没有太大进展。

在 Mojave 下,我已经安装了 python2 (2.7.15) 和 python3 (3.7.0),并且我必须执行以下操作:

cd /Applications/VirtualBox.app/Contents/MacOS/sdk/installer
sudo VBOX_INSTALL_PATH=/Applications/VirtualBox.app/Contents/MacOS /usr/local/bin/python2 vboxapisetup.py install
sudo VBOX_INSTALL_PATH=/Applications/VirtualBox.app/Contents/MacOS python3 vboxapisetup.py install

内置 Mojave 版本的 Python (/usr/bin/python 版本 2.7.10) 是唯一可以在 VirtualBox 安装后导入 vboxapi 的版本。我必须手动添加其他 Python 版本。

我能找到的关于此的唯一说明位于 SDK 参考的第 40 页,其中建议:

# cd VBOX_INSTALL_PATH/sdk/installer
# PYTHON vboxapisetup.py install

但是,当然没有提及环境变量。正如 Tal 在已接受的答案中指出的那样,有趣的是,他们可能会费心编写 440 页的 SDK 手册,但却没有提及这一点。

Five years later, things haven't progressed much it seems.

Under Mojave, I had brew installed python2 (2.7.15) and python3 (3.7.0), and I had to do the following:

cd /Applications/VirtualBox.app/Contents/MacOS/sdk/installer
sudo VBOX_INSTALL_PATH=/Applications/VirtualBox.app/Contents/MacOS /usr/local/bin/python2 vboxapisetup.py install
sudo VBOX_INSTALL_PATH=/Applications/VirtualBox.app/Contents/MacOS python3 vboxapisetup.py install

The built-in Mojave version of Python (/usr/bin/python version 2.7.10) was the only one that could import vboxapi after the VirtualBox install. I had to add the other Python versions manually.

The only instruction regarding this that I could find comes on page 40 of the SDK ref, where it suggests:

# cd VBOX_INSTALL_PATH/sdk/installer
# PYTHON vboxapisetup.py install

But, of course no mention of an environment variable. As Tal points out in the accepted answer, interesting that they can be bothered to write a 440 page SDK manual, and yet fail to mention this.

风蛊 2024-12-21 05:52:00

使用虚拟环境的简单方法

尝试仅使用python 3。对于Mac OS上的pyvbox API,我使用第二个virtualenv,即python 2 Python2 venv

基础设置:

cd /Applications/VirtualBox.app/Contents/MacOS/sdk/installer
export VBOX_INSTALL_PATH=/Applications/VirtualBox.app/Contents/MacOS
sudo -E python3 vboxapisetup.py
cd $HOME
mkdir vbox
virtualenv -p /usr/bin/python venvpy2
source venvpy2/bin/activate
pip install virtualbox

我仍然几乎只使用 python3,然后使用 subprocess.Popen 初始化 venvpy2 并运行 python2 模块。将 stdoutstderr 返回到主控制 python3 代码中。完成此操作后,我得出的结论是,适合我的用例的更好方法是使用命令行 vboxmanage 自动化 Box 服务器设置

Simple approach using virtual environs

I try to only use python 3. For pyvbox API on Mac OS I'm using a second virtualenv which is python 2 Python2 venv

Base set up:

cd /Applications/VirtualBox.app/Contents/MacOS/sdk/installer
export VBOX_INSTALL_PATH=/Applications/VirtualBox.app/Contents/MacOS
sudo -E python3 vboxapisetup.py
cd $HOME
mkdir vbox
virtualenv -p /usr/bin/python venvpy2
source venvpy2/bin/activate
pip install virtualbox

I still pretty much only use python3, then use subprocess.Popen initialise venvpy2 and run python2 module. Take stdout and stderr back into main controlling python3 code. Having got this to work, I've concluded better approach for my use case is use command line vboxmanage Automate box server setup

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文