Freeze in Python

Pip freeze vs. pip list

One may generate a requirements.txt via:

$ pip freeze > requirements.txt

A user can use this requirements.txt file to install all the dependencies. For instance:

$ pip install -r requirements.txt

The packages need to be in a specific format for pip to understand, such as:

# requirements.txt
feedparser==5.1.3
wsgiref==0.1.2
django==1.4.2
...

That is the "requirements format".

Here, django==1.4.2 implies install django version 1.4.2 (even though the latest is 1.6.x).
If you do not specify ==1.4.2, the latest version available would be installed.

You can read more in "Virtualenv and pip Basics",
and the official "Requirements File Format" documentation.

Using `pip freeze requirements` in Python code

Redirection is implemented in the shell/terminal, that means the command must be executed in the shell using shell=True keyword argument. Otherwise subprocess executes the first item in the list and uses the rest as arguments to it. See the documentation for subprocess for more information.

subprocess.call("pip freeze > requirements.txt", shell=True)

Pip freeze --local

Pip is a package manger for Python modules. The command pip freeze outputs all installed modules (including version numbers). The --local flag prevents Pip from printing globally installed packages in a virtual environment.

Usually, a Python program depends on other modules. You can put those required modules in a text file (requirements.txt by convention) so that other people can install those dependencies by running pip install -r requirements.txt. You can conveniently create such a file using pip freeze.

On a Linux machine, cat is used to output the contents of a file. You can use type on Windows.

The requirements format looks like this:

docutils==0.11
Jinja2==2.7.2
MarkupSafe==0.19
Pygments==1.6
Sphinx==1.2.2

Each lines consist of a python module name and a corresponding version.


https://pip.pypa.io/en/stable/reference/pip_freeze/

https://pip.readthedocs.io/en/1.1/requirements.html

Pip freeze shows a weird version of a package

As @Corralien pointed out it's not that weird to have a post-release version of something: https://www.python.org/dev/peps/pep-0440/#version-scheme

Post-releases are usually made to make some minor change to the released package that does not affect the code necessarily (e.g. a typo in the readme, or some other minor packaging bug).

It is a little weird in this case because on PyPI there is no 52.0.0.post20210125 release for setuptools. There is, however, a 51.1.0.post20201221 release which was apparently made by mistake.

I don't know how you ended up with the one you have though. It does not appear to exist (maybe it was deleted).

You should try upgrading setuptools before freezing your pip environment since the one you have is outdated anyways.

pip freeze creates some weird path instead of the package version

It looks like this is an open issue with pip freeze in version 20.1, the current workaround is to use:

pip list --format=freeze > requirements.txt

In a nutshell, this is caused by changing the behavior of pip freeze to include direct references for distributions installed from direct URL references.

You can read more about the issue on GitHub:

pip freeze does not show version for in-place installs

Output of "pip freeze" and "pip list --format=freeze" differ for packages installed via Direct URLs

Better freeze of distributions installed from direct URL references

How to freeze windows 10 screen with Python?

You can do this with a mixture root.attributes() and root.protocol().

If you wanted a button to give you back control in your GUI, say after you had completed your tasks, you could use something like this:

import tkinter as tk

def foo():
pass
root = tk.Tk()
root.attributes("-fullscreen", True, "-topmost", True)
root.protocol("WM_DELETE_WINDOW", foo)

but = tk.Button(root, text = "I have completed my tasks", command=root.destroy)
but.grid()

root.mainloop()

Or if you wanted a simple timer-activated screen that shuts off after a set time:

import tkinter as tk

root = tk.Tk()
root.attributes("-fullscreen", True, "-topmost", True, "-disabled", True)

time_interrupt = 5000 # Time screen is active in ms
root.after(time_interrupt, root.destroy)

root.mainloop()

Note these only work properly for a single screen, if you have multiple screens it may potentially work but you will likely need to add more code.



Related Topics



Leave a reply



Submit