[python 일반] How to Update All Python Packages : 설치된 파이썬 패키지 모두 업데이트 하기

How to Update All Python Packages

With Python, the best practice of pinning all the packages in an environment at a specific version ensures that the environment can be reproduced months or even years later. 

  • Pinned packages in a requirements.txt file are denoted by ==. For example,  requests==2.21.0. Pinned packages should never be updated except for a very good reason, such as to fix a critical bug or vulnerability.
  • Conversely, unpinned packages are typically denoted by >=, which indicates that the package can be replaced by a later version. Unpinned packages are more common in development environments, where the latest version can offer bug fixes, security patches and even new functionality.

As packages age, many of them are likely to have vulnerabilities and bugs logged against them. In order to maintain the security and performance of your application, you’ll need to update these packages to a newer version that fixes the issue. 

The pip package manager can be used to update one or more packages system-wide. However, if your deployment is located in a virtual environment, you should use the Pipenv package manager to update all Python packages. 

NOTE: be aware that upgrading packages can break your environment by installing incompatible dependencies. This is because pip and pipenv do not resolve dependencies, unlike the ActiveState Platform. To ensure your environment doesn’t break on upgrade, you can sign up for a free ActiveState Platform account and import your current requirements.txt, ready to be upgraded.

Python Package Upgrade Checklist

In general, you can use the following steps to perform a package upgrade:

1. Check that Python is installed

Before packages can be updated, ensure that a Python installation containing the necessary files needed for updating packages is in place by following the steps outlined in <Installation Requirements>

2. Get a list of all the outdated packages

To generate a list of all outdated packages:

pip list --outdated

3. Upgrade outdated packages

Depending on your operating system or virtual environment, refer to the following sections.

Update all Python Packages on Windows

The easiest way to update all packages in a Windows environment is to use pip in conjunction with Windows PowerShell: 

  1. Open a command shell by typing ‘powershell’ in the Search Box of the Task bar
  2. Enter:
    pip freeze | %{$_.split('==')[0]} | %{pip install --upgrade $_}

This will upgrade all packages system-wide to the latest version available in the Python Package Index (PyPI).

Update all Python Packages on Linux

Linux provides a number of ways to use pip in order to upgrade Python packages, including grep and awk.

To upgrade all packages using pip with grep on Ubuntu Linux:

pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U 

To upgrade all packages using pip with awk on Ubuntu Linux:

pip3 list -o | cut -f1 -d' ' | tr " " "\n" | awk '{if(NR>=3)print}' | cut -d' ' -f1 | xargs -n1 pip3 install -U 

Updating Python Packages on Windows or Linux 

Pip can be used to upgrade all packages on either Windows or Linux:

  1. Output a list of installed packages into a requirements file (requirements.txt): 
pip freeze > requirements.txt
  1. Edit requirements.txt, and replace all ‘==’ with ‘>=’. Use the ‘Replace All’ command in the editor.
  2. Upgrade all outdated packages: 
pip install -r requirements.txt --upgrade

Updating all Packages in a Virtual Environment

The easiest way to update unpinned packages (i.e., packages that do not require a specific version) in a virtual environment is to run the following Python script that makes use of pip:

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

import pkg_resources
from subprocess import callfor dist in pkg_resources.working_set:
    call("python -m pip install --upgrade " + dist.<projectname>, shell=True)

Updating all Packages in a Pipenv Environment

The simplest way to update all the unpinned packages in a specific virtual environment created with pipenv is to do the following steps:

  1. Activate the Pipenv shell that contains the packages to be upgraded:
pipenv shell
  1. Upgrade all packages:
pipenv update

Modern way to manage Python packages – ActiveState Platform

The ActiveState Platform is a cloud-based build automation and dependency management tool for Python. It provides dependency resolution for:

  • Python language cores, including Python 2.7 and Python 3.5+
  • Python packages and their dependencies, including:
    • Transitive dependencies (ie., dependencies of dependencies)
    • Linked C and Fortran libraries, so you can build data science packages
    • Operating system-level dependencies for Windows, Linux, and macOS
    • Shared dependencies (ie., OpenSSL)

The ActiveState Platform is the only Python package management solution that not only resolves dependencies but also provides workarounds for dependency conflicts.

Simply following the instruction prompts will resolve the conflict, eliminating dependency hell.

You can try the ActiveState Platform for free by creating an account using your email or your GitHub credentials.  Start by creating a new Python project, pick the latest version that applies to your project, your OS and start to add packages. Or start by simply importing your requirements.txt file and creating a Python version with all the packages you need. The Platform will automatically pick the right package versions for your environment to ensure security and reproducibility.

Watch this tutorial to learn how to use the ActiveState Platform to create a Python 3.9 environment, and then use the Platform’s Command-Line Interface (State Tool) to install and manage it.

requested packages dependenciesReady to see for yourself? You can try the ActiveState Platform by signing up for a free account using your email or GitHub credentials.

Just run the following command to install Python 3.9 and our package manager, the State Tool:

Windows

powershell -Command "& $([scriptblock]::Create((New-Object Net.WebClient).DownloadString('https://platform.activestate.com/dl/cli/install.ps1'))) -activate-default ActiveState-Labs/Python-3.9Beta"

Linux

sh <(curl -q https://platform.activestate.com/dl/cli/install.sh) --activate-default ActiveState-Labs/Python-3.9Beta

Now you can run state install <packagename>. Learn more about how to use the State Tool to manage your Python environment. Or sign up for a free demo and let us show you how it can help improve your dev team’s workflow by compiling Python packages and resolve dependencies in minutes.

 

[출처] https://www.activestate.com/resources/quick-reads/how-to-update-all-python-packages/

 

 

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
142 [Python 인터넷] PM2로 Python Flask 앱 관리하기 : Managing Python Flask App with PM2 file 졸리운_곰 2025.01.08 452
141 [Python 인터넷] Telegram bot! 봇 만들기 with 파이썬 file 졸리운_곰 2024.06.19 531
140 [Python 인터넷] python-screenshot-to-FTP /screengrab.py 졸리운_곰 2024.06.07 389
139 [Python 인터넷] IP 주소를 찾는 Python 프로그램 file 졸리운_곰 2024.06.07 365
138 [Python 인터넷] python 을 사용한 instagram (인스타그램) 자동 포스팅 : Automate Instagram Posts with Python: A Step-by-Step Guide 졸리운_곰 2024.05.19 317
137 [Python 인터넷] python 을 사용한 instagram (인스타그램) 자동 포스팅 : Automating Instagram Posts with Python: A Quick Guide file 졸리운_곰 2024.05.19 374
136 [Python 인터넷] 파이썬 셀레늄 네이버 포스트 자동 포스팅 방법 졸리운_곰 2024.05.05 442
135 [Python 인터넷] websocket을 이용한 python server에 대용량 파일 전송하기 졸리운_곰 2023.12.14 310
134 [Python 인터넷] [Python] Websocket을 사용하는 방법 file 졸리운_곰 2023.12.12 321
133 [Python 인터넷] 네이버 뉴스 기사 크롤링 졸리운_곰 2023.05.13 462
132 [Python 인터넷] 웹 페이지를 mhtml로 저장하기 python web page save as mthml 졸리운_곰 2023.04.12 448
131 [Python 인터넷] 16 - 셀레니움 이미지 크롤링, 스크롤 다운 file 졸리운_곰 2023.04.06 259
130 [Python 인터넷] 15 - 셀레니움 크롤링 (input) file 졸리운_곰 2023.04.06 406
129 [Python 인터넷] 14 - 셀레니움 click file 졸리운_곰 2023.04.06 538
128 [Python 인터넷] 13 - 셀레니움 사용해보기 file 졸리운_곰 2023.04.06 358
127 [Python 인터넷] 12 - 데이터 엑셀로 저장 file 졸리운_곰 2023.03.31 334
126 [Python 인터넷] 11 - Page 숫자 설정 file 졸리운_곰 2023.03.31 387
125 [Python 인터넷] 10 - 다음 뉴스 키워드로 크롤링 file 졸리운_곰 2023.03.30 363
124 [Python 인터넷] 9 - Flask POST file 졸리운_곰 2023.03.30 489
123 [Python 인터넷] 8 - 약간의 레이아웃 설정하기 file 졸리운_곰 2023.03.30 347
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED