Use Package Versioning (2024)

Use Package Versioning (1)

Why do we version packages?

When you have previously worked on text documents you might have found yourself naming files as myfile.doc, myfilev2.doc, myfilev3.doc, etc., so that you can keep track of which version is which. Alternatively, you might use a file name based on the date: myfile22062020.doc, myfile23062020.doc, myfile27062020.doc.

Similar to text documents, Python packages are "versioned" so that we can easily keep track of what is in each version. Python packages, however, are versioned according to a strict format:

major.minor.patch

...where major, minor, and patch are all integer numbers. For example, at the time of writing the latest version of the requests package is 2.24.0.

Whenever a change is made to a Python package, the version number is changed (regardless of how small the change is). The changes are split according to three different categories:

In this course so far we have installed Python packages using the command pip install <package> , where <package> is the name of the Python package that you want to install. When we run this command there is no mention of any sort of package version. However, you might notice that the output of the command does include a reference to a particular package version. For example, if I run the following command:

→ pip install requestsCollecting requests Using cached https://files.pythonhosted.org/packages/45/1e/0c169c6a5381e241ba7404532c16a21d86ab872c9bed8bdcd4c423954103/requests-2.24.0-py2.py3-none-any.whlRequirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./anaconda3/lib/python3.7/site-packages (from requests) (1.24.1)Requirement already satisfied: certifi>=2017.4.17 in ./anaconda3/lib/python3.7/site-packages (from requests) (2019.6.16)Requirement already satisfied: chardet<4,>=3.0.2 in ./anaconda3/lib/python3.7/site-packages (from requests) (3.0.4)Requirement already satisfied: idna<3,>=2.5 in ./anaconda3/lib/python3.7/site-packages (from requests) (2.8)Installing collected packages: requestsSuccessfully installed requests-2.24.0~→

Note that my command pip install requests doesn’t mention a specific version of the package, but that the last line of the output Successfully installed requests-2.24.0 shows that we have installed a specific version: 2.24.0. This version, at the time of writing, is the latest version of the requests package available. So, if you don’t specify a package version, pip installs the latest requestspackage available.

Get to grips with package versioning

The simplest way to install a particular Python package version is to use the == operator. For example, pip install requests==2.1.0 will, as you would expect, install version 2.1.0 . There are, however, a number of different ways in which to specify the package version. For example:

  • pip install requests~=2.2 will install the highest version available above 2.2, but not 3.0 or higher.

  • pip install requests~=2.1.0 will install the highest version available above 2.1.0, but not 2.2.0 or higher.

  • pip install requests>2.5.0 will install the highest version available above 2.5.0.

  • pip install “requests>2.4.0,<2.6.0” will install the highest version available above 2.4.0, but lower than 2.6.0.

Let’s give some of these commands a go together. Each time we install the requests package we will uninstall it using the pip uninstall <package> command. Let’s start by uninstalling requests:

~→ pip uninstall requestsUninstalling requests-2.5.3:Would remove:/Users/george/anaconda3/lib/python3.7/site-packages/requests-2.5.3.dist-info/*/Users/george/anaconda3/lib/python3.7/site-packages/requests/*Proceed (y/n)? ySuccessfully uninstalled requests-2.5.3~→

Now let’s run pip install requests~=2.2 :

~→ pip install requests~=2.2Collecting requests~=2.2 Using cachedhttps://files.pythonhosted.org/packages/45/1e/0c169c6a5381e241ba7404532c16a21d86ab872c9bed8bdcd4c423954103/requests-2.24.0-py2.py3-none-any.whlRequirement already satisfied: idna<3,>=2.5 in ./anaconda3/lib/python3.7/site-packages(fromrequests~=2.2)(2.8)Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./anaconda3/lib/python3.7/site-packages(fromrequests~=2.2)(1.24.1)Requirement already satisfied: certifi>=2017.4.17 in ./anaconda3/lib/python3.7/site-packages(fromrequests~=2.2)(2019.6.16)Requirement already satisfied: chardet<4,>=3.0.2 in ./anaconda3/lib/python3.7/site-packages(fromrequests~=2.2)(3.0.4)Installing collected packages: requestsSuccessfully installed requests-2.24.0~→

As expected, this installs version 2.24.0, the highest version of requests available below 3.0 (which doesn’t actually exist yet) at the time of writing. Let’s uninstall again and then run pip install requests~=2.1.0:

→ pip uninstall requestsUninstalling requests-2.24.0: Would remove:/Users/george/anaconda3/lib/python3.7/site-packages/requests-2.24.0.dist-info/* /Users/george/anaconda3/lib/python3.7/site-packages/requests/*Proceed (y/n)? y Successfully uninstalled requests-2.24.0~→ pip install requests~=2.1.0Collecting requests~=2.1.0 Using cached https://files.pythonhosted.org/packages/1e/97/f0a8e5e71c75a2abf5ec91438b84ec1a40a5e1b5f985c06721a3ebe57c0a/requests-2.1.0-py2.py3-none-any.whlconda 4.7.5 has requirement requests>=2.12.4, but you'll have requests2.1.0 which is incompatible.anaconda-client1.7.2 has requirement requests>=2.9.1, but you'll have requests 2.1.0 which is incompatible.Installing collected packages: requestsSuccessfully installed requests-2.1.0~→

This installs version 2.1.0, the highest version of requests available in the 2.1.x range. Let’s uninstall requests again and try our last installation command, pip install “requests>2.4.0,<2.6.0”:

~→ pip uninstall requestsUninstalling requests-2.1.0: Would remove:/Users/george/anaconda3/lib/python3.7/site-packages/requests-2.1.0.dist-info/* /Users/george/anaconda3/lib/python3.7/site-packages/requests/*Proceed (y/n)? y Successfully uninstalled requests-2.1.0~→pip install “requests>2.4.0,<2.6.0”-bash: 2.6.0”: No such file or directory~→pip install "requests>2.4.0,<2.6.0"Collecting requests<2.6.0,>2.4.0 Using cached https://files.pythonhosted.org/packages/95/54/44dc83b5f11c6da06bf9abd18c8a0905e0e297e0a9c3bfbc0c6ee4bdd33d/requests-2.5.3-py2.py3-none-any.whlconda 4.7.5 has requirement requests>=2.12.4, but you'll have requests 2.5.3 which is incompatible.anaconda-client1.7.2 has requirement requests>=2.9.1, but you'll have requests 2.5.3 which is incompatible.Installing collected packages: requestsSuccessfully installed requests-2.5.3~→

This installs requests 2.5.3, the highest version of requests available above 2.4.0 but below 2.6.0.

To watch me installing different versions of requests check out the following screencast:

Exercise

Your manager has been doing some analysis using Python. They have written a script which makes use of two Python packages: matplotlib version 3.2.2 and numpy version 1.19.0 .

First install the script:p1c4s2_exercise_script.py

Then install the two particular package versions needed and run the script.

Let’s Recap!

  • Python packages are versioned so that we can keep track of what code is in each version.

  • Python packages have a new version number each and every time a change to the package is made.

  • You can use pip to install your desired version of a Python package.

Now that you are up to speed with Python package versioning, let’s check your understanding of Pip with a short quiz. Then we’ll look at setting up a Python virtual environment, one way of using different Python package versions across different projects.

Use Package Versioning (2024)
Top Articles
Gold-backed ETFs and gold futures: What’s the difference?
FedEx | System Down
Spectrum Gdvr-2007
Kathleen Hixson Leaked
Wizard Build Season 28
80 For Brady Showtimes Near Marcus Point Cinema
Beacon Schnider
The Best English Movie Theaters In Germany [Ultimate Guide]
Urban Dictionary Fov
Ella Eats
Labor Gigs On Craigslist
735 Reeds Avenue 737 & 739 Reeds Ave., Red Bluff, CA 96080 - MLS# 20240686 | CENTURY 21
2015 Honda Fit EX-L for sale - Seattle, WA - craigslist
Navy Female Prt Standards 30 34
3476405416
What Is Vioc On Credit Card Statement
Jet Ski Rental Conneaut Lake Pa
Valic Eremit
Greensboro sit-in (1960) | History, Summary, Impact, & Facts
Milwaukee Nickname Crossword Clue
Craigslist Rome Ny
Dr Seuss Star Bellied Sneetches Pdf
Shelby Star Jail Log
Gopher Hockey Forum
Miles City Montana Craigslist
Free Tiktok Likes Compara Smm
Vlocity Clm
Stolen Touches Neva Altaj Read Online Free
Wbli Playlist
Ma Scratch Tickets Codes
Spinning Gold Showtimes Near Emagine Birch Run
Powerspec G512
Sephora Planet Hollywood
Albertville Memorial Funeral Home Obituaries
Ticket To Paradise Showtimes Near Regal Citrus Park
Oxford House Peoria Il
“To be able to” and “to be allowed to” – Ersatzformen von “can” | sofatutor.com
18006548818
2024-09-13 | Iveda Solutions, Inc. Announces Reverse Stock Split to be Effective September 17, 2024; Publicly Traded Warrant Adjustment | NDAQ:IVDA | Press Release
'The Night Agent' Star Luciane Buchanan's Dating Life Is a Mystery
Haunted Mansion (2023) | Rotten Tomatoes
Europa Universalis 4: Army Composition Guide
Copd Active Learning Template
Hdmovie2 Sbs
Wzzm Weather Forecast
Grand Park Baseball Tournaments
St Als Elm Clinic
Runelite Ground Markers
Verilife Williamsport Reviews
Aspen.sprout Forum
Bob Wright Yukon Accident
Kindlerso
Latest Posts
Article information

Author: Tish Haag

Last Updated:

Views: 6183

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Tish Haag

Birthday: 1999-11-18

Address: 30256 Tara Expressway, Kutchburgh, VT 92892-0078

Phone: +4215847628708

Job: Internal Consulting Engineer

Hobby: Roller skating, Roller skating, Kayaking, Flying, Graffiti, Ghost hunting, scrapbook

Introduction: My name is Tish Haag, I am a excited, delightful, curious, beautiful, agreeable, enchanting, fancy person who loves writing and wants to share my knowledge and understanding with you.