The best practice is to give the virtual environment the same name as your project. The is a name chosen by the user to help keep track of the environment. We can create a virtual environment with a specific Python version in a single command. Working with pyenv in virtual environments If we cd out of the new directory, the Python version will revert to the global version. Let’s test to make sure version 3.8.9 is running in our new directory. Then we create a directory, cd into that directory and set the local version of Python to 3.8.9 $ mkdir test_dir_3.8.9 & cd test_dir_3.8.9 Let’s say we want to use Python 3.8.9 when working in a certain directory. When we want to change versions, we can use ‘pyenv local’. Okay, once I have the global version set, I almost never mess with it. Let’s confirm 3.8.11 is the global Python version. The second way is to edit the version in this file: There are two ways we can set it as the global version. Python 3.8.11 is a good version of Python to set as our global version it’s relatively recent but not too new. ‘system’ denotes the Python version installed with your operating system. ‘system’ has an (*) next to it to indicate this is the version that is currently active. We can now see version 3.8.11 is available to us. When it’s done, we can check pyenv for the versions of Python now available to us. Now suppose you need to install Python 3.8.11 in order to run a certain application locally. Let’s say we want to see just the available Python 3.8 versions we can run this command. With the following command, we can see all the Python version available from pyenv (the list is too long to show). Use pyenv to install whichever versions of Python we want $ exec "$SHELL" # Or just restart your terminal Once you see that, restart your shell and we can begin installing python versions with pyenv. Load pyenv automatically by adding the following to ~/.bashrc: export PATH="$HOME/.pyenv/bin:$PATH"eval "$(pyenv init -)"eval "$(pyenv virtualenv-init -)" When pyenv is properly installed, you should see something like this: WARNING: seems you still have not added 'pyenv' to the load path. One thing you do not want to skip, is setting up your shell environment, whether bash or zsh, for pyenv. To see what those are, see the pyenv GitHub repository here: However, there are other installation methods, including with brew and with GitHub checkout. The recommended method is to use cURL and the pyenv-installer. Once again, the instructions vary by operating system. However, there is some basic support for Windows now available via the pyen-win project. Originally, pyenv did not support Windows at all. Ubuntu/Debian $ sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-opensslįedora/CentOS/RHEL $ sudo yum install gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite \sqlite-devel openssl-devel xz xz-devel libffi-devel MacOS $ brew install openssl readline sqlite3 xz zlib Pyenv builds from source this means we definitely need to install the required dependencies first. Ok, let’s install pyenv…but first, we must install build dependencies But this can be problematic if we need to run another version besides the one we installed globally. Normally, when we install Python, we do so globally. It may be 2.7 or 3.0 or 3.6, but regardless, it’s probably not the version you want, at least not all the time. * I've had better success with the following process inside of an IDE, like VS Code, than in the Terminal Which version of Python are you running on your local system? Activate different Python versions and virtual environments automatically. Switch between the installed versions of Python with ease.Install multiple versions of Python, from 2.1 all the way to the latest development version.Pyenv does that and more! Here are the core abilities of pyenv: Wouldn’t it be nice to have a ‘version manager’ for Python to switch between versions locally in different directories, as well as in our virtual environments? Often, different projects we have benefited from or contributed to require exact Python versions in order to run as expected. At the time of this writing, Python has progressed all the way from version 1.0 in 1994 to version 3.10 and beyond today. The Python language has many working versions. Pyenv for Managing Python Versions and Environments
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |