0

I use pyenv to manage my python versions as well as their virtual environments. Sometimes I ran into problems, of which the solution requires building python after installing certain dependencies.

So I simply run

pyenv uninstall 3.8.12

and install the dependencies required, then

pyenv install 3.8.12

however, this operation removes all the package installed along with the entire virtual environment under

pyenvrootdir/.pyenv/versions/3.8.12

in the previous version, like numpy or matplotlib.

So is there any way to remove, then re-build python, while those packages remains, so that I don't need to install them again?

1 Answers1

0

Use virtualenv with pyenv: https://github.com/pyenv/pyenv-virtualenv

Then you can just write, uninstall only needed if you like to delete it:

pyenv install 3.11.2
pyenv virtualenv 3.11.2 test1
pyenv activate test1
pyenv uninstall test1 

To install a new one, just deactivate the current:

pyenv deactivate
pyenv virtialenv 3.11.2 mynewapp
pyenv activate mynewapp

It is not uncommon having lots of virtualenvs.

MortenB
  • 2,749
  • 1
  • 31
  • 35
  • Thank you for answering:) Maybe I wasn't clear enough, the problem I ran into requires uninstall -> reinstall the python interpreter itself. When I remove python 3.8.12 (by running pyenv uninstall), all virtualenvs under 3.8.12 will be removed as well. What I am trying to find is a way to rebuild the python interpreter, while the virtualenv and packages under it remains. I wonder if it's possible. My problem was [link](https://stackoverflow.com/questions/5459444/tkinter-python-may-not-be-configured-for-tk), to be specific. – Bright Lee Mar 17 '23 at 09:19
  • You should not delete a python version until all virtualenvs using is are deleted. Check with `pyenv versions`, but you can have lots of python versions installed '`pyenv install `installs it alongside the others. If you just work with the virtualenv names not python version it will all be fine. – MortenB Mar 17 '23 at 12:35