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: IN_PROGRESS
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Lars Wendler (Polynomial-C)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-12 07:37 UTC by Balint SZENTE
Modified: 2020-02-02 01:58 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

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) 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!