pipenv sync raises `ValueError: Path not found or generated` when `PIPENV_VENV_IN_PROJECT=1` and `.venv/bin` doesn't exist
See original GitHub issuepipenv 2022.01.08 doesn’t properly support creating a new virtual environment in the project (using PIPENV_VENV_IN_PROJECT=1
) if there’s isn’t already an existing one. This makes it hard to do a clean install.
More specifically, if PIPENV_VENV_IN_PROJECT=1
and the .venv/bin
directory doesn’t exist within the project directory, pipenv sync
raises ValueError: Path not found or generated
rather than simply creating the directory (as was done in previous versions). See the repro steps below:
The initial state is a project directory with an initialized pipenv virtual environment
$ pipenv --version
pipenv, version 2022.1.8
$ echo $PIPENV_VENV_IN_PROJECT
1
$ pwd
/workspaces/project
$ pipenv --venv
/workspaces/project/.venv
$ pipenv --rm
$ pipenv sync --dev
Traceback (most recent call last):
File "/home/vscode/.pyenv/versions/3.7.4/bin/pipenv", line 10, in <module>
sys.exit(cli())
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/vendor/click/decorators.py", line 84, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/vendor/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/cli/command.py", line 657, in sync
system=state.system
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/core.py", line 2842, in do_sync
clear=clear,
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/core.py", line 531, in ensure_project
pypi_mirror=pypi_mirror,
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/core.py", line 452, in ensure_virtualenv
python = ensure_python(project, three=three, python=python)
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/core.py", line 344, in ensure_python
path_to_python = find_a_system_python(python)
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/core.py", line 313, in find_a_system_python
python_entry = find_python(finder, line)
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/utils.py", line 2230, in find_python
result = finder.find_python_version(line)
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/pythonfinder.py", line 288, in find_python_version
return self.system_path.find_python_version(
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/pythonfinder.py", line 120, in system_path
self._system_path = self.create_system_path()
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/pythonfinder.py", line 86, in create_system_path
ignore_unsupported=self.ignore_unsupported,
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/path.py", line 683, in create
instance = instance._run_setup()
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/path.py", line 251, in _run_setup
paths[p] = new_instance.get_path(p.joinpath(bin_dir))
File "/home/vscode/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/path.py", line 439, in get_path
raise ValueError("Path not found or generated: {0!r}".format(path))
ValueError: Path not found or generated: PosixPath('/workspaces/project/.venv/bin')
$ mkdir -p .venv/bin
$ pipenv sync --dev
Creating a virtualenv for this project...
# Output not shown, but pipenv successfully created the environment
As shown above:
- pipenv is configured to install the virtual environment within the project directory in the
.venv
dir. This is configured usingPIPENV_VENV_IN_PROJECT=1
- We started with an existing pipenv virtual environment (i.e., the Pipfile.lock exists and the virtual environment is installed in
.venv
within the project directory) - We run
pipenv --rm
to remove the existing environment (this removes the.venv
dir) - Running
pipenv sync --dev
now fails withValueError: Path not found or generated
- After simply creating an empty directory
.venv/bin
, nowpipenv sync --dev
works fine
I do no know when this bug was introduced, but I know that it did not exist in 2018.11.26 but does exist in 2022.01.08.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:5
Top Results From Across the Web
ValueError when trying to use pipenv install - Stack Overflow
I have python installed in 'D:/python382' There is no such directory that the error mentions. I have checked my environment variables and ...
Read more >Frequently Encountered Pipenv Problems - Read the Docs
☤ My pyenv-installed Python is not found Make sure you have PYENV_ROOT set correctly. Pipenv only supports CPython distributions, with version name like...
Read more >pipenv Documentation - Read the Docs
Automatically generates a Pipfile, if one doesn't exist. • Automatically creates a virtualenv in a standard customizable location. • Automatically adds/removes ...
Read more >Configure a Pipenv environment | PyCharm Documentation
Install pipenv by running the following command: $ pip install --user pipenv · For your convenience, you might add the user base's binary...
Read more >Release and Version History — pipenv 2022.12.20.dev0 ...
Bug Fixes¶ · virtualenv creation no longer uses --creator=venv by default; introduced two environment variables: PIPENV_VIRTUALENV_CREATOR – May be specified to ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I just had a very similar issue, with the same version of Pipenv. , in my case it was complaining about a path that seemed to relate to a Pipenv environment I had just removed:
May or may not be related, but I also just recently installed pyenv. I’m not familiar with how pyenv works internally, so I decided I’d try reinstalling Pipenv. I had originally installed it with
pip install pipenv
, this time I installed it with Homebrew.That didn’t work, but then I noticed that directory I mentioned above was in my
PATH
variable, so I closed/restarted my shell and the issue disappeared.I have no idea how the
PATH
got messed up, that was my problem.I believe this happens when you call
pipenv --rm
while you are still insidepipenv shell
. This will mess up yourPATH
variable. So don’t do this:Instead you must do this