pyenv global interpreter not working on windows10 - python

I have just installed pyenv following the installation guide pyenv-win, things goes smoothly, but i could not make the pyenv global python as the global interpreter
I have rehashed after installation using pyenv rehash
PS D:\> pyenv versions
3.5.1
3.6.2
3.7.7
* 3.8.2 (set by C:\Users\xxx\.pyenv\pyenv-win\version)
results
> python --version
> 3.8.4
# expected
> 3.8.2
therefore, I am not able to use virtualenv with the pyenv installed python interpreter
virtualenv py382-djangodev --python=3.8.2
The path 3.8.2 (from --python=3.8.2) does not exist

I had the same issue which I finally solved:
1 - Uninstall Python (your current version when you type the command python -V)
2 - Install pyenv-win and add it to the PATH (here are some optional steps to install it via chocolatey, which adds it directly to the PATH)
2.2 - Install chocolatey
2.3 - In an administrator powershell run: choco install pyenv-win
3 - Start menu (windows key) -> Manage application execution aliases -> disable aliases related to python
4 - install the desired python version via pyenv: pyenv install DESIRED VERSION NUMBER
5- run pyenv rehash
6 - set it as global pyenv global DESIRED VERSION NUMBER
7 - you sould see the desired version by running the command python -V

In windows NT, the PATH variable is a combined result of the system and user variables:
The Path is constructed from the system path, which can be viewed in
the System Environment Variables field in the System dialog box. The
User path is appended to the system path
Shims PATH are defined in the user variables, so make sure your host python interpreter path is not defined in your system path

Deinstalling everything connected to python (except pyenv) and using pyenv only worked for me.

Related

Why there are two python versions in a virtual environment?

I have created a virtual environment using anaconda in VS. When the environment is active. I check the version using python --version, it gives the following output Python 3.9.9, whereas when I use which python and check the version from the path /usr/bin/python --version I get a different version Python 2.7.18. Why is that happening, and which version does the environment use?
Once your virtual environment is activated the python command will use the python version from your venv (located in path/to/.venv/bin/python).
which python and /usr/bin/python forces the use of the python version installed in /usr/bin/python which in your case seems to be version 2.7.18. If you want to change your default Python version (the one thats used with python without a venv being active) you can use sudo ln -s /usr/bin/python /usr/bin/python3.9.

Pipenv not recognizing shims for PyEnv python installation

I'm attempting to use pipenv and pyenv to create a virtual environment using python 3.9.0 for a project, but am not able to get pipenv to recognize the version of python 3.9.0 installed by pyenv. Oddly, using pyenv python 3.8.6 works just as expected, and I'm specifying the specific python I want pipenv to use, similar to this answer.
I'm running Catalina 10.15.7 and had a coworker reproduce this exact same behavior on his machine.
Both Pipenv and pyenv have been installed via Homebrew. I have since tried uninstalling homebrew Pipenv and reinstalling with pip, with the same results.
To Reproduce
I successfully ran pyenv install 3.9.0, and when I run pyenv versions, I see:
system
3.8.6
3.9.0
Just as I'd expect.
Inside my working directory, I run pyenv local 3.9.0 to switch my local version of python, followed by pyenv version, which returns returns:
3.9.0 (set by /Users/my-name/myproject)
indicating that the local version was set.
To double check, running pyenv which python returns:
/Users/my-name/.pyenv/versions/3.9.0/bin/python
Now, if I run pipenv install --python 3.9.0 I get the following:
This already is suspect, since 3.9.0 is my local version already. If I respond with y, I get:
Which seems odd, as when I run python, I get to python 3.9.0, so clearly it is on my path. A Pipfile is not created for me, and I don't get a pipenv virtual environment.
Now, if instead I run pipenv install --python $PIPENV_PYTHON, which should in theory use the version of python on my path (which, again, should be 3.9.0), I get this:
Notice how it says "using /users/..../python (3.9.0) to create virtualenv", which is correct, however the next line down says "created virtual environment CPYTHON3.8.6...".
Now, if I repeat the above steps using python 3.8.6, everything works fine.
Additionally, if I specify pipenv --python ~/.pyenv/versions/3.9.0/bin/python3.9, that also seems to work fine -- so for some reason it's not respecting the version, but it is respecting the binary.
The same is true if I run pipenv install --python $(pyenv which python), since it's effectively the same thing as the above command.
For reference my environment vars:
PIP_PYTHON_PATH=/usr/local/Cellar/pipenv/2020.11.15/libexec/bin/python <- perhaps this is a problem?
PIPENV_ACTIVE=1
PIPENV_PYTHON=/Users/myname/.pyenv/shims/python
PYENV_ROOT=/Users/myname/.pyenv
And my $PATH starts with PATH=/Users/my-name/.pyenv/shims:
I do happen to have python 3.8 and python 3.9 installed via homebrew as well, however I'm not trying to use these, and since my path leads off with the shims, I feel like this should not be a problem. Running which python3 and which python both point to the "shims" folder.
Summary
Pipenv is not respecting my pyenv shims, despite the fact that my PYENV_ROOT and my PATH are set correctly. Running pipenv install --python $(pyenv which python) works, specifying a python version does not.
Is this a problem with pipenv, or pyenv, or something that I'm doing?
Per the pipenv docs:
Pipenv by default uses the Python it is installed against to create
the virtualenv. You can set the --python option to $(pyenv which python) to use your current pyenv interpreter.
It was probably using your system python versions rather than your shims

VScode doesnt see pyenv python interpreters

I installed pyenv-win on my windows machine. It works fine in the command line. I can install python versions, set them as global etc. But My VS Code doesn't see them. It only sees one python interpreter I installed a long time ago when I wasn't using pyenv yet.
VScode:
pyenv:
C:\Users\jbron\cmder
λ pyenv versions
3.7.0
* 3.8.0 (set by C:\Users\jbron\.pyenv\pyenv-win\version)
Why is it not finding my pyenv interpreters? I don't have problems like that on my Linux machines
It is recommended that you try the following:
Please check whether the Python environment variable contains your installed Python path:
Please reopen VSCode after installation:
Update:
The environment variable path of "pyenv" I use is: (Under this path, we can find Python 3.6.7 downloaded by pyenv)
We can see the storage location where it downloaded Python 3.6.7:
C:\Users\...\.pyenv\pyenv-win\install_cache\python-3.6.7-amd64-webinstall.exe
Double-click to install:

Specify python version when creating a new virtual-environment using pyenv-virtualenvwrapper and change the version afterwards

As far as I've understood, with the homebrew-installed pyenv-virtualenvwrapper I can create a new virtual environment via the command mkvirtualenv proj_name independently of the current working directory in the terminal where I'm executing the command.
I.e., I assume I don't have to do cd /path/to/proj_name before executing mkvirtualenv proj_name.
Still, what I was wondering is how to choose the local python version of this very project, since if I used pyenv virtualenv the syntax allows for specifying the exact python version for that very project like so:
pyenv virtualenv 3.9.0 proj_name
What I did was going into the project folder via cd /path/to/proj_name and executed pyenv local 3.9.0 before creating the virtual environment (venv) via mkvirtualenv proj_name, but I'm not sure whether this had an effect at all.
How will the python version for the new project venv created via pyenv-virtualenvwrapper be chosen, and can it be changed for that specific venv later on?
OS:
Description: Lubuntu 20.04.1 LTS,
Release: 20.04,
Codename: focal

Why pyenv states that a version is not installed despite it does exist?

I have the error in the script output
Notice: /Stage[main]/Python/Exec[set-python-global]/returns: pyenv: version `2.7.9' not installed
Error: /usr/local/pyenv/bin/pyenv global 2.7.9 returned 1 instead of one of [0]
However, the command
pyenv versions
returns correctly:
pyenv versions
• system (set by /usr/local/pyenv/version)
2.7.9
Some other commands:
sudo /usr/local/pyenv/bin/pyenv global 2.7.9
pyenv: version `2.7.9' not installed
In the directory
/usr/local/pyenv/versions
I see the directory 2.7.9
The command
sudo /usr/local/pyenv/bin/pyenv local 2.7.9
Also returns
pyenv: version `2.7.9' not installed
I am on RHEL 7
pyenv installs Python into $PYENV_ROOT, defaults to $HOME/.pyenv, for each user.
When you're using sudo, you switch to root user temporarily in this very command. There's no python installed by pyenv for user root under directory /root/.pyenv. So python version 2.7.9 was not found.

Categories

Resources