{"id":6314,"date":"2017-07-07T09:46:08","date_gmt":"2017-07-07T13:46:08","guid":{"rendered":"https:\/\/qxf2.com\/blog\/?p=6314"},"modified":"2018-04-02T10:35:58","modified_gmt":"2018-04-02T14:35:58","slug":"auto-generate-requirements-txt-file-using-pipreqs","status":"publish","type":"post","link":"https:\/\/qxf2.com\/blog\/auto-generate-requirements-txt-file-using-pipreqs\/","title":{"rendered":"Auto-generate requirements.txt file using pipreqs"},"content":{"rendered":"<p>At <a href=\"http:\/\/www.qxf2.com\/?utm_source=pipreqs&#038;utm_medium=click&#038;utm_campaign=From%20blog\">Qxf2<\/a>, we love Python. We use Python on multiple projects and as per our requirements, we install multiple modules. But, I found it difficult to create a <a href=\"https:\/\/pip.readthedocs.io\/en\/1.1\/requirements.html\">requirements.txt file<\/a> for specific projects manually. So I searched for a tool\/technique to generate a requirement.txt file. I come across the <a href=\"https:\/\/github.com\/bndr\/pipreqs\">pipreqs<\/a> package, which generates a requirement.txt file based on the import statements of the project. I like it because it is helpful in maintaining the requirements file, easy to use and saves me a lot of time.<\/p>\n<hr \/>\n<h3>Setup:<\/h3>\n<p>To get setup with the pipreqs, you need to install the pipreqs package using the following command.<\/p>\n<pre lang=\"python\">pip install pipreqs<\/pre>\n<hr \/>\n<h3>Usage:<\/h3>\n<p>Usage of the pipreqs is very easy. You just need to provide the root location of your project and the pipreqs automatically generate a requirements.txt file in root folder. Use the following command for usage.<\/p>\n<pre lang=\"python\">pipreqs \/path\/to\/project<\/pre>\n<p>The following Fig. 1 shows a snapshot of how I generated a requirements.txt file for our <a href=\"https:\/\/github.com\/qxf2\/qxf2-page-object-model\">Qxf2&#8217;s public POM<\/a>.<\/p>\n<figure id=\"attachment_6323\" aria-describedby=\"caption-attachment-6323\" style=\"width: 883px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/06\/pipreqs_auto_generate_requirements_file.png\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-6323\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/06\/pipreqs_auto_generate_requirements_file.png\" alt=\"\" width=\"883\" height=\"65\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/06\/pipreqs_auto_generate_requirements_file.png 883w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/06\/pipreqs_auto_generate_requirements_file-300x22.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/06\/pipreqs_auto_generate_requirements_file-768x57.png 768w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><\/a><figcaption id=\"caption-attachment-6323\" class=\"wp-caption-text\">Fig.1 pipreqs to auto generate a requirement.txt file<\/figcaption><\/figure>\n<p><strong>The content of auto-generated requirement.txt:<\/strong><\/p>\n<pre lang=\"python\">requests==2.9.1\r\npytest==3.0.5\r\nselenium==3.4.3\r\nmechanize==0.2.5\r\npython_dotenv==0.1.0\r\nAppium_Python_Client==0.24\r\ndotenv==0.0.5\r\n<\/pre>\n<hr \/>\n<h3>Limitations:<\/h3>\n<p>Pipreqs uses imports of projects to generate a requirements.txt file. So, it is very important to note that, pipreqs will not include\u00a0the plugins required for specific projects. You need to add plugins information manually in a requirement.txt.<\/p>\n<p>In our case, I need to add pytest-xdist\u00a0plugin details in a requirement.txt file manually.<\/p>\n<p><strong>If you are a startup finding it hard to hire technical QA engineers, learn more <a href=\"https:\/\/qxf2.com\/blog\/about-qxf2\/\">about Qxf2 Services<\/a>.<\/strong><\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>At Qxf2, we love Python. We use Python on multiple projects and as per our requirements, we install multiple modules. But, I found it difficult to create a requirements.txt file for specific projects manually. So I searched for a tool\/technique to generate a requirement.txt file. I come across the pipreqs package, which generates a requirement.txt file based on the import [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[107,18],"tags":[],"class_list":["post-6314","post","type-post","status-publish","format-standard","hentry","category-pytest","category-python"],"_links":{"self":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/6314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/comments?post=6314"}],"version-history":[{"count":4,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/6314\/revisions"}],"predecessor-version":[{"id":6392,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/6314\/revisions\/6392"}],"wp:attachment":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/media?parent=6314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/categories?post=6314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/tags?post=6314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}