Hey Guys, So I recently had the problem of moving from one python environment to another due to some issue with my computer. Now the problem was that I had tons of packages already installed on my python environment, now pip installing each package again would be more than a day’s task.
So I came across the use of requirements.txt file. The concept is simple – a requirements file would include all the packages and versions of the packages already installed on your working environment and giving this file to your new python environment would result in automatic installation of all packages and dependencies mentioned in the requirements file.
How do I create a requirements file?
To see all the packages already installed in your work environment, All you need to do is:
pip list

Now you can either copy all the requirements shown into a txt file or you can ask the command prompt to do it for you. If you are going for the first just copy the package names and versions into a text file like this:
alabaster 0.7.12
anaconda-client 1.7.2
anaconda-navigator 1.9.7
anaconda-project 0.8.3
asn1crypto 1.0.1
astroid 2.3.1
astropy 3.2.1
atomicwrites 1.3.0
attrs 19.2.0
Babel 2.7.0
Alternatively, just type this command and you will get the requirements text file generated by typing:
pip freeze > requirements.txt

This will create a requirements.txt file at your base directory. Navigate there and get the file.
Now to install the same packages from your working environment into your new environment, all you need to do is paste the requirements file you just generated into your new computer or new directory.
Open the command prompt for that python environment and navigate to the new directory where you had saved your requirements file. Then type the command below:
pip install -r requirements.txt
Any package you fail to install, just remove that from the requirements file and rerun the above command. Trust me this will save loads of your time.
Another time saver is to just remove the installed package names from your requirements.txt file. This will save time by not retrying/rechecking to see if the package has been installed.
This helped me save loads of my time. Hope it helps you too.