Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--relocatable fails on Windows #49

Closed
vbabiy opened this issue Mar 14, 2011 · 12 comments
Closed

--relocatable fails on Windows #49

vbabiy opened this issue Mar 14, 2011 · 12 comments
Labels

Comments

@vbabiy
Copy link

vbabiy commented Mar 14, 2011

C:\TEMP>\Python25\Scripts\virtualenv.exe --relocatable python
The environment doesn't have a file python\bin\activate_this.py -- please re-run
 virtualenv on this environment to update it
Traceback (most recent call last):
  File "C:\Python25\Scripts\virtualenv-script.py", line 9, in <module>
    load_entry_point('virtualenv==1.4.3', 'console_scripts', 'virtualenv')()
  File "c:\python25\lib\site-packages\virtualenv-1.4.3-py2.5.egg\virtualenv.py",
 line 523, in main
    make_environment_relocatable(home_dir)
  File "c:\python25\lib\site-packages\virtualenv-1.4.3-py2.5.egg\virtualenv.py",
 line 928, in make_environment_relocatable
    fixup_scripts(home_dir)
  File "c:\python25\lib\site-packages\virtualenv-1.4.3-py2.5.egg\virtualenv.py",
 line 942, in fixup_scripts
    for filename in os.listdir(bin_dir):
WindowsError: [Error 3] The system cannot find the path specified: 'python\\bin/
*.*'

@vbabiy
Copy link
Author

vbabiy commented Mar 14, 2011

Same problem here. In functions related to the env relocation
(make_environment_relocatable, fixup_scripts), a 'bin' string is used in place
of 'Scripts' in paths. I guess the path_locations function have to be used
here.


Original Comment By: Sylvain Prat

@vbabiy
Copy link
Author

vbabiy commented Mar 14, 2011

Here is a patch that fix the WindowsError(s). But there's still some messages
printed on the screen:

Script Stackless\Scripts\deactivate.bat cannot be made relative (it's not

a normal script that starts with
#!d:\projects\dev\python\sandboxes\stackless/bin/python)

Script Stackless\Scripts\easy_install-2.6-script.py cannot be made

relative (it's not a normal script that starts with
#!d:\projects\dev\python\sandboxes\stackless/bin/python)

Script Stackless\Scripts\easy_install-2.6.exe cannot be made relative

(it's not a normal script that starts with
#!d:\projects\dev\python\sandboxes\stackless/bin/python)

Script Stackless\Scripts\easy_install-2.6.exe.manifest cannot be made

relative (it's not a normal script that starts with
#!d:\projects\dev\python\sandboxes\stackless/bin/python)

Script Stackless\Scripts\easy_install-script.py cannot be made relative

(it's not a normal script that starts with
#!d:\projects\dev\python\sandboxes\stackless/bin/python)

Script Stackless\Scripts\easy_install.exe cannot be made relative (it's

not a normal script that starts with
#!d:\projects\dev\python\sandboxes\stackless/bin/python)

Script Stackless\Scripts\easy_install.exe.manifest cannot be made relative

(it's not a normal script that starts with
#!d:\projects\dev\python\sandboxes\stackless/bin/python)

Script Stackless\Scripts\pip-script.py cannot be made relative (it's not a

normal script that starts with
#!d:\projects\dev\python\sandboxes\stackless/bin/python)

Script Stackless\Scripts\pip.exe cannot be made relative (it's not a

normal script that starts with
#!d:\projects\dev\python\sandboxes\stackless/bin/python)

Script Stackless\Scripts\pip.exe.manifest cannot be made relative (it's

not a normal script that starts with
#!d:\projects\dev\python\sandboxes\stackless/bin/python)

Script Stackless\Scripts\python.exe cannot be made relative (it's not a

normal script that starts with
#!d:\projects\dev\python\sandboxes\stackless/bin/python)

Script Stackless\Scripts\pythonw.exe cannot be made relative (it's not a

normal script that starts with
#!d:\projects\dev\python\sandboxes\stackless/bin/python)

It seems related to path case sensitivity and forward/backward slashes, but
I'm not sure if it's an issue since windows does not use/read shebang lines as
far as I know ;)


Original Comment By: Sylvain Prat

@vbabiy
Copy link
Author

vbabiy commented Mar 14, 2011

  • Changed status from new to resolved.
  • Changed responsible from nobody to jezdez.

Original Comment By: Jannis Leidel

@jpenney
Copy link

jpenney commented Mar 6, 2012

I was having numerous issues with this under Python 2.7 (32-bit).

  • shebang never matched anything due to mixed slashes, case differences, and 'bin' vs. 'Scripts'

  • the new_shebang was breaking things (CLI tools were creating themselves as (for example) pip.exe, and calling pip-script.py, but if the shebang in pip-script.py didn't point to a valid windows exe, it failed).

    I modified the fixup_scripts function as follows and everything seems to be working, but it probably needs more testing:

def fixup_scripts(home_dir):
    if sys.platform == 'win32':
        bin_suffix = 'Scripts'
        # This is what we'll put:
        new_shebang = '#!%s /c python' % os.path.normcase(os.environ['COMSPEC'])
    else:
        bin_suffix = 'bin'
        # This is what we'll put:
        new_shebang = '#!/usr/bin/env python%s' % sys.version[:3]
    # This is what we expect at the top of scripts:
    shebang = '#!%s' % os.path.normcase(os.path.abspath(os.path.join(home_dir, bin_suffix, 'python')))

    activate = "import os; activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); execfile(activate_this, dict(__file__=activate_this)); del os, activate_this"
    bin_dir = os.path.join(home_dir, bin_suffix)
    home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
    for filename in os.listdir(bin_dir):
        filename = os.path.join(bin_dir, filename)
        if not os.path.isfile(filename):
            # ignore subdirs, e.g. .svn ones.
            continue
        f = open(filename, 'rb')
        try:
            try:
                lines = f.read().decode('utf-8').splitlines()
            except UnicodeDecodeError:
                # This is probably a binary program instead
                # of a script, so just ignore it.
                continue
        finally:
            f.close()
        if not lines:
            logger.warn('Script %s is an empty file' % filename)
            continue
        old_shebang = lines[0].strip()
        old_shebang = old_shebang[0:2] + os.path.normcase(old_shebang[2:])
        if not old_shebang.startswith(shebang):
            if os.path.basename(filename) in OK_ABS_SCRIPTS:
                logger.debug('Cannot make script %s relative' % filename)
            elif lines[0].strip() == new_shebang:
                logger.info('Script %s has already been made relative' % filename)
            else:
                logger.warn('Script %s cannot be made relative (it\'s not a normal script that starts with %s)'
                            % (filename, shebang))
            continue
        logger.notify('Making script %s relative' % filename)
        lines = [new_shebang+'\n', activate+'\n'] + lines[1:]
        f = open(filename, 'wb')
        f.write(os.linesep.join(lines).encode('utf-8'))
        f.close()

@piotr-dobrogost
Copy link

Why was it closed?
What needs to be done before @jpenney's fix could be merged?
cc @agronholm

@pnasrat
Copy link

pnasrat commented Nov 14, 2012

What's the PR for the fix?

@jpenney
Copy link

jpenney commented Nov 14, 2012

Since this never seemed of interest I never filed one. I'll update to the latest code and get one together.

@pnasrat
Copy link

pnasrat commented Nov 14, 2012

@jpenney thanks

@pnasrat pnasrat reopened this Nov 15, 2012
@jpenney
Copy link

jpenney commented Nov 27, 2012

I didn't forget about this, but it did not merge cleanly with the latest, so I need to rework it and retest it.

@piotr-dobrogost
Copy link

@jpenney

Do you still feel like getting this patch ready? :)

@jpenney
Copy link

jpenney commented Mar 5, 2013

I apologize! This slipped my mind completely over the holidays. I'll take a look at it later today.

@pfmoore
Copy link
Member

pfmoore commented Mar 8, 2013

Fixed with pull request #401

@pfmoore pfmoore closed this as completed Mar 8, 2013
@pypa pypa locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants