Pyenv showing correct pyenv environment but actually using different version

Hi everyone,

I installed pyenv with pyenv-virtualenv on my manjaro. Everything seems fine, installation using pyenv install “version” and pyenv virtualenv “version” “name” works as intended. Then I activate my pyenv virtualenv and I even get the name of the environment in the terminal. When I run

which python && which pip && python -V

I get:

/home/fregy/.pyenv/shims/python
/home/fregy/.pyenv/shims/pip
Python 3.10.5

Which is correct I wanted 3.10.5. But when I try to run some code, that uses for example python’s dataclesses.py I get error because it’s trying to use dataclasses.py in /usr/lib/python3.11:

/usr/lib/python3.11/dataclasses.py:1230: in dataclass
return wrap(cls)
/usr/lib/python3.11/dataclasses.py:1220: in wrap
return _process_class(cls, init, repr, eq, order, unsafe_hash,
/usr/lib/python3.11/dataclasses.py:958: in _process_class
cls_fields.append(_get_field(cls, name, type, kw_only))
/usr/lib/python3.11/dataclasses.py:815: in _get_field
raise ValueError(f'mutable default {type(f.default)} for field '
E   ValueError: mutable default <class 'libs.data_models.user_model.Email'> for field email is not allowed: use default_factor

The error itself it’s not important, the problem is it’s using different version of python.

My .zshrc file:

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/shims:$PATH"
export PATH="$PYENV_ROOT/bin:$PATH"

eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

I don’t know if it’s important, but I am using urxvt as my terminal. Also, when I use VSCode and I choose my pyenv env I can use the “Go to definition” function and it opens the correct file under .pyenv/versions/3.10.5/lib/python3.10/dataclasses.py.

Thank you for any help.

I tried reinstalling pyenv alongside with pyenv-virtualenv. Play around with zshrc file, but nothing worked.

How did you activate the 3.10 version?

pyenv local sel (sel is my environment name)

And how do run your application?

pytest -s -v -m "name_of_the_test"

Try python -m pytest

It says /home/fregy/.pyenv/versions/sel/bin/python: No module named pytest

bad shebang ?

You don’t have pytest installed in your environment.

I am sorry what does it mean? :grimacing:

Yeah I was playing around with the environment and forgot to download one in here. But that only shows that I was able to run pytest even without actually having it downloaded in the environment, because it was probably using the python3.11 one.

When I run pytest -s -v -m "name" it goes for the python3.11, but when I run pip I can’t see pytest installed. Would you know how is that possible, how it can even see they pytest in the python3.11 version.

And when I run python -m pytest it says /home/fregy/.pyenv/versions/sel/bin/python: No module named pytest, but when I run pytest -s -v -m "revolving_1" it says zsh: command not found: pytes. I reinstalled the environment so the pytest is not there rn, but I think the problem is zsh is running the system python and not the env python.

You showed before that pip is the 3.10 version, not the 3.11 version.

Probably somewhat fixed it now, I uninstalled pytest from system’s python pip and suddenly it started working, maybe becuase it was just finding next available one which was in my environment. Weird

But thank you for your time :heart: