0

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.

  • Does `pyenv virtualenvs` also show `env_concept_context` by itself? – 9769953 Aug 25 '22 at 19:21
  • @9769953, no, it doesn't. – JoAnn Alvarez Aug 25 '22 at 21:31
  • And if you create a new environment, are there two versions of this new environment? Or also just one. – 9769953 Aug 26 '22 at 07:47
  • I made a new environment, `test_env`, and this one *does* appear twice: `pyenv virtualenvs` returns: ``` 3.9.1/envs/env_name (created from /home/jalvarez/.pyenv/versions/3.9.1) 3.9.1/envs/test_env (created from /home/jalvarez/.pyenv/versions/3.9.1) * test_env (created from /home/jalvarez/.pyenv/versions/3.9.1) ``` `pyenv versions` returns: ``` system 3.7.4 3.9.1 3.9.1/envs/env_name 3.9.1/envs/test_env ``` – JoAnn Alvarez Aug 26 '22 at 17:31

1 Answers1

2

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).

9769953
  • 10,344
  • 3
  • 26
  • 37