Most of the time, I use pipreqs
to generate a requirements.txt
file so anyone can reproduce the working environment on their side based on that requirements file.
Here I am facing a case where there is a missing package requirement in the file generated by pipreqs, so the code is not running out of the box in a freshly created environment using the requirements.txt
file.
ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.
The missing package is openpyxl
which is an optional dependency of pandas
.
>>> import pandas as pd
>>> pd.show_versions()
INSTALLED VERSIONS
------------------
commit : 5f648bf1706dd75a9ca0d29f26eadfbb595fe52b
python : 3.9.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19042
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 13, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : English_Canada.1252
pandas : 1.3.2
numpy : 1.21.4
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3.1
setuptools : 59.6.0
Cython : None
... ...
openpyxl : None <== HERE!
... ...
numba : None
Indeed, the content of the generated requirements.txt
file does not contain openpyxl
, but contains pandas
:
pandas==1.3.2
plotly==5.4.0
Is there a way that pipreqs
could outputs the pandas
dependencies in the generated requirements.txt
file so I don't have to enter it manually?
NOTE: I know about pip freeze > requirements.txt
but I don't like that method since it generates requirements based on the installed packages in the environment, which many of them may not be required to run the code.