'Python 'requirements.txt' file in package

SITUATION:

I have created a python package where I use the following libraries:

  1. matplotlib
  2. regex
  3. statistics
  4. os
  5. unittest
  6. coverage

my problem is that when I do pip freeze, the result only returns versions values for

  1. matplotlib==3.2.1
  2. regex==2020.11.13
  3. statistics==1.0.3.5
  4. coverage==5.3.1

I have read some sites where they say that this is because, for example, os and unittest comes already installed with Python3.X.

QUESTION:

  1. Should I include 'os', 'unittest' in 'requirements.txt'?
  2. If so, which is the version I should write?


Solution 1:[1]

You shouldn't include os and unittest in requirements.txt.

As you read, I confirm that os and unittest are included in Python 3.X.

os and unittest version depends on your Python 3.X version.

Solution 2:[2]

The source was right, you should't include os etc in your requirements.txt. Here is a little different problem with pip freeze tho - when you are not using different environments and have all the libraries in one environment, your pip freeze is gonna give you all the libraries you have inside and that is not helpful at all.

I'd recommend using pipreqs library for getting all the necessary libraries you want to put in your requirements.txt for your script.

pip install pipreqs

pipreqs /path/to/your_project

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marte Valerio Falcone
Solution 2 Leemosh