To create a Python virtual environment using pyenv for a specific Python version, like Python 3.7, you'll need to follow these steps. However, make sure you have both pyenv and the pyenv-virtualenv plugin installed. If you haven't installed the pyenv-virtualenv plugin yet, you can do so by following the instructions on its GitHub page.
Here are the steps to create a Python 3.7 virtual environment using pyenv:
Install Python 3.7 using pyenv, if you haven't already done so:
pyenv install 3.7.12
Once the installation is complete, you can create a virtual environment with Python 3.7. For example, to create an environment named myenv37 using Python 3.7.12, you would run:
pyenv virtualenv 3.7.12 myenv37
After the virtual environment has been created, you need to activate it. You can do so by running:
pyenv activate myenv37
To deactivate the environment, you can simply run:
pyenv deactivate
To ensure your shell always activates this environment by default when you navigate to a specific directory, you can set a local pyenv version in that directory:
cd /path/to/your/project pyenv local myenv37
This will create a .python-version file in your project directory, and pyenv will automatically activate myenv37 whenever you're in this directory.
Comments