How to Install and Run Multiple Python Versions on Ubuntu/Debian | pyenv & virtualenv Setup Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
you want to install different python versions on the debian or ubuntu linux because you work on different projects that require different python versions and dependencies or you just want to check out the latest release candidate of the next python version in this video i'm going to show you how to install and use different python versions using pi inf together with virtual environments and how to use those with visual studio code welcome i'm cons i got a master's degree in computer science and currently i work as a graduate research assistant where i use python on a daily basis and that makes pionf to one of my most important tools installing and using different python versions under ubuntu or debian linux is actually pretty easy using pyenv pi info is a command line tool which allows you to seamlessly switch between different python versions and also enables you to set specific python versions for dedicated folders together with virtual environments pinef is an incredibly useful tool for everyone who uses python on a regular basis so without further ado let's jump right into linux to set everything up before we can start using pi end we have to install a bunch of packages using apt and you can find a list of all the packages you have to install throughout on my website for which you can find the link down below in the description so we're going to copy all the packages over here and enter them in our terminal and press on enter and wait until they have been installed now that we have installed all the packages necessary for pine we can install pine which is super easy we're just going to clone the pion github repository into our home directory we copy that paste and press on enter and then we'll clone the pie and github repository into the dot pyth directory in our home directory before we can start using pint we have to add three things to our bashrc the first one is the environment variable pi and root which points to the dot pint directory we just created with our git clone then we're going to extend the path variable such that the pile command is actually usable when we open a terminal and then we're going to add the pi init command which will activate pi every time we open a new terminal so we're just going to copy those three commands over here copy paste and enter them and now we can close this terminal and open up a new one and when we now enter pi inf we can see pi inf is working and this concludes the installation of pine and now we're going to use it and the first thing we are going to do is to check out which python versions we can actually install using pyenv and for this we're going to enter the command pi and install minus l which will list all the python versions which are available through pi f and there's a lot of those versions there's stackless there's pi pi there's anaconda miniconda but for this video we are going to stick to the normal c python implementation and i would like to install the latest stable version of the python version 3.9 which is 3.9.7 so we're going to copy this string over here and then we enter pi end install and paste the version number and press enter and this will install the python version 3.9.7 through pyent now that we have installed our first python version through pyen we can check which python versions are available through pine on our system and for that i'm going to enter payan versions and we can see currently the system version which comes with the operating system is installed and the version 3.9.7 is available and the currently active version is marked by this asterisk in the front i would like to use the version 3.9.7 for my whole system so i'm going to enter the command pin global [Applause] 3.9.7 and this will make this python version globally the default for every python command i'm going to issue we can check that by entering python capital v which shows that we are actually using python version 3.9.7 and i even prepared a little python test program it's a quick hello world which prints out the current python version and when we run that python hello pi we can see it says hello i'm python version 3.9.7 but now i would like to check out the latest release candidate of python with one of my python projects and for that i'm going to install the latest release candidate let's first look it up pi n install minus l and when we scroll up we can find that the latest release candidate for the python version 3.10 is 3.10.0 rc2 we're going to copy that copy and then enter once again pi and install and then we paste the version and press on enter now with this python release kinetic installed we're going to issue the pi end versions command once again which shows us that the version is now available and if we enter pi n local 3 10 0 rc 2 we're going to set the python release candidate version for our local directory here this created the dot pion minus version file and when we have a look at that it actually contains the version string and if we run python minus v we can see it actually uses python 3.10 point rc2 and when we run our python script or hello world script we see it actually runs with python version 3.9.02 when you work on a python project you usually import several modules but you don't want to install those modules system-wide because different projects might depend on different versions of those modules and virtual environments help you out here virtual environments will create a dedicated directory in your project folder which will store all the modules you want to use for that project and to create a virtual environment we first have to enter python m venth dot vent and this will create the virtual environment in our python test directory when we have a look we can see it actually created the dot event directory and when we look at ven bin we can see it actually has the python version here it has its pip version here and to activate this virtual environment we have to enter source vent bin activate and this will activate the virtual environment and we can see that it is actually activated because it added this dot vent in front of our prompt and now you can use pip to install your python modules and the python modules will be stored within the dot vent directory and as a last step i'm going to show you how to use virtual environments within visual studio code we're going to start visual studio code from the command line we enter code dot and this will open visual studio code in the directory we are currently in which is the python test and we can see we have the hello dot pi which contains our hello world script which prints out the version number before we can run our python script we are going to add a settings json to this project which will tell vs code to always launch the virtual environment for that we are going to enter ctrl shift p to open the command palette then we enter settings json and we're going to open the workspace settings json this will open a empty json file but in here we're going to enter python terminal activate environment and this will be set to true and if we save it and close it and now go to run start without debugging a new terminal will pop up at the bottom of our visual studio code and we can see it automatically activated our virtual environment and it is running with the python version 3.10 point rc2 and this concludes this video on pine virtual environments and visual studio code we've seen how to install different python versions how to set a global python version through pi inf how to set a local version through pint and how to use virtual environments together with pint in visual studio code i hope you enjoyed this video and let me know in the comments if it was helpful for you remember that you can find all the commands used in this video together with a complete documentation on how to set up pi virtual environments together with visual studio code on my website for which you can find the link down below in the description give this video a like and if you want to catch up with me join our lovely discord community last but not least big shout out to my patreon subscribers for their support i wish you a fantastic day and i hope to see you in my next video bye bye
Info
Channel: k0nze
Views: 35,807
Rating: undefined out of 5
Keywords: python tutorial, learn python, pyenv, python, python 3, python programming, python3, virtual environments, install python, virtualenv, venv, python virtual environment, python virtual environments, pipenv, vscode, visual studio code, vs code, k0nze, k0nze builds, Konze, python for everyone, python for everybody, tutorial, ubuntu, pyenv tutorial, install python on linux, linux, debian
Id: 1Zgo8M9yUtM
Channel Id: undefined
Length: 9min 7sec (547 seconds)
Published: Sat Sep 25 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.