title: With pip, should I create requirements.txt from pip freeze, or by manually editing the requirements.txt file?
body: <p>For context, I don't know much about Python, let alone idiomatic Python. I'm working on a brownfield project. Everything I say about docker may be irrelevant to the question I'm asking, but I can't tell: Our code runs in a Docker container. Instead of using virtual environments, we hardcode the Python version and run this in the Dockerfile:</p>
  <pre><code>ADD requirements.txt /
  RUN pip install -r /requirements.txt \
  &amp;&amp; rm -rf /requirements.txt 
  </code></pre>
  <p>At the moment, we have two ways of adding requirements to the <code>requirements.txt</code>:</p>
  <ol>
  <li><p>By running this command (using twilio as an example):</p>
  <pre class="lang-sh prettyprint-override"><code>docker-compose run --rm django bash -c &quot;pip install twilio &amp;&amp; pip freeze &gt; requirements.txt&quot;
  </code></pre>
  </li>
  <li><p>By going to pypi.org, finding a dependency's name and current version, and manually adding that line to the hosts <code>requirements.txt</code>.</p>
  </li>
  </ol>
  <p>Both seem to work, but my gut tells me there are latent downsides to one/both of these. What are the pros and cons of each choice and which one is considered idiomatic? If neither of these are considered idiomatic, what's the right way to add to the <code>requirements.txt</code>?</p>
  <p>I've been googling, but a lot of the results are questionable because they are really old. e.g., <a href="https://pip.pypa.io/en/latest/user_guide/#changes-to-the-pip-dependency-resolver-in-20-3-2020" rel="nofollow noreferrer">pip 20.3.2020</a> added resolver functionality, and I don't know what ripples that had on best practices.</p>