Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 378871 - app-emulation/virtualbox does not install Python vboxapi properly
Summary: app-emulation/virtualbox does not install Python vboxapi properly
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Viorel Munteanu
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2011-08-12 07:37 UTC by Balint SZENTE
Modified: 2023-08-26 11:53 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
ebuild patch (vbox.patch,1.51 KB, patch)
2011-12-12 21:29 UTC, Ian Delaney (RETIRED)
Details | Diff
Patch to set VBOX_INSTALL_PATH in environment (virtualbox-7.0.8a.ebuild.patch,595 bytes, patch)
2023-08-22 16:40 UTC, Richard Ash
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Balint SZENTE 2011-08-12 07:37:56 UTC
Installing app-emulation/virtualbox with python USE flag enabled does not install vboxapi to the site packages as it should be. The ebuild should run the vboxapisetup.py at the end of the installation.

Reproducible: Always

Steps to Reproduce:
1. USE="python sdk" emerge app-emulation/virtualbox-ose
2. $ python
    >>> import vboxapi
Actual Results:  
>>> import vboxapi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named vboxapi

Expected Results:  
>>> import vboxapi
>>>

Now it must be installed manually:
# export VBOX_INSTALL_PATH=/usr/lib/virtualbox
# cd /usr/lib/virtualbox/sdk/installer
# python vboxapisetup.py install

I propose to:
 1. add also the VBOX_INSTALL_PATH=... variable to /etc/env.d/90virtualbox file, because it is used by VirtualBox (and other) tools.
 2. execute the vboxsetup.py script directly from the ebuild when the python USE flag is set.
Comment 1 Balint SZENTE 2011-08-12 08:00:56 UTC
Also vboxshell.py should be installed. Actually it is a VirtualBox command line frontend in Python and the source package contains the file. It is a very good source of documentation for vboxapi developers.
Comment 2 Ian Delaney (RETIRED) gentoo-dev 2011-12-12 21:29:56 UTC
Created attachment 295603 [details, diff]
ebuild patch

the source has its own libxml2 which you may want or need to disable if it's already installed, but the python module xpcom need be emerged with use python.
If the modules want compiling, add the python_mod_optimize and python_mod_cleanup.

gentoo64 virtualbox # USE=python ebuild virtualbox-4.1.6-r1.ebuild merge

 * Updating desktop mime database ...
>>> Original instance of package unmerged safely.
 * Updating desktop mime database ...
This adds the requested vboxshell.py to /usr/bin so you may want to add an elog msg.
Comment 3 Ian Delaney (RETIRED) gentoo-dev 2011-12-13 07:28:31 UTC
shall have to have a second go at this.  for some reason the source has its internal copy of libxml2, and on emerging or re-emerging ir has a file collision mishap.  I shall go for rm -f the handful of files that double up, but if you like you can go in a step earlier and stop them building; ether way is will prevent a file collision event.
Comment 4 Ian Delaney (RETIRED) gentoo-dev 2011-12-13 16:03:43 UTC
well not sure whether it's an issue or not.  I had to unmerge libxml2 to emerge it in the first place, then on expecting the file collision. it didn't occur.
This it them happily installing from emerging with USE=python.  Have a test or two with it.

>>> /usr/lib64/python2.7/site-packages/libxml2.py
>>> /usr/lib64/python2.7/site-packages/drv_libxml2.py
>>> /usr/lib64/python2.7/site-packages/libxml2_python-2.6.30-py2.7.egg-info
>>> /usr/lib64/python2.7/site-packages/libxml2mod.so
Comment 5 Lars Wendler (Polynomial-C) (RETIRED) gentoo-dev 2011-12-20 12:44:41 UTC
I am not really into python that's why this bug unfortunately is rotting a bit.
Thanks for the patch Ian, it gives at least a hint where to look for the problem. What really gives me pain is the compilation of the bundled libxml2. This is something that is generally discouraged in gentoo packages. So if anyone can come up with a solution that works with our system-libxml2 package, I will happily add that to our virtualbox ebuilds.
Comment 6 Balint SZENTE 2012-02-20 15:13:09 UTC
I think you are unnecessarily complicating this issue.

The solution is what I wrote in my first post. You are not supposed to deal with embedded libxml2. It is VirtualBox's internal business. Definitely it is not necessary to be installed separately. The same is with xpcom. It is not meant to be installed in site-packages.

Only the content of the /usr/lib/virtualbox/sdk/installer/vboxapi directory needs to be installed in the Python's site-packages with the vboxapisetup.py script.

/usr/lib/python2.7/site-packages/vboxapi/__init__.py will import the xpcom module directly from the sdk directory:

class PlatformXPCOM:
    def __init__(self, params):
        sys.path.append(VboxSdkDir+'/bindings/xpcom/python/')
        import xpcom.vboxxpcom
        import xpcom
        import xpcom.components

This is how it was meant to be used. You should not hassle with installing the internal libxml2 python bindings and the xpcom module.

You can check also Arch Linux's virtualbox-sdk package content:
<http://www.archlinux.org/packages/community/i686/virtualbox-sdk/files/>
Comment 7 Ben Kohler gentoo-dev 2017-08-31 18:26:08 UTC
Is this still a problem on current versions?
Comment 8 Erik Ohrnberger 2020-02-01 14:08:58 UTC
I see that this is an older bug, but still open and in progress.
I may have run into a similar instance.
I'd like to work work someone on this.

Per: https://pypi.org/project/pyvbox/
"Go to VirtualBox’s downloads page (https://www.virtualbox.org/wiki/Downloads) and download the VirtualBox SDK. Within the extracted ZIP file there is a directory called “installer”. Open a console within the installer directory and run python vboxapisetup.py install using your system Python. This installs vboxapi which is the interface that talks to VirtualBox via COM.

Next is to install this library:

To get the latest released version of virtualbox from PyPI run the following:

$ python -m pip install virtualbox"

When trying to run python -m pip install virtualbox 

receive the error message: 

ERROR: (Gentoo) Please run pip with the --user option to avoid breaking python-exec

OK, so run pip install --user virtualbox

This installs the python modules into ~/.local/lib64/python3.6/site-packages
OK.  Make sure that 

export PYTHONPATH=~/.local/lib64/python3.6/site-packages

OK, so now install vboxapi.

python vboxapisetup.py install
Traceback (most recent call last):
  File "vboxapisetup.py", line 88, in <module>
    main(sys.argv)
  File "vboxapisetup.py", line 61, in main
    raise Exception("No VBOX_INSTALL_PATH defined, exiting")
Exception: No VBOX_INSTALL_PATH defined, exiting

Per: https://bugs.gentoo.org/378871
Now it must be installed manually:
# export VBOX_INSTALL_PATH=/usr/lib/virtualbox
# cd /usr/lib/virtualbox/sdk/installer
# python vboxapisetup.py install

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

Done.


Run a single program that should list the VMs VBox has configured, but receive this error:

./VirtualBox.py
import: attempt to perform an operation not allowed by the security policy `PS' @ error/constitute.c/IsCoderAuthorized/412.
./VirtualBox.py: line 13: syntax error near unexpected token `('
./VirtualBox.py: line 13: `vbox = virtualbox.VirtualBox()'

[code]
# # Per: https://code.visualstudio.com/docs/python/debugging#_remote-debugging
# import ptvsd

# # Allow other computers to attach to ptvsd at this IP address and port.
# ptvsd.enable_attach(address=('192.168.2.2', 3000), redirect_output=True)

# # Pause the program until a remote debugger is attached
# ptvsd.wait_for_attach()

import virtualbox

# Initialzie the VirtualBox environment
vbox = virtualbox.VirtualBox()

i = 0
for m in vbox.machines:
    print( i, "vboxname: ", m.name )
    i = i + 1

print( "Done" )
[/code]

The eventual goal is to be able to work in Visual Code on a Windows client, and run and debug the python code on the Gentoo Linux target.
Comment 9 Erik Ohrnberger 2020-02-01 14:11:13 UTC
While the python is running, it seems to freeze the X Window clients, until one of them is clicked, and the the error message is displayed in the ssh shell.
Comment 10 Erik Ohrnberger 2020-02-02 01:58:48 UTC
Resolved my own problem here.

First, vboxapi from the SDK needs to be installed, and for this the VBOX_INSTALL_PATH env var needs to be set.  I took a guess and set it to /usr/lib64/virtualbox, which seemed to be the correct answer.

Once the vboxapi is installed, then install the pyvbox using pip.

Once those two are installed OK, then the python code is good.

Cheers!
Comment 11 Michael Patton 2023-07-19 03:44:33 UTC
(In reply to Balint SZENTE from comment #6)
> I think you are unnecessarily complicating this issue.
> 
> The solution is what I wrote in my first post. You are not supposed to deal
> with embedded libxml2. It is VirtualBox's internal business. Definitely it
> is not necessary to be installed separately. The same is with xpcom. It is
> not meant to be installed in site-packages.
> 
> Only the content of the /usr/lib/virtualbox/sdk/installer/vboxapi https://freegamesonline.io directory
> needs to be installed in the Python's site-packages with the vboxapisetup.py
> script.
> 
> /usr/lib/python2.7/site-packages/vboxapi/__init__.py will import the xpcom
> module directly from the sdk directory:
> 
> class PlatformXPCOM:
>     def __init__(self, params):
>         sys.path.append(VboxSdkDir+'/bindings/xpcom/python/')
>         import xpcom.vboxxpcom
>         import xpcom
>         import xpcom.components
> 
> This is how it was meant to be used. You should not hassle with installing
> the internal libxml2 python bindings and the xpcom module.
> 
> You can check also Arch Linux's virtualbox-sdk package content:
> <http://www.archlinux.org/packages/community/i686/virtualbox-sdk/files/> 
To begin, the VBOX_INSTALL_PATH environment variable must be configured so that the SDK's vboxapi may be installed.  I made an educated guess and used the directory /usr/lib64/virtualbox.
Comment 12 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-07-24 01:21:27 UTC
I suspect it's not IN_PROGRESS anymore (set in 2011). But I'm sure ceamac will take a look soon if it's still broken.
Comment 13 Richard Ash 2023-08-22 16:40:13 UTC
Created attachment 868500 [details, diff]
Patch to set VBOX_INSTALL_PATH in environment

This is still an issue, and means that it's not easily possible to write Python code to interact with VirtualBox (e.g. create and export Virtual Machines).

The first obstacle is that VBOX_INSTALL_PATH is still missing - this should be set as part of the installation in the /etc/env.d/90virtualbox file (which currently only contains VBOX_APP_HOME). As far as I can see this is a one-line patch to the ebuild, as attached.

The second and much nastier problem is that what gets installed at the moment is not python bindings, but an installer (python package) for the python bindings, which then needs to be executed to actually install them. In the process the installer tries to write to the directory where it is located, which is of course read-only (being installed data) and so the installation fails if run as non-root - I haven't tried to run it as root.

I'm not sure what the correct approach is here, as the SDK installer needs to be installed (into destination directory?), before then jumping back and installing the actual bindings using the installer!

Signed-off-by: Richard Ash <richardashaudacity@googlemail.com>
Comment 14 Larry the Git Cow gentoo-dev 2023-08-26 11:50:26 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=93ab26a36f5d15fef87efa4db2a26ec844289bdc

commit 93ab26a36f5d15fef87efa4db2a26ec844289bdc
Author:     Viorel Munteanu <ceamac@gentoo.org>
AuthorDate: 2023-08-26 11:31:58 +0000
Commit:     Viorel Munteanu <ceamac@gentoo.org>
CommitDate: 2023-08-26 11:50:08 +0000

    app-emulation/virtualbox: install python vboxapi
    
    Closes: https://bugs.gentoo.org/378871
    Signed-off-by: Viorel Munteanu <ceamac@gentoo.org>

 .../virtualbox/virtualbox-7.0.10-r1.ebuild         | 753 +++++++++++++++++++++
 app-emulation/virtualbox/virtualbox-9999.ebuild    |  22 +-
 2 files changed, 773 insertions(+), 2 deletions(-)
Comment 15 Viorel Munteanu gentoo-dev 2023-08-26 11:53:07 UTC
Seems to work on my machine.

`vboxshell.py` crashes with python 3.12, so I disabled python3_12 for now.