Skip to content

Instantly share code, notes, and snippets.

@asimihsan
Last active August 29, 2015 13:56
Show Gist options
  • Save asimihsan/9186003 to your computer and use it in GitHub Desktop.
Save asimihsan/9186003 to your computer and use it in GitHub Desktop.
Installing Bokeh in a virtualenv

You can't install Bokeh in a virtualenv without modifying /home/asim.ihsan/Programming/envs/default/lib/python2.7/site.py to add the getsitepackages() from the Python 2.7 version of the file in e.g. /usr/lib64/python2.7/site.py. This is because virtualenv uses a Python 2.6 version of this file. This is an open bug:

pypa/virtualenv#355

In your virtualenv site.py search for addsitepackages() and add the following above it:

def getsitepackages():
    """Returns a list containing all global site-packages directories
    (and possibly site-python).

    For each directory present in the global ``PREFIXES``, this function
    will find its `site-packages` subdirectory depending on the system
    environment, and will return a list of full paths.
    """
    sitepackages = []
    seen = set()

    for prefix in PREFIXES:
        if not prefix or prefix in seen:
            continue
        seen.add(prefix)

        if sys.platform in ('os2emx', 'riscos'):
            sitepackages.append(os.path.join(prefix, "Lib", "site-packages"))
        elif os.sep == '/':
            sitepackages.append(os.path.join(prefix, "lib64",
                                        "python" + sys.version[:3],
                                        "site-packages"))
            sitepackages.append(os.path.join(prefix, "lib",
                                        "python" + sys.version[:3],
                                        "site-packages"))
            sitepackages.append(os.path.join(prefix, "lib", "site-python"))
        else:
            sitepackages.append(prefix)
            sitepackages.append(os.path.join(prefix, "lib64", "site-packages"))
            sitepackages.append(os.path.join(prefix, "lib", "site-packages"))
        if sys.platform == "darwin":
            # for framework builds *only* we add the standard Apple
            # locations.
            from sysconfig import get_config_var
            framework = get_config_var("PYTHONFRAMEWORK")
            if framework:
                sitepackages.append(
                        os.path.join("/Library", framework,
                            sys.version[:3], "site-packages"))
    return sitepackages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment