xvfbwrapper requires python2.7 or up.
I have a script that does this:
from xvfbwrapper import Xvfb
I have python2.7 installed as an alternate installation of python because my OS (centOS 6.4) requires 2.6. When I run the script like this:
python2.7 some_script.py
I get this error:
ImportError: cannot import name Xvfb
This baffles me because the correct version of python is executing the script. It seems that the imported modules are trying to use the system version. If I change the python executable from /usr/local/bin/python2.7 to /usr/local/bin/python, I can open up the console and run the same import statement without getting the error if I ensure there are no byte code compiled files of the module from a previously failed execution, probably compiled with python2.6 for whatever reason.
It seemed like a path issues so I tried putting /usr/local/bin at the top of PATH and changing the name of python2.7 to python but no dice.
Any ideas about what is happening? I'm pulling my hair out trying to figure this out.
Thanks so much.
UPDATE:
xvfbwrapper was installed with:
pip-2.7 install xvfbwrapper
The same issue exists with virtualenv. *In the following example, some_script.py is simply an import statement:
""" some_script.py """
from xvfbwrapper import Xvfb
I ran the following commands:
$ virtualenv --no-site-packages --python=/usr/local/bin/python2.7 venv
$ source ./venv/bin/activate
$ pip install xvfbwrapper
$ python -v some_script.py
The partial output:
import xvfbwrapper # directory /home/projects/process/venv/lib/python2.7/site-packages/xvfbwrapper
# /home/projects/process/venv/lib/python2.7/site-packages/xvfbwrapper/__init__.pyc matches /home/projects/process/venv/lib/python2.7/site-packages/xvfbwrapper/__init__.py
import xvfbwrapper # precompiled from /home/projects/process/venv/lib/python2.7/site-packages/xvfbwrapper/__init__.pyc
Traceback (most recent call last):
File "some_script.py", line 2, in <module>
from xvfbwrapper import Xvfb
ImportError: cannot import name Xvfb
exact python version is 2.7.3 The xvfbwrapper module definitely has Xvfb class defined. I use the same module on a different system without any issues and it is the same version. (xvfbwrapper version 0.2.3)
To provide a little bit more context to the nature of the oddity: I can run the python console within the above virtual environment and successfully execute the same command.
UPDATE:
python2.7 -c "import sys; print sys.path"
The command outputs (*this is the system python, not the virtualenv):
['',
'/usr/local/lib/python2.7/site-packages/supervisor-3.0-py2.7.egg',
'/usr/local/lib/python2.7/site-packages/pip-1.4.1-py2.7.egg',
'/usr/local/lib/python2.7/site-packages/virtualenv-1.10.1-py2.7.egg',
'/usr/local/lib/python2.7/site-packages/distribute-0.7.3-py2.7.egg',
'/usr/local/lib/python2.7/site-packages/setuptools-1.1.6-py2.7.egg',
'/usr/local/lib/python27.zip',
'/usr/local/lib/python2.7',
'/usr/local/lib/python2.7/plat-linux2',
'/usr/local/lib/python2.7/lib-tk',
'/usr/local/lib/python2.7/lib-old',
'/usr/local/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/site-packages']
within the virtualenv created:
['',
'/home/projects/process/venv/lib/python27.zip',
'/home/projects/process/venv/lib/python2.7',
'/home/projects/process/venv/lib/python2.7/plat-linux2',
'/home/projects/process/venv/lib/python2.7/lib-tk',
'/home/projects/process/venv/lib/python2.7/lib-old',
'/home/projects/process/venv/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7',
'/usr/local/lib/python2.7/plat-linux2',
'/usr/local/lib/python2.7/lib-tk',
'/home/projects/process/venv/lib/python2.7/site-packages']