We can easily create an environment named env_name: $ virtualenv env_name In that folder, virtualenv places a binary of Python (which we can also customize and doesn’t need to be the default one in Linux). Instead of using the default directory provided by Linux, virtualenv installs these packages in a custom / bin directory. Virtualenv creates Python environments for Python packages. pyenv also simplifies downloading, installing, and managing several Python versions, making their installation as simple as: $ pyenv install 3.9 Based on the virtual environment we’ve activated, pyenv will intercept all our calls to commands such as python, pip, and more, and redirect them to the appropriate tool (found in PATH) and from there to the right binary file. We can have several virtual environments with different Python versions. Pyenv is the reference tool used to manage multiple isolated Python versions, as pyenv supports both Python 2 and Python 3. In fact, from Python 3.6, the use of pyvenv is deprecated. Although there are others such as pyvenv, pyenv-virtualenv, and poetry that we can use for the same goals, they are less frequent, are losing official support, and there is less documentation about them. We’ll briefly present pyenv, virtualenv and pipenv. Virtual environments help us manage different Python versions and different package versions. Thus, we need to keep track not only of Python versions but also of the versions of Python packages themselves. Python programs may depend on third-party packages whose versions might differ between programs. However, especially if we also use virtual environments, we should get used to pip as it makes installing packages rather easy: $ pip install It’s likely that the package manager of our Linux distribution can also install Python packages. pip also handles dependencies and uninstalls packages. With pip, we can choose to install packages globally or for a given user. Let’s go through the most relevant ones before discussing which one is more suited for a given project.īefore diving more deeply into how to manage different Python or package versions, we need to introduce pip, which is considered the package manager for Python. We can’t discuss all of them, but we should be aware of the variety that the Python ecosystem offers. However, there are many different tools to manage these virtual environments. Virtual environments are tools that developers use to isolate Python versions and Python packages for specific projects, without messing around with other Python versions, such as that of the Linux system. This way, we avoid overwriting or causing trouble with Linux packages. The right way to install another Python version is by using virtual environments. We shouldn’t change the default Python version of Linux, but we might still need a different Python version than the default one. Before installing a new version, it’s worth checking the default one: Nonetheless, we can install multiple versions of Python without replacing the default one (usually located in /usr/bin/python). To fix the problem, we just need to reinstall Python, and the package manager should take care of redoing all the symbolic links that we broke. In case we’ve already changed the default Python version of our Linux environment, we might need to revert our changes. If we change the default Python version of Linux, we might break these applications. Linux systems rely on Python for applications that go from the storm built-in in Ubuntu to the RPM package manager yum in Debian/Red Hat. This can make other packages stop working, especially the ones written for the default Python version that might not have support in the replaced version. If it does, when we change the default version of Python in Linux, we’re changing the interpreter. Our Linux distribution may or may not come with a default Python interpreter. There are only a few cases where we truly need to change the default Python version. This is a bad idea because we can break packages within the distribution. In general, manually changing the default version of Python in Linux is a procedure that may end up in broken dependencies.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |