Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Pythonbrew + virtualenv: fixup_pth_and_egg_link incorrect paths #315

Open
kylegibson opened this Issue · 0 comments

1 participant

@kylegibson

Environment

> which virtualenv
/home/kyle/.pythonbrew/pythons/Python-2.6.5/bin/virtualenv
> which python
/home/kyle/.pythonbrew/pythons/Python-2.6.5/bin/python
> virtualenv --version
1.7.2

Create a virtual environment

> virtualenv testenv
> source testenv/bin/activate

Install editable package from github

(testenv)> pip install -e git+git://github.com/disqus/nexus.git#egg=nexus
(testenv)> cat testenv/lib/python2.6/site-packages/nexus.egg-link
/home/kyle/testenv/src/nexus

The initial egg-link is absolute.

Make the virtualenv relocatable

(testenv)> virtualenv -vv --relocatable testenv
(testenv)> cat testenv/lib/python2.6/site-packages/nexus.egg-link
/home/kyle/testenv/src/nexus

Egg-link is still absolute.

I have the following code in the fixup_pth_and_egg_link function to display additional information about the environment:

def fixup_pth_and_egg_link(home_dir, sys_path=None):
    """Makes .pth and .egg-link files use relative paths"""
    home_dir = os.path.normcase(os.path.abspath(home_dir))
    if sys_path is None:
        sys_path = sys.path
    logger.debug('paths %s' % sys_path)
    logger.debug('prefix %s' % sys.prefix)
    logger.debug('executable %s' % sys.executable)
    # rest of method ...

Output from the above logging statements:

paths ['/home/kyle/.pythonbrew/pythons/Python-2.6.5/bin', '/home/kyle/.pythonbrew/pythons/Python-2.6.5/lib/python2.6/site-packages/distribute-0.6.24-py2.6.egg', '/home/kyle/.pythonbrew/pythons/Python-2.6.5/lib/python26.zip', '/home/kyle/.pythonbrew/pythons/Python-2.6.5/lib/python2.6', '/home/kyle/.pythonbrew/pythons/Python-2.6.5/lib/python2.6/plat-linux2', '/home/kyle/.pythonbrew/pythons/Python-2.6.5/lib/python2.6/lib-tk', '/home/kyle/.pythonbrew/pythons/Python-2.6.5/lib/python2.6/lib-old', '/home/kyle/.pythonbrew/pythons/Python-2.6.5/lib/python2.6/lib-dynload', '/home/kyle/.pythonbrew/pythons/Python-2.6.5/lib/python2.6/site-packages', '/home/kyle/.pythonbrew/pythons/Python-2.6.5/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info']
prefix /home/kyle/.pythonbrew/pythons/Python-2.6.5
executable /home/kyle/.pythonbrew/pythons/Python-2.6.5/bin/python

I would expect the executable to be the python in the new virtualenv, especially given that the top of virtualenv.py includes #!/usr/bin/env python

> source testenv/bin/activate
(testenv)> env python
Python 2.6.5 (r265:79063, Dec 16 2011, 19:49:33) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.executable
/home/kyle/testenv/bin/python

Workaround #1

Install virtualenv in the new environment, deactivate and activate again

> virtualenv testenv
> source testenv/bin/activate
(testenv)> pip install virtualenv
(testenv)> deactivate
source testenv/bin/activate
(testenv)> pip install -e ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.