pipvirtualenvpipenv

How do I create a Pipfile from an existing virtualenv?


I can't seem to find the exact answer here. Is it possible to work without requirements.txt at all?

With pip (or pipenv), if I have a virtual environment, I can generate requirements.txt easily.

But, what if I have a project where we're trying to move to using pipfiles entirely. How do I initialize the pipfile from the existing virtualenv? In such a way that I can get rid of requirements.txt


Solution

  • This worked for me:

    1. rm Pipfile
    2. rm Pipfile.lock
    3. source path/to/venv/bin/activate
    4. pip freeze > requirements.txt
    5. pipenv install -r requirements.txt
    6. rm requirements.txt
    7. Rule the world

    -- In english:

    1. Delete or rename Pipfile and Pipefile.lock
    2. Activate the virtual env
    3. Use pip freeze to create a requirements.txt file
    4. Use pipenv to install from the requirement.txt file. This initializes the Pipfile as well
    5. Delete the requirements.txt file
    6. Grab a coffee

    The generated Pipfile will be version locked, but easy to edit.