xxxxxxxxxx
pip list --format=freeze > requirements.txt
xxxxxxxxxx
# Create a requirements.txt file with packages installed in your environment
pip freeze > requirements.txt
xxxxxxxxxx
# install
pip3 install pipreqs
# Run in current directory
python3 -m pipreqs.pipreqs .
xxxxxxxxxx
# install
pip3 install pipreqs
# Run in current directory
python3 -m pipreqs.pipreqs .
xxxxxxxxxx
# install
pip install --upgrade pipreqs
# run
python -m pipreqs.pipreqs . --force
xxxxxxxxxx
<table class="table">
<caption>List of users</caption>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>
xxxxxxxxxx
import subprocess
# Run pip to get the installed packages
installed_packages = subprocess.check_output(['pip', 'freeze']).decode('utf-8').split('\n')
# Write the installed packages and versions to requirements.txt
with open('requirements.txt', 'w') as file:
for package in installed_packages:
file.write(package + '\n')