python generate requirements.txt code example

Example 1: command to make requirements.txt

pip freeze > requirements.txt

Example 2: pip freeze requirements.txt

$ env1/bin/pip freeze > requirements.txt
$ env2/bin/pip install -r requirements.txt

Example 3: how to generate requirements.txt django

For Unix families: pip3 freeze > requirements.txt
For Windos: pip freeze > requirements.txt

Example 4: python generate uid

# Python3 code to generate the 
# random id using uuid1() 
  
import uuid 
  
# Printing random id using uuid1() 
print ("The random id using uuid1() is : ",end="") 
print (uuid.uuid1())

Example 5: python generate requirements.txt

# First:
pip install pipreqs

# Then:
pipreqs path/to/project

# There is now a requirements.txt file in the project folder.

Example 6: generate binay image python

import numpy as np
from numpy import random

# Generating an image of values between 1 and 255. 
im_thresh = random.randint(1,256, (64,64))

# Set anything less than 255 to 0. Unnecessary if cv2 does this during threshold. 
# Must go before the operation below in order not to set all values to 0. 
im_thresh[im_thresh<255] = 0

# Set all values at indices where the array equals 255 to 1.
im_thresh[im_thresh==255] = 1