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

Relativ paths does not work for Windows #47

Open
dmatuschek opened this issue Mar 25, 2021 · 1 comment · May be fixed by #53
Open

Relativ paths does not work for Windows #47

dmatuschek opened this issue Mar 25, 2021 · 1 comment · May be fixed by #53

Comments

@dmatuschek
Copy link

dmatuschek commented Mar 25, 2021

We use this package for a project and we discovered a bug for Windows users. If you want to install dependencies on windows you will receive an OSError - File not found.

We looked a bit deeper into this bug and found out that the path to the python binary (on windows \.venv\Scripts\python.exe) is passed as a relative path. The problem is that Popen on windows does not execute this path from the current working directory (see: https://stackoverflow.com/a/21412727).

Therefore the argument for the Popen call needs to have an absolute path. This could be fixed with (if path contains the absolute path)

@property
def _python_rpath(self):
    """The relative path (from environment root) to python."""
    # Windows virtualenv installation installs pip to the [Ss]cripts
    # folder. Here's a simple check to support:
    if sys.platform == 'win32':
        return os.path.join(self.path, 'Scripts', 'python.exe')
    return os.path.join('bin', 'python')

Alternatively, it could be solved with a os.path.abspath for Windows.

dolfinus added a commit to dolfinus/virtualenv-api that referenced this issue May 13, 2021
@dolfinus dolfinus linked a pull request May 13, 2021 that will close this issue
@madhavajay
Copy link

@sjkingo ? Any chance of merging this?

For anyone else, thank god for monkeypatching.

from virtualenvapi.manage import VirtualEnvironment
def fix_windows_virtualenv_api(cls):
    def _python_rpath(self):
        """The relative path (from environment root) to python."""
        # Windows virtualenv installation installs pip to the [Ss]cripts
        # folder. Here's a simple check to support:
        if sys.platform == 'win32':
            # fix here https://github.com/sjkingo/virtualenv-api/issues/47
            return os.path.join(self.path, 'Scripts', 'python.exe')   
        return os.path.join('bin', 'python')

    setattr(cls, "_python_rpath", property(_python_rpath))

fix_windows_virtualenv_api(VirtualEnvironment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants