'Dependencies library at the top of requirements.txt

I created a file requirements.txt with the command pipdeptree | grep -P '^\w+' > requirements.txt. However, I would like to have a requirements file being organized in a such a way that all the dependencies libraries are at the top of the file, so that when trying to install a library I'm sure that all of its dependecies are already present in the environment. Is there a way to organize the requirements file such?

Thanks



Sources

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

Source: Stack Overflow

Solution Source