Issue
Summary: To activate a pyenv environment, pyenv is requiring me to include the path to the environment instead of just the environment name.
I was previously able to run pyenv activate env_name
, whereas now I must run pyenv activate 3.9.1/envs/env_name
.
I accidentally deleted some files in my home directory, but I still had (at least some of) my .pyenv, and it still contained files in the versions
directory with the names of my environments. When I ran pyenv
, it did not recognize the command.
So I reinstalled pyenv, first copying the old .pyenv into a separate forlder, and then I copied the contents of versions
and shims
into the new .pyenv.
Now, if I run pyenv versions
or pyenv virtualenvs
, it does include the environment I want: 3.9.1/envs/env_name
. However, if I type pyenv activate env_name
, it says that there is no virtual environment with that name. However, If I type pyenv activate 3.9.1/envs/env_name
, it does work. In the past, before accidentally deleting those files, it would recognize my environment without prepending 3.9.1/envs
on the environment name.
I'm running linux.
Solution
Since your pyenv
itself doesn't seem broken (it can create new versions with their alias (symbolic link) just fine), it's probably just the symbolic links that have disappeared.
From a quick test, it appears you can very simply recreate the virtual environment, and everything (packages installed) will still be there, while you get the alias again.
So try
pyenv virtualenv 3.9.1 env_name
It may complain, and ask to continue: just enter y
(I think the --force
option can also do it, in case you have many virtual environments to repair and want to do that in a loop or so).
Check after doing the first one, if pyenv virtualenvs
now lists the full name and the alias, then continue with the others.
If you want to be safe, first make a backup of the first virtual environment you're testing this on, or save the installed packages into a list somewhere (pip freeze > pip.list
or so), so it's easy to recover if something goes wrong. But as mentioned, my quick tests shows pyenv virtualenv
just recreates the symbolic link, nothing really more, since the other parts of the virtual environment already exists (that is, creating a virtual environment doesn't remove an existing one).
Answered By - 9769953 Answer Checked By - Timothy Miller (WPSolving Admin)