N
N
No_name4512021-12-17 18:40:06
Python
No_name451, 2021-12-17 18:40:06

Why doesn't pyenv activate the environment with the new python interpreter (Ubuntu 20.04.3 LTS)?

Before installing docker and docker-compose on the machine, the command to check the python 3 version seems to work through an alias:
python -V -> Python 3.8.10

After installing the alias, it stopped working, now the command looks like this:

python -V -> Команда «python» не найдена...
python3 -V -> Python 3.8.10


Now installed pyenv , installed Python==3.7.7 .
Registered settings for .bashrc :
# ---PYENV---
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"


Created a virtual environment with the required version of Python==3.7.7 :
pyenv virtualenv 3.7.7 env_project

Thanks to the .bashrc config , when you enter the directory from which the pyenv environment was created , it is automatically pulled up:
(env_project) [email protected]:~/path1/path2/path3/3_7_7$


But still, python activation doesn't happen:
(env_project) [email protected]:~/path1/path2/path3/3_7_7$ python -V -> Команда «python» не найдена...
(env_project) [email protected]:~/path1/path2/path3/3_7_7$ python3 -V -> Python 3.8.10
(env_project) [email protected]:~/path1/path2/path3/3_7_7$ pyenv which python -> /home/user-name/.pyenv/versions/env_project/bin/python
(env_project) [email protected]:~/path1/path2/path3/3_7_7$ pyenv which python3 -> /home/user-name/.pyenv/versions/env_project/bin/python3


In order to normally activate the environment and it really worked, you have to activate it like on windows:
source "/home/user-name/.pyenv/versions/env_project/bin/activate"


And then the commands are executed correctly:
python -V -> Python 3.7.7

A crutch, and an unpleasant one at that...

But most of all I'm interested in how to make pyenv friends with VS CODE it will pseudo-run as always:

pyenv shell env_project
(env_project) [email protected]:~/path1/path2/path3/3_7_7$


And again, an attempt to run Python of the desired version will fail (already from the VS CODE console ):
pyenv shell env_project
(env_project) [email protected]:~/path1/path2/path3/3_7_7$ python -V -> Команда «python» не найдена...
(env_project) [email protected]:~/path1/path2/path3/3_7_7$ python3 -V -> Python 3.8.10


I have to go back to the crutch above ...

Tell me, what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
No_name451, 2021-12-18
@No_name451

Found a solution.
As it turned out, you need to add an additional line to the .bashrc configuration file , which is not in the installation documentation:

# ---PYENV---
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)" # <- Без нее почему-то не работало
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

Before line: 61be0224e228f064009353.png
After:
61be0231d1475787140982.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question