{"id":132543,"date":"2023-03-18T21:43:26","date_gmt":"2023-03-18T21:43:26","guid":{"rendered":"https:\/\/blog.finxter.com\/?p=1222091"},"modified":"2023-03-18T21:43:26","modified_gmt":"2023-03-18T21:43:26","slug":"easy-way-to-update-a-python-package-with-pip-upgrade","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2023\/03\/18\/easy-way-to-update-a-python-package-with-pip-upgrade\/","title":{"rendered":"Easy Way to Update a Python Package with Pip Upgrade"},"content":{"rendered":"\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-top\" data-payload='{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;1222091&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;top&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;1&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;5\\\/5 - (1 vote)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;width&quot;:&quot;142.5&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n<div class=\"kksr-stars\">\n<div class=\"kksr-stars-inactive\">\n<div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"kksr-stars-active\" style=\"width: 142.5px;\">\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\"> 5\/5 &#8211; (1 vote) <\/div>\n<\/p><\/div>\n<p>If you&#8217;ve ever found yourself in a situation where you need to update or upgrade a package using Python&#8217;s <code>pip<\/code>, but just can&#8217;t figure out how, don&#8217;t worry! You&#8217;re not alone.<\/p>\n<h2><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4e6.png\" alt=\"\ud83d\udce6\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> The Correct Command to Upgrade a Package<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">To upgrade a package with Python&#8217;s pip, you can use the <code>install<\/code> command along with the <code>--upgrade<\/code> or <code>-U<\/code> flag. Open a command prompt or terminal and run the following command: <code>pip install my_package -U<\/code>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install --upgrade my_package<\/pre>\n<p>or<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install -U my_package<\/pre>\n<p>Replace <code>my_package<\/code> with the name of the package or module you want to upgrade. This command will automatically <a href=\"https:\/\/blog.finxter.com\/list-how-to-check-package-version-in-python\/\" data-type=\"post\" data-id=\"496032\" target=\"_blank\" rel=\"noreferrer noopener\">check for the latest version<\/a> of the package and upgrade it if a newer version is available. If the package is already at its latest version, the command will do nothing.<\/p>\n<p>Ensure you have the appropriate permissions (e.g., administrator or <code>sudo<\/code> access) if you&#8217;re upgrading a package installed globally on your system.<\/p>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"248\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-211-1024x248.png\" alt=\"\" class=\"wp-image-1222104\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-211-1024x248.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-211-300x73.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-211-768x186.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-211.png 1463w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/p>\n<h2><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f510.png\" alt=\"\ud83d\udd10\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> Using Sudo and &#8211;user Flag<\/h2>\n<p>When upgrading a package installed globally on your system, ensure you have the appropriate permissions, such as an administrator or <code>sudo<\/code> access. However, using sudo is considered unsafe, so avoid it if possible.<\/p>\n<p>If you don&#8217;t have admin access, consider using the <code>--user<\/code> flag to install the package only for the current user:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install &lt;package_name> --upgrade --user\n<\/pre>\n<h2><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f310.png\" alt=\"\ud83c\udf10\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> Updating Pip Itself<\/h2>\n<p>Though the original question focused on updating specific packages, some users might want to update <code>pip<\/code>. To do that, use the following command:<\/p>\n<p>For Python 3.4+:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo pip3 install pip --upgrade<\/pre>\n<p>For Python 2.7:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo pip install pip --upgrade\n<\/pre>\n<h2><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f527.png\" alt=\"\ud83d\udd27\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> Extra Tip: Updating All Packages<\/h2>\n<p>If you&#8217;re looking to update all your installed packages at once, you can use the following one-liner:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">for i in $(pip list -o | awk 'NR > 2 {print $1}'); do sudo pip install -U $i; done<\/pre>\n<p>This will update all outdated packages, but remember that it will require root access.<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<p><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f389.png\" alt=\"\ud83c\udf89\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> And there you have it! You now know how to update or upgrade a package using Python&#8217;s pip. Happy coding! <img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f389.png\" alt=\"\ud83c\udf89\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/><\/p>\n<p>Make sure to check out the free Finxter cheat sheet collection (with OpenAI and basic Python cheat sheets):<\/p>\n","protected":false},"excerpt":{"rendered":"<p>5\/5 &#8211; (1 vote) If you&#8217;ve ever found yourself in a situation where you need to update or upgrade a package using Python&#8217;s pip, but just can&#8217;t figure out how, don&#8217;t worry! You&#8217;re not alone. The Correct Command to Upgrade a Package To upgrade a package with Python&#8217;s pip, you can use the install command [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857],"tags":[73,468,528],"class_list":["post-132543","post","type-post","status-publish","format-standard","hentry","category-python-tut","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/132543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=132543"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/132543\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=132543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=132543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=132543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}