Skip to content

Virtualenv creation fails when current directory contains a file that shadows a module used by virtualenv #6568

@FlavioAmurrioCS

Description

@FlavioAmurrioCS

Issue description

If user has a file in the current directory that shadows a module used by virtualenv it will cause the virtualenv creation to fail.

I did some digging and it seems that because pipenv calls virtualenv with python -m virtualenv ... that python's default behavior is to add the current directory to the PYTHONPATH
https://github.com/pypa/pipenv/blob/main/pipenv/utils/virtualenv.py#L122-L126
After some googling it seems we could just add -P to the command and that should fix it. (Will try and if it works will raise a PR)

Expected result

virtualenv should be created regardless of what files may be present in current directory

Actual result

virtualenv creation fails
Check next section for details.

Steps to replicate

[flavio@Mac ~]
$ mkdir -p /tmp/foo

[flavio@Mac ~]
$ cd /tmp/foo

[flavio@Mac /tmp/foo]
$ echo 'import requests' > secrets.py

[flavio@Mac /tmp/foo]
$ pipenv install certifi
Creating a virtualenv for this project
Pipfile: /private/tmp/foo/Pipfile
Using /Users/flavio/Applications/brew/bin/python33.14.2 to create virtualenv...
⠙ Creating virtual environment...ModuleNotFoundError: No module named 'requests'

✘ Failed creating virtual environment

Failed to create virtual environment.

Please run $ pipenv --support, and paste the results here. Don't put backticks (`) around it! The output already contains Markdown formatting.

If you're on macOS, run the following:

$ pipenv --support | pbcopy

If you're on Windows, run the following:

> pipenv --support | clip

If you're on Linux, run the following:

$ pipenv --support | xclip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions