question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

create requirements.txt without virtualenv?

See original GitHub issue

hi! Is there a way to create a requrirements.txt file without creating a virtualenv? I’m trying to build a series of lambdas that each have separate Pipfiles.

After cding into each lambdas fodler, I’m running pipenv lock -r | pip install -r /dev/stdin --target src. Unfortunately, it creates a virtualenv per invocation which wastes time.

Is there an easy way to just translate the Pipfile.lock -> requirements.txt format without creating the virtualenv?

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:15 (13 by maintainers)

github_iconTop GitHub Comments

7reactions
petergaultneycommented, Aug 29, 2019

here’s a slightly more full-featured version of @uranusjr 's workaround for this issue, which I would still love to see the pipenv maintainers reconsider.

def pipenv_lock(lockfile: str):
    """If you rely on `pipenv lock -r to do this for you, it will force-create a venv for you.
     This is a workaround that gives the same result.
    """
    from pipenv.vendor.requirementslib import Requirement
    # this is imported late because it very rudely does a basicConfig on logging
    # which will prevent basicConfig in your own scripts from taking effect
    section = 'default' if lockfile == 'requirements.txt' else 'develop'
    with open('Pipfile.lock') as f:
        with open(lockfile, 'w') as outf:
            data = json.load(f)
            for source in data.get('_meta', {}).get('sources', []):
                url = source['url']
                if source['name'] == 'pypi':
                    outf.write(f'-i {url}\n')
                else:
                    outf.write(f'--extra-index-url {url}\n')
            for name, entry in data[section].items():
                r = Requirement.from_pipfile(name, entry)
                outf.write(r.as_line() + '\n')
5reactions
AlJohricommented, Sep 2, 2018

Why would you do that?

AWS Lambda requires a flat folder with all packages installed. I’m running the same command (pipenv lock -r | pipenv run pip install -r /dev/stdin --target src) in production on codepipeline and for local development via the aws-sam-cli.

Locally, I need to prefix pipenv run to pip install so that pip doesn’t see my globally installed packages. Otherwise, locally, I get weird issues like:

awscli 1.15.83 has requirement botocore==1.10.82, but you'll have botocore 1.11.6 which is incompatible.

In production, the virtualenv doesn’t exist so the weird parallel creation of virtualenv occurs.

Might be too much of an edgecase.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Automatically create requirements.txt - Stack Overflow
Use virtualenv and pip3 freeze > requirements.txt. Let me explain: pipreqs only saves packages which are imported in project, not their dependencies. Sometimes ......
Read more >
How to Generate Requirements.txt for Your Python Project
A guide to generating Requirements.txt for Python project.
Read more >
Why and How to make a Requirements.txt - Robert Boscacci
This is where a requirements.​​ As long as the developers of this app provide a file listing the necessary packages, we can simply...
Read more >
How to Create Requirements.txt File In Python - JCharisTech
How to Get the Requirements.txt File: Without VirtualEnv using Pipreqs. Pipreqs is the other simple alternative to use that doesn't require you ...
Read more >
How to Create Requirements.txt File in Python - Javatpoint
The main reason behind this is that all users do not use the same version of libraries and packages. However, if you used...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found