I do this infrequently enought that I always forget how to do it. Note that I've finally decided to move away from virtualenvwrapper (workon
, mkvirtualenv
, etc) since it didn't play nicely with the python versions set by pyenv.
Only necessary if this is a new laptop
brew install pyenv
brew install pyenv-virtualenv
If not specified by the project, use a python version released in the last year or two.
pyenv install 3.11
Note that pyenv may say that there is no matching versions, and you'll need to append the latest minor release version to the version number as well.
Create a .python-version
file to ensure pyenv always uses the correct python version when using a terminal window inside this project's directory.
pyenv local 3.11
Verify this is getting picked up correctly by running
python --version
as well as
pyenv version
Now that python is setup correctly in the project's directory, create a new virtualenv to isolate dependencies.
pyenv virtualenv 3.11 name-of-virtualenv
View the virtualenvs you've created with
pyenv virtualenvs <-- note the "s" on the end of the command
Verify you have setup a clean virtualenv
pip freeze
Now you can install your project's dependencies
pip install -r requirements.txt
To activate the virtualenv in a new shell (say, whenever you cd
into the directory with autoenv)
pyenv activate name-of-virtualenv