Как обновить requirements txt python
Перейти к содержимому

Как обновить requirements txt python

  • автор:

 

How to Update Requirements Files¶

The different requirements files introduced in Software Process section are the following:

requirements.txt¶

requirements.txt of the project can be created or updated and then captured using the following script:

requirements-(dev|doc).txt¶

Any of these requirements files can be updated using the following scripts:

requirements-min.txt¶

Minimum requirements should be updated manually if a new feature or bug fix is added in a dependency that is required for proper running of PyNWB. Minimum requirements should also be updated if a user requests that PyNWB be installable with an older version of a dependency, all tests pass using the older version, and there is no valid reason for the minimum version to be as high as it is.

© Copyright 2017-2023, Neurodata Without Borders. Revision 71d880ab .

How to Update all Python Packages with a Single pip Command

Ensure all present Python packages on Windows and Linux systems are parallel with their latest available versions from the command line.

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.

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 “[Using Python on Windows]” in the official documentation.

2. Get a list of all the outdated packages

To generate a list of all outdated packages:

3. Upgrade outdated packages

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

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:

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:

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

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):
  1. Edit requirements.txt, and replace all == with >= . Use the Replace All command in the editor.
  2. Upgrade all outdated packages:

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:

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:

Name already in use

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.rst

Update the packages in a requirements.txt file.

Give pur your requirements.txt file and it updates all your packages to the latest versions.

For example, given a requirements.txt file:

Running pur on that file updates the packages to current latest versions:

как вы обновляете requirements.txt?

Возникла задача обновить requirements.txt . А проблема в том что он содержит как прямые зависимости проекта, так и зависимости зависимостей. Мне бы хотелось обновить прямые зависимости до конкретных версий, а все остальные поставить самые последние (чтобы, скажем, получить все security fixes и прочее). Как бы это сделать?

Ну или поделитесь своим опытом обновления requirements.txt . Я пока не придумал ничего лучше как начать с пустого virtualenv и добавлять пакеты пока проект не станет запускаться. Но мне этот подход не нравится, например, тем что

1) это ручная работа

2) иногда import попадается в середине кода. А покрытие тестами пока хромает чтобы надёжно выявить такие дурацкие проблемы (но мы над этим работаем).

 

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *