Build failed when pyenv install on macOS

I installed Miniconda3 before installing pyenv, so I tried to uninstall Miniconda and then install pyenv, but it failed.

Error

terminal

$ pyenv install miniconda3-4.7.12
Downloading Miniconda3-4.7.12-MacOSX-x86_64.sh...
-> https://repo.anaconda.com/miniconda/Miniconda3-4.7.12-MacOSX-x86_64.sh
Installing Miniconda3-4.7.12-MacOSX-x86_64...

EnvironmentLocationNotFound: Not a conda environment: /Users/[user]/opt/miniconda3/envs/[environment]


BUILD FAILED (OS X 12.1 using python-build 20180424)

Check the environment variable

I uninstalled Miniconda, but it seemed to remain the environment variables.

terminal

$ env | grep CONDA
CONDA_EXE=/Users/[user]/opt/miniconda3/bin/conda
_CE_CONDA=
CONDA_PYTHON_EXE=/Users/[user]/opt/miniconda3/bin/python
CONDA_SHLVL=3
CONDA_PREFIX=/Users/[user]/opt/miniconda3/envs/[environment]
CONDA_DEFAULT_EXE=[environment]
CONDA_PROMPT_MODIFIER=([environment])
CONDA_PREFIX_1=/Users/[user]/anaconda3
CONDA_PREFIX_1=/Users/[user]/opt/miniconda3

Delete the environment variable

Delete the variables with unset command.

terminal

$ unset CONDA_XXX

After deleting, the environment was built successfully.

Other things I did

terminal

$ xcode-select --install