Search code examples
pythonpipvirtualenv

How to create requirement.txt without all package versions


Right now my requirement.txt contains following package list:

asgiref==3.2.3
beautifulsoup4==4.8.2
certifi==2019.11.28
chardet==3.0.4
Click==7.0
Django==3.0.2
idna==2.8
pytz==2019.3
requests==2.22.0
six==1.14.0
soupsieve==1.9.5
sqlparse==0.3.0
urllib3==1.25.7

I just want the package name only, so that pip3 always installs the latest version.


Solution

  • Use sed to remove version info from your requirements.txt file. e.g.

    sed 's/==.*$//' requirements.txt
    

    will give output

    asgiref
    beautifulsoup4
    certifi
    chardet
    Click
    Django
    idna
    pytz
    requests
    six
    soupsieve
    sqlparse
    urllib3
    

    and this can be piped into pip to do the install

    sed 's/==.*$//' requirements.txt | xargs pip install