logo

Python - Environment

Last Updated: 2024-01-20

PYTHONHASHSEED

Python 3.3 and greater, hash randomization is turned on by default.

On previous versions of Python, this option turns on hash randomization, so that the hash() values of str, bytes and datetime are “salted” with an unpredictable random value. Although they remain constant within an individual Python process, they are not predictable between repeated invocations of Python.

Hash randomization is intended to provide protection against a denial-of-service caused by carefully-chosen inputs that exploit the worst case performance of a dict construction, O(n^2) complexity.

PYTHONHASHSEED allows you to set a fixed value for the hash seed secret.

To disable randomized hash for string in Python 3.3+

export PYTHONHASHSEED=0

Check OS Version

>>> import os
>>> os.environ

Check path

where the installed site-packages are found

>>> import sys
>>> sys.path