pipreqs - Generate pip requirements.txt file based on imports of any project. Looking for maintainers to move this project forward.

Overview

pipreqs - Generate requirements.txt file for any project based on imports

Installation

pip install pipreqs

Usage

Usage:
    pipreqs [options] <path>

Options:
    --use-local           Use ONLY local package info instead of querying PyPI
    --pypi-server <url>   Use custom PyPi server
    --proxy <url>         Use Proxy, parameter will be passed to requests library. You can also just set the
                          environments parameter in your terminal:
                          $ export HTTP_PROXY="http://10.10.1.10:3128"
                          $ export HTTPS_PROXY="https://10.10.1.10:1080"
    --debug               Print debug information
    --ignore <dirs>...    Ignore extra directories
    --encoding <charset>  Use encoding parameter for file open
    --savepath <file>     Save the list of requirements in the given file
    --print               Output the list of requirements in the standard output
    --force               Overwrite existing requirements.txt
    --diff <file>         Compare modules in requirements.txt to project imports.
    --clean <file>        Clean up requirements.txt by removing modules that are not imported in project.
    --no-pin              Omit version of output packages.

Example

$ pipreqs /home/project/location
Successfully saved requirements file in /home/project/location/requirements.txt

Contents of requirements.txt

wheel==0.23.0
Yarg==0.1.9
docopt==0.6.2

Why not pip freeze?

  • pip freeze only saves the packages that are installed with pip install in your environment.
  • pip freeze saves all packages in the environment including those that you don't use in your current project. (if you don't have virtualenv)
  • and sometimes you just need to create requirements.txt for a new project without installing modules.
Comments
  • Error while creating requirements.txt

    Error while creating requirements.txt

    Hello!

    C:\Users\ipetrash\Desktop\PyScripts\hideme.ru-proxy-list>pipreqs C:\Users\ipetrash\Desktop\PyScripts\hideme.ru-proxy-list
    Traceback (most recent call last):
      File "C:\Python34\lib\runpy.py", line 170, in _run_module_as_main
        "__main__", mod_spec)
      File "C:\Python34\lib\runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "C:\Python34\Scripts\pipreqs.exe\__main__.py", line 9, in <module>
      File "C:\Python34\lib\site-packages\pipreqs\pipreqs.py", line 178, in main
        init(args)
      File "C:\Python34\lib\site-packages\pipreqs\pipreqs.py", line 157, in init
        local = get_import_local(candidates)
      File "C:\Python34\lib\site-packages\pipreqs\pipreqs.py", line 112, in get_import_local
        local = get_locally_installed_packages()
      File "C:\Python34\lib\site-packages\pipreqs\pipreqs.py", line 105, in get_locally_installed_packages
        'version': package[1].replace(".dist", ""),
    IndexError: list index out of range
    

    Used for: https://github.com/gil9red/hideme.ru-proxy-list

    Sincerely yours, gil9red

    bug 
    opened by gil9red 23
  • New Option for Dynamic Versioning, e.g. wheel==0.23.*, wheel==0.* or wheel

    New Option for Dynamic Versioning, e.g. wheel==0.23.*, wheel==0.* or wheel

    Added new option "dynamic", for dynamic versioning.

    Example: wheel==0.23.0

    There will be 3 possible args for this option, micro, minor or all. The result in requirements.txt will be as below.

    • wheel==0.23.* (micro)
    • wheel==0.* (minor)
    • wheel (all)

    This will enable more targeted installations, esp if one is only looking at bug fixes, security patches or minor/micro version updates, or simply just install most recent updates.

    --no-pin option is merged within this new option as the "all" arg.

    @jcch94

    opened by mapattacker 13
  • UnicodeDecodeError: 'utf-8' codec can't decode byte

    UnicodeDecodeError: 'utf-8' codec can't decode byte

    I just installed pipreqs for the first time. This is what it does:

    $ pipreqs $(pwd)
    Traceback (most recent call last):
      File "/Users/tillmann/dev/textSum/.direnv/python-3.8.3/bin/pipreqs", line 10, in <module>
        sys.exit(main())
      File "/Users/tillmann/dev/textSum/.direnv/python-3.8.3/lib/python3.8/site-packages/pipreqs/pipreqs.py", line 470, in main
        init(args)
      File "/Users/tillmann/dev/textSum/.direnv/python-3.8.3/lib/python3.8/site-packages/pipreqs/pipreqs.py", line 406, in init
        candidates = get_all_imports(input_path,
      File "/Users/tillmann/dev/textSum/.direnv/python-3.8.3/lib/python3.8/site-packages/pipreqs/pipreqs.py", line 122, in get_all_imports
        contents = f.read()
      File "/usr/local/bin/../Cellar/[email protected]/3.8.3_2/bin/../Frameworks/Python.framework/Versions/3.8/lib/python3.8/codecs.py", line 322, in decode
        (result, consumed) = self._buffer_decode(data, self.errors, final)
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 81: invalid start byte
    

    Am I doing something wrong?

    $ neofetch           
                        'c.          [email protected] 
                     ,xNMM.          -------------------- 
                   .OMMMMo           OS: macOS Catalina 10.15.5 19F101 x86_64 
                   OMMM0,            Host: MacBookPro15,1 
         .;loddo:' loolloddol;.      Kernel: 19.5.0 
       cKMMMMMMMMMMNWMMMMMMMMMM0:    Uptime: 17 days, 14 hours, 5 mins 
     .KMMMMMMMMMMMMMMMMMMMMMMMWd.    Packages: 115 (brew) 
     XMMMMMMMMMMMMMMMMMMMMMMMX.      Shell: zsh 5.7.1 
    ;MMMMMMMMMMMMMMMMMMMMMMMM:       Resolution: [email protected], [email protected], [email protected] 
    :MMMMMMMMMMMMMMMMMMMMMMMM:       DE: Aqua 
    .MMMMMMMMMMMMMMMMMMMMMMMMX.      WM: Quartz Compositor 
     kMMMMMMMMMMMMMMMMMMMMMMMMWd.    WM Theme: Blue (Light) 
     .XMMMMMMMMMMMMMMMMMMMMMMMMMMk   Terminal: Apple_Terminal 
      .XMMMMMMMMMMMMMMMMMMMMMMMMK.   Terminal Font: HackNerdFontComplete-Regular 
        kMMMMMMMMMMMMMMMMMMMMMMd     CPU: Intel i7-8850H (12) @ 2.60GHz 
         ;KMMMMMMMWXXWMMMMMMMk.      GPU: Intel UHD Graphics 630, Radeon Pro 560X 
           .cooc,.    .,coo:.        Memory: 10080MiB / 16384MiB 
    $ python -V                      
    Python 3.8.3
    
    opened by tbrodbeck 13
  • Pipreqs missing some requirements

    Pipreqs missing some requirements

    I develop this project: https://github.com/tuwien-musicir/rp_extract

    As you can see from the imports it uses a lot of libraries (numpy, scipy, matplotlib, argparse, unicsv, cPickle, sklearn, ...) - many of which are missed by pipreqs:

    pipreqs --debug --force . DEBUG: Found packages: set(['argparse', 'cPickle', 'uuid', 'tempfile', 'numpy', 'pylab', 'matplotlib', 'wave', 'sys', 'subprocess', 'os', 'sklearn']) DEBUG: Found imports: matplotlib, numpy, matplotlib, scikit_learn DEBUG: Getting packages information from Local/PyPI INFO: Starting new HTTPS connection (1): pypi.python.org DEBUG: Setting read timeout to None DEBUG: "GET /pypi/numpy/json HTTP/1.1" 200 65657 INFO: Starting new HTTPS connection (1): pypi.python.org DEBUG: Setting read timeout to None DEBUG: "GET /pypi/scikit_learn/json HTTP/1.1" 301 0 DEBUG: Setting read timeout to None DEBUG: "GET /pypi/scikit-learn/json HTTP/1.1" 200 102410 DEBUG: Writing 4 requirements: matplotlib, matplotlib, numpy, scikit_learn to ./requirements.txt INFO: Successfully saved requirements file in ./requirements.txt [email protected]:~/rp_extract$ cat requirements.txt matplotlib == 1.3.1.egg matplotlib == 1.3.1.egg numpy == 1.10.1 scikit_learn == 0.17

    Why does it miss many of the library requirements? (some of them are even mentioned in the debug output, some are not, e.g. scipy, unicsv) (and matplotlib on the other hand is put twice into the requirements.txt)

    bug 
    opened by audiofeature 10
  • Error executing newly installed pipreqs

    Error executing newly installed pipreqs

    I installed pipreqs using pip install pipreqs within my local virtualenv and then executed it, got this error:

    ~/code % pipreqs web
    Looking for imports
    Traceback (most recent call last):
      File "/home/satiani/code/web/venv/bin/pipreqs", line 8, in <module>
        load_entry_point('pipreqs==0.1.8', 'console_scripts', 'pipreqs')()
      File "/home/satiani/code/web/venv/local/lib/python2.7/site-packages/pipreqs/pipreqs.py", line 109, in main
        init(args)
      File "/home/satiani/code/web/venv/local/lib/python2.7/site-packages/pipreqs/pipreqs.py", line 92, in init
        imports = get_all_imports(args['<path>'])
      File "/home/satiani/code/web/venv/local/lib/python2.7/site-packages/pipreqs/pipreqs.py", line 62, in get_all_imports
        with open(os.path.join(os.path.dirname(__file__), "stdlib"), "r") as f:
    IOError: [Errno 2] No such file or directory: '/home/satiani/code/web/venv/local/lib/python2.7/site-packages/pipreqs/stdlib'
    zsh: exit 1     pipreqs web
    
    bug 
    opened by satiani 10
  • -bash: pipreqs: command not found

    -bash: pipreqs: command not found

    When I try to run the pipreqs from cli, I got ther is no command found. I miss something? The installation process and the usage is jus this:

    $ pip install pipreqs
    $ pipreqs [path/to/project]
    
    opened by varadig 9
  • Difference between package name and import name makes problem

    Difference between package name and import name makes problem

    For example, to import beautifulsoup4 package, it should be import bs4. So pipreqs cannot find the beautifulsoup4 package from pypi server. I don't have an idea to resolve this problem... :(

    bug 
    opened by littmus 9
  • whitelines at the beginning of the file

    whitelines at the beginning of the file

    pipreqs fails on python files which have blank lines at the beginning of the file.

    System:

    • Python 3.6.8
    • 16.04.1-Ubuntu
    • pipreqs 0.4.10

    Stacktrace:

    ERROR: Failed on file: /home/test/file.py
    Traceback (most recent call last):
      File "/usr/local/bin/pipreqs", line 10, in <module>
        sys.exit(main())
      File "/usr/local/lib/python3.6/dist-packages/pipreqs/pipreqs.py", line 470, in main
        init(args)
      File "/usr/local/lib/python3.6/dist-packages/pipreqs/pipreqs.py", line 409, in init
        follow_links=follow_links)
      File "/usr/local/lib/python3.6/dist-packages/pipreqs/pipreqs.py", line 138, in get_all_imports
        raise exc
      File "/usr/local/lib/python3.6/dist-packages/pipreqs/pipreqs.py", line 124, in get_all_imports
        tree = ast.parse(contents)
      File "/usr/lib/python3.6/ast.py", line 35, in parse
        return compile(source, filename, mode, PyCF_ONLY_AST)
      File "<unknown>", line 1
        
        ^
    SyntaxError: invalid character in identifier
    
    opened by EliasVansteenkiste 8
  • Is there a way to output >= instead of == in requirements.txt?

    Is there a way to output >= instead of == in requirements.txt?

    Is there a way to output >= instead of == in requirements.txt?

    pygsheets>=1.1.3
    retrying>=1.3.3
    

    Instead of

    pygsheets==1.1.3
    retrying==1.3.3
    

    Thanks!

    opened by philipperemy 8
  • Exception when 'import' is used in comments

    Exception when 'import' is used in comments

    A freshly installed pipreqs (in a venv) crashes on pylint source (in a venv in my case)

    Offending line is: https://bitbucket.org/logilab/pylint/src/cc5990f6a12a467d09567bfc1b210ba999f6cb13/pylint/test/functional/unused_import.py?at=default#cl-3

    ~/src/c3 $ pipreqs .
    Traceback (most recent call last):
      File "/home/koert/src/c3/.ve2/bin/pipreqs", line 11, in <module>
        sys.exit(main())
      File "/home/koert/src/c3/.ve2/local/lib/python2.7/site-packages/pipreqs/pipreqs.py", line 167, in main
        init(args)
      File "/home/koert/src/c3/.ve2/local/lib/python2.7/site-packages/pipreqs/pipreqs.py", line 139, in init
        candidates = get_all_imports(args['<path>'])
      File "/home/koert/src/c3/.ve2/local/lib/python2.7/site-packages/pipreqs/pipreqs.py", line 48, in get_all_imports
        res = map(get_name_without_alias, item.split(","))
      File "/home/koert/src/c3/.ve2/local/lib/python2.7/site-packages/pipreqs/pipreqs.py", line 130, in get_name_without_alias
        name = REGEXP[0].match(name.strip()).groups(0)[0]
    AttributeError: 'NoneType' object has no attribute 'groups'
    ~/src/c3 $ pip freeze
    docopt==0.6.2
    pipreqs==0.2.4
    requests==2.7.0
    yarg==0.1.9
    
    bug 
    opened by kvdveer 8
  • Incorret package included for Hydra

    Incorret package included for Hydra

    I'm using Facebook hydra-core package (see Hydra.cc). But this package is not correctly handled because of another package with the same name (hydra - the python bloom filter).

    Example

    # content of my.py, the only file in my dir to show the behavior with pipreqs
    import hydra
    
    if __name__ == "__main__":
        print(hydra.__version__)
    

    Case 1:

    Only hydra-core is locally installed

    # Name Version Build Channel hydra-core 1.0.6 pypi_0 pypi

    Then output of pipreqs --print is:

    hydra_core==1.0.6
    hydra==2.5
    INFO: Successfully output requirements
    

    And output of pipreqs --print --use-local is:

    hydra_core==1.0.6
    INFO: Successfully output requirements
    

    Case 2:

    When both hydra-core and hydra are installed (this easily happens to anyone using fb hydra-core package because of accidentally using pip install hydra instead of pip install hydra-core), then for both commands (with and without --use-local flag) the output is following:

    Hydra==2.5
    INFO: Successfully output requirements
    

    Question

    I was thinking about updating mapping with a line of hydra:hydra-core (similarly to https://github.com/bndr/pipreqs/pull/234). Is that the right way how to deal with this issue? I was just a bit wondering about this since the behavior described above was quite strange to me (I was also confused with e.g. why hydra starts sometimes with capital letter and sometimes not).

    Environment

    Python 3.8.6 pipreqs 0.4.10

    opened by sxooler 7
  • Bump wheel from 0.23.0 to 0.38.1

    Bump wheel from 0.23.0 to 0.38.1

    Bumps wheel from 0.23.0 to 0.38.1.

    Changelog

    Sourced from wheel's changelog.

    Release Notes

    UNRELEASED

    • Updated vendored packaging to 22.0

    0.38.4 (2022-11-09)

    • Fixed PKG-INFO conversion in bdist_wheel mangling UTF-8 header values in METADATA (PR by Anderson Bravalheri)

    0.38.3 (2022-11-08)

    • Fixed install failure when used with --no-binary, reported on Ubuntu 20.04, by removing setup_requires from setup.cfg

    0.38.2 (2022-11-05)

    • Fixed regression introduced in v0.38.1 which broke parsing of wheel file names with multiple platform tags

    0.38.1 (2022-11-04)

    • Removed install dependency on setuptools
    • The future-proof fix in 0.36.0 for converting PyPy's SOABI into a abi tag was faulty. Fixed so that future changes in the SOABI will not change the tag.

    0.38.0 (2022-10-21)

    • Dropped support for Python < 3.7
    • Updated vendored packaging to 21.3
    • Replaced all uses of distutils with setuptools
    • The handling of license_files (including glob patterns and default values) is now delegated to setuptools>=57.0.0 (#466). The package dependencies were updated to reflect this change.
    • Fixed potential DoS attack via the WHEEL_INFO_RE regular expression
    • Fixed ValueError: ZIP does not support timestamps before 1980 when using SOURCE_DATE_EPOCH=0 or when on-disk timestamps are earlier than 1980-01-01. Such timestamps are now changed to the minimum value before packaging.

    0.37.1 (2021-12-22)

    • Fixed wheel pack duplicating the WHEEL contents when the build number has changed (#415)
    • Fixed parsing of file names containing commas in RECORD (PR by Hood Chatham)

    0.37.0 (2021-08-09)

    • Added official Python 3.10 support
    • Updated vendored packaging library to v20.9

    ... (truncated)

    Commits
    • 6f1608d Created a new release
    • cf8f5ef Moved news item from PR #484 to its proper place
    • 9ec2016 Removed install dependency on setuptools (#483)
    • 747e1f6 Fixed PyPy SOABI parsing (#484)
    • 7627548 [pre-commit.ci] pre-commit autoupdate (#480)
    • 7b9e8e1 Test on Python 3.11 final
    • a04dfef Updated the pypi-publish action
    • 94bb62c Fixed docs not building due to code style changes
    • d635664 Updated the codecov action to the latest version
    • fcb94cd Updated version to match the release
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • How can I include pipreqs in my requirements.txt file. (so meta, I know)

    How can I include pipreqs in my requirements.txt file. (so meta, I know)

    Is there a way to include additional packages in the requirements.txt file that are not imported into the project? For example, including pipreqs in the outputted requirements.txt.

    Thanks!

    opened by nodesocket 1
  • "pipreqs --encoding=utf8 --force ." return error

    Hi, when I do this command : pipreqs --encoding=utf8 --force . I have this error : 'utf-8' codec can't decode byte 0xf6 in position 122: invalid start byte. I tried without the encoding, and I have the charmap error. i tried with utf16, other error. Do you know why ?

    opened by Impre-visible 0
  • pipreqs --savepath always overwrite despite i'm not using --force

    pipreqs --savepath always overwrite despite i'm not using --force

    Hi,

    i'm actually using pipreqs to generate a requirements.in file and then use pip-tools on it.

    My issue is that using pipreqs --savepath requirements.in is overwriting my existing requirements.in file, even if i do not use the --force option.

    Any idea why this is happening? Is there a way to just append the new requirements pipreqs finds without overwriting the existing ones? (Some i added by hand, so they get deleted everytime).

    This does not happen when using pipreqs to generate the "default" requirements.txt, so the issue is only when specifying a custom file name with --savepath.

    Thank you.

    opened by steakhutzeee 0
Releases(v0.4.11)
Owner
Vadim Kravcenko
CTO @ Mindnow AG
Vadim Kravcenko
Python Environment & Package Manager

Python Environment Manager A Visual Studio Code extension that provides the ability to via and manage all of your Python environments & packages from

Don Jayamanne 72 Dec 29, 2022
pip-run - dynamic dependency loader for Python

pip-run provides on-demand temporary package installation for a single interpreter run. It replaces this series of commands (or their Windows equivale

Jason R. Coombs 79 Dec 14, 2022
Python dependency management and packaging made easy.

Poetry: Dependency Management for Python Poetry helps you declare, manage and install dependencies of Python projects, ensuring you have the right sta

Poetry 23.1k Jan 01, 2023
If you have stars in your Pipfile and you don't want them, this project is for you!

unstar-pipfile If you have stars in your Pipfile, this project is for you! unstar-pipfile is a tool to scan Pipfile.lock and replace any stars in Pipf

2 Jul 26, 2022
Python dependency management and packaging made easy.

Poetry: Dependency Management for Python Poetry helps you declare, manage and install dependencies of Python projects, ensuring you have the right sta

Poetry 23.2k Jan 05, 2023
Easy to use, fast, git sourced based, C/C++ package manager.

Yet Another C/C++ Package Manager Easy to use, fast, git sourced based, C/C++ package manager. Features No need to install a program, just include the

31 Dec 21, 2022
Python PyPi staging server and packaging, testing, release tool

devpi: PyPI server and packaging/testing/release tool This repository contains three packages comprising the core devpi system on the server and clien

629 Jan 01, 2023
Simple Library Management made with Python

Installation pip install mysql-connector-python NOTE: You must make a database (library) & and table (books, student) to hold all data. Languange and

SonLyte 10 Oct 21, 2021
A Poetry plugin for dynamically extracting the package version.

Poetry Version Plugin A Poetry plugin for dynamically extracting the package version. It can read the version from a file __init__.py with: # __init__

Sebastián Ramírez 264 Dec 22, 2022
A tool to upgrade dependencies to the latest versions

pip-check-updates A tool to upgrade dependencies to the latest versions, inspired by npm-check-updates Install From PyPi pip install pip-check-updates

Zeheng Li 12 Jan 06, 2023
Dotpkg - Package manager for your dotfiles

Dotpkg A package manager for your dotfiles. Usage First make sure to have Python

FW 4 Mar 18, 2022
A set of tools to keep your pinned Python dependencies fresh.

pip-tools = pip-compile + pip-sync A set of command line tools to help you keep your pip-based packages fresh, even when you've pinned them. You do pi

Jazzband 6.5k Dec 29, 2022
Package manager based on libdnf and libsolv. Replaces YUM.

Dandified YUM Dandified YUM (DNF) is the next upcoming major version of YUM. It does package management using RPM, libsolv and hawkey libraries. For m

1.1k Dec 26, 2022
The Fast Cross-Platform Package Manager

The Fast Cross-Platform Package Manager part of mamba-org Package Manager mamba Package Server quetz Package Builder boa mamba Mamba is a reimplementa

Mamba 4k Dec 30, 2022
The Python package installer

pip - The Python Package Installer pip is the package installer for Python. You can use pip to install packages from the Python Package Index and othe

Python Packaging Authority 8.4k Dec 30, 2022
Template repo for a GCP-hosted REST API with automatic API versioning and custom domain mapping

Python + Poetry REST API with FastAPI, hosted on GCP This template will get you ready to deploy a FastAPI app in Google Cloud with automatic API versi

Kevin Duff 10 Dec 25, 2022
Conan - The open-source C/C++ package manager

Conan Decentralized, open-source (MIT), C/C++ package manager. Homepage: https://conan.io/ Github: https://github.com/conan-io/conan Docs: https://doc

Conan.io 6.5k Jan 05, 2023
Workon - A simple project manager for conda, windows 10 and vscode

WORK ON A simple project manager for conda, windows 10 and vscode Installation p

Jesus Alan Hernandez Galvan 1 Jan 16, 2022
Cilantropy: a Python Package Manager interface created to provide an "easy-to-use" visual and also a command-line interface for Pythonistas.

Cilantropy Cilantropy is a Python Package Manager interface created to provide an "easy-to-use" visual and also a command-line interface for Pythonist

48 Dec 16, 2022
Library Management System

Library Management Library Management System How to Use run main.py python file. python3 main.py Links Download Source Code: Click Here My Github Aco

Mohammad Dori 3 Jul 15, 2022