Hi, first let me just say two things: 1) I like the tool. Thanks! 2) My understanding is that -f/--force would overwrite an existing environment of the same name and version.
Here is what happens when I try to use -f with an environment that already exists:
$ pyenv versions
* system (set by ~/.pyenv/version)
2.7.10
2.7.10/envs/test-py2.7.10
$ pyenv virtualenv -f 2.7.10 test-py2.7.10
pyenv-virtualenv: `~/.pyenv/versions/test-py2.7.10' already exists.
A little dive into the shell script leads me the following pair of conditionals:
...
VIRTUALENV_PATH="${PYENV_ROOT}/versions/${VIRTUALENV_NAME}"
if [[ "${VIRTUALENV_PATH/*/envs/*}" != "${PYENV_ROOT}/versions" ]]; then
COMPAT_VIRTUALENV_PATH="${PYENV_ROOT}/versions/${VIRTUALENV_NAME##*/}"
fi
if [ -n "${COMPAT_VIRTUALENV_PATH}" ]; then
if [ -e "${COMPAT_VIRTUALENV_PATH}" ] || [ -L "${COMPAT_VIRTUALENV_PATH}" ]; then
echo "pyenv-virtualenv: \`${COMPAT_VIRTUALENV_PATH}' already exists." 1>&2
exit 1
fi
fi
...
I'm really not sure what this section is trying to do but it looks to me like it may always evaluate to true if an environment already exists, regardless of the force tag.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
Quick comment: I've found pyenv rehash necessary at some points to fix problems. Did not fix this problem.
I have the same issue.
--force does not appear to be doing anything.
$ pyenv virtualenv --force --update python3.6
pyenv-virtualenv: `/Users/cmeza/.pyenv/versions/python3.6' already exists.
$ pyenv virtualenv --force --clear python3.6
pyenv-virtualenv: `/Users/cmeza/.pyenv/versions/python3.6' already exists.
I also noticed that the return code is 1 if a virtualenv of the given name already exists. Since the version already existing is documented as a supported case of --force, it seems like the return code should be 0 in this case.
$ pyenv virtualenv --force alreadyexists
pyenv-virtualenv: `/Users/chris/.pyenv/versions/alreadyexists' already exists.
$ echo $?
1
I found some info as to the cause of this issue. These lines have logic to handle the --force flag, and they were added four years ago:
# If the virtualenv exists, prompt for confirmation unless
# the --force option was specified.
if [ -d "${VIRTUALENV_PATH}/bin" ]; then
if [ -z "$FORCE" ]; then
echo "pyenv-virtualenv: ${VIRTUALENV_PATH} already exists" 1>&2
read -p "continue with installation? (y/N) "
case "$REPLY" in
y* | Y* ) ;;
* ) exit 1 ;;
esac
fi
However, the lines in the OP, which cause a premature exit with return-code 1, were added two years ago. So it seems like this change from 2 years ago might have broken the force flag: https://github.com/pyenv/pyenv-virtualenv/commit/0b9b19232ad2bb03155d356adc5b56b2a25bd92c
Most helpful comment
I found some info as to the cause of this issue. These lines have logic to handle the
--forceflag, and they were added four years ago:However, the lines in the OP, which cause a premature exit with return-code 1, were added two years ago. So it seems like this change from 2 years ago might have broken the force flag: https://github.com/pyenv/pyenv-virtualenv/commit/0b9b19232ad2bb03155d356adc5b56b2a25bd92c