Shai Avr
Shai Avr

Reputation: 1340

Update python version using pyenv?

I am using pyenv to manage my python installations on both my Windows desktop (using pyenv-win) and on my MacBook.

I currently have one global installation of version 3.10.4 which is my "main" python version where I play around, work on simple projects and have all my pip packages installed. I'd like to update my python version to 3.10.5, but maintain all my packages and I am sure how to do that.

Before using pyenv, I, simply, installed python from python.org. When I wanted to update, I'd simply download the installer of the new version and run it, which would override the python installation, but not touch any of the packages, so it was that simple.

I am not sure how it's done with pyenv though. I couldn't find any update command, so it seems I am supposed to install the new version, set it as the new global version, and remove the old one. However, does it mean that I have to reinstall all my pip packages? I can export a list of them to install them again, but it feels like there should be a simple update command that would update the version and maintain all the packages.

Am I missing something?

Upvotes: 3

Views: 2532

Answers (1)

Sarvesh Gupta
Sarvesh Gupta

Reputation: 74

For this you need to understand how pyenv actually works, So when you install pyenv and install python, it sets your environment variables to your python location. And when you change python version in pyenv, it changes those python version to it. Since with every python environment, it has its own pip(which is also set by pyenv). You will be having different version of it. The best way I think is that you can do

pip freeze > requirements.txt

Change your python version, And then install all listed dependencies from requirements.txt

pip install -r requirements.txt

This will be fast and easy method. To update and other stuff related to pyenv is here https://realpython.com/intro-to-pyenv/, These are more good then pyenv official doc.

Upvotes: 2

Related Questions