• Python生成项目依赖包文件requirements.txt


    方法一:使用pip freeze > requirements.txt

    Microsoft Windows [版本 10.0.17763.914]
    (c) 2018 Microsoft Corporation。保留所有权利。
    
    D:devdev_pydeving>
    
    
    
    D:devdev_pydeving>
    D:devdev_pydeving>python
    Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] :: Anaconda, Inc. on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> quit()
    
    D:devdev_pydeving>python -m pip freeze > requirements.txt
    
    

    方法二:使用pipreqs

    D:devdev_pydeving>
    D:devdev_pydeving>
    D:devdev_pydeving>python -m pip install pipreqs
    Looking in indexes: http://pypi.douban.com/simple
    Collecting pipreqs
      Downloading http://pypi.doubanio.com/packages/9b/83/b1560948400a07ec094a15c2f64587b70e1a5ab5f7b375ba902fcab5b6c3/pipreqs-0.4.10-py2.py3-none-any.whl
    Requirement already satisfied: docopt in c:usersxhanaconda3libsite-packages (from pipreqs) (0.6.2)
    Collecting yarg (from pipreqs)
      Downloading http://pypi.doubanio.com/packages/8b/90/89a2ff242ccab6a24fbab18dbbabc67c51a6f0ed01f9a0f41689dc177419/yarg-0.1.9-py2.py3-none-any.whl
    Requirement already satisfied: requests in c:usersxhanaconda3libsite-packages (from yarg->pipreqs) (2.19.1)
    Requirement already satisfied: idna<2.8,>=2.5 in c:usersxhanaconda3libsite-packages (from requests->yarg->pipreqs) (2.7)
    Requirement already satisfied: certifi>=2017.4.17 in c:usersxhanaconda3libsite-packages (from requests->yarg->pipreqs) (2019.6.16)
    Requirement already satisfied: urllib3<1.24,>=1.21.1 in c:usersxhanaconda3libsite-packages (from requests->yarg->pipreqs) (1.23)
    Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:usersxhanaconda3libsite-packages (from requests->yarg->pipreqs) (3.0.4)
    Installing collected packages: yarg, pipreqs
    Successfully installed pipreqs-0.4.10 yarg-0.1.9
    WARNING: You are using pip version 19.2.1, however version 20.0.2 is available.
    You should consider upgrading via the 'python -m pip install --upgrade pip' command.
    
    D:devdev_pydeving>pipreqs ./
    Traceback (most recent call last):
      File "c:usersxhanaconda3lib
    unpy.py", line 193, in _run_module_as_main
        "__main__", mod_spec)
      File "c:usersxhanaconda3lib
    unpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "C:UsersXHAnaconda3Scriptspipreqs.exe\__main__.py", line 9, in <module>
      File "c:usersxhanaconda3libsite-packagespipreqspipreqs.py", line 470, in main
        init(args)
      File "c:usersxhanaconda3libsite-packagespipreqspipreqs.py", line 409, in init
        follow_links=follow_links)
      File "c:usersxhanaconda3libsite-packagespipreqspipreqs.py", line 122, in get_all_imports
        contents = f.read()
    UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 113: illegal multibyte sequence
    
    D:devdev_pydeving>pipreqs ./ --encoding utf-8
    WARNING: Requirements.txt already exists, use --force to overwrite it
    
    D:devdev_pydeving>pipreqs ./ --encoding utf-8 --force
    INFO: Successfully saved requirements file in ./requirements.txt
    
    D:devdev_pydeving>
    

    方法一和方法二,都可以生成requirements.txt。方法一是会将python环境中的依赖包全都加入;方法二只将项目依赖包加入。

    生成 requirements.txt 后,需要安装 requirements.txtpip install -r requirements.txt.

    以上。

    参考——https://www.cnblogs.com/jclian91/p/12431215.html

  • 相关阅读:
    一些PC小软件/工具/神器备份
    三角函数与反三角函数
    常用网站整理(书签整理)
    谷歌和谷歌学术镜像网站
    微擎系统jssdk系统快速签名变量
    phpexcel 导入超过26列时的解决方案
    js循环对象,(多层数组)
    CentOS 6 下无法wget https链接的解决方法
    centos6 7 yum安装mongodb 3.6
    yum except KeyboardInterrupt, e: 错误
  • 原文地址:https://www.cnblogs.com/lovebkj/p/12789105.html
Copyright © 2020-2023  润新知