最近写完的自动化脚本,分享给同事的时候发现依赖包很难解决(使用的不是virtualenv环境)。想起来之前看开源接口平台项目的时候可以一键下载依赖包,于是就找到了第三方包pipreqs,可以自动帮助我们自动生成requirements.txt

第一步:下载pipreqs工具包(pip install pipreqs)

Microsoft Windows [版本 10.0.17134.1069]
(c) 2018 Microsoft Corporation。保留所有权利。 C:\Users\wy.DESKTOP-KENPKKP\Desktop\Dingda\dingAPI>pip install pipreqs
Collecting pipreqs
Downloading https://files.pythonhosted.org/packages/f8/8d/2e7c15bc5fcab54f9c5b404b5668fdac65f5e3224b2116097fae1299fc98/pipreqs
-0.4.9-py2.py3-none-any.whl
Collecting docopt
Downloading https://files.pythonhosted.org/packages/a2/55/8f8cab2afd404cf578136ef2cc5dfb50baa1761b68c9da1fb1e4eed343c9/docopt-
0.6.2.tar.gz
Collecting yarg
Downloading https://files.pythonhosted.org/packages/8b/90/89a2ff242ccab6a24fbab18dbbabc67c51a6f0ed01f9a0f41689dc177419/yarg-0.
1.9-py2.py3-none-any.whl
Installing collected packages: docopt, yarg, pipreqs
Running setup.py install for docopt ... done
Successfully installed docopt-0.6.2 pipreqs-0.4.9 yarg-0.1.9

第二步:切换到项目路径下,生成依赖包的txt文档(pipreqs ./ --encoding=utf8)

期间遇到报错:编码错误(UnicodeDecodeError: 'gbk' codec can't decode byte 0x95 in position 40)

C:\Users\wy.DESKTOP-KENPKKP\Desktop\Dingda\dingAPI>pipreqs ./
Traceback (most recent call last):
File "c:\users\wy.desktop-kenpkkp\appdata\local\programs\python\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
......
extra_ignore_dirs=extra_ignore_dirs)
File "c:\users\wy.desktop-kenpkkp\appdata\local\programs\python\python36\lib\site-packages\pipreqs\pipreqs.py", line 75, in ge
t_all_imports
contents = f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0x95 in position 40: illegal multibyte sequence

找到原因是因为在Windows下需要制定编码方式为:uft-8,操作如下

C:\Users\wy.DESKTOP-KENPKKP\Desktop\Dingda\dingAPI>pipreqs ./ --encoding=utf8
INFO: Successfully saved requirements file in ./requirements.txt

第三步:查看需要的依赖包(type requirements.txt)

C:\Users\wy.DESKTOP-KENPKKP\Desktop\Dingda\dingAPI>type  requirements.txt
requests==2.18.4
xlutils==2.0.0
xmltodict==0.12.0
xlrd==1.2.0
dicttoxml==1.7.4

下载依赖包方法(pip install -r requriements.txt)

C:\Users\wy.DESKTOP-KENPKKP\Desktop\Dingda\dingAPI>pip install -r  requirements.txt
Requirement already satisfied: requests==2.18.4 in c:\users\wy.desktop-kenpkkp\appdata\local\programs\python\python36\lib\site-p
ackages (from -r requirements.txt (line 1)) (2.18.4)
Requirement already satisfied: xlutils==2.0.0 in c:\users\wy.desktop-kenpkkp\appdata\local\programs\python\python36\lib\site-pac
kages (from -r requirements.txt (line 2)) (2.0.0)
Requirement already satisfied: xmltodict==0.12.0 in c:\users\wy.desktop-kenpkkp\appdata\local\programs\python\python36\lib\site-
packages (from -r requirements.txt (line 3)) (0.12.0)
Requirement already satisfied: xlrd==1.2.0 in

附带pipreqs详细用法

gitbug地址:https://github.com/bndr/pipreqs

  • 用法:
  • pipreqs [选项] <路径>
  • 选项:
  • use-local仅使用本地软件包信息,而不是查询PyPI
  • pypi-server 使用自定义PyPi服务器
  • proxy 使用代理,参数将传递到请求库。您也可以只设置终端中的environment参数:
  • ignore <目录> ...忽略多余的目录
  • encoding 使用encoding参数打开文件
  • savepath <文件>将需求列表保存在给定文件中
  • print在标准输出中输出需求列表
  • force覆盖现有的requirements.txt
  • clean <文件>通过删除项目中未导入的模块来清理requirements.txt。

Python项目生成所有依赖包的清单的更多相关文章

  1. 将Python项目生成所有依赖包的清单requirements .txt文件

    在开发中不同的项目总会牵扯到各种不同作用的包安装,下面是总结一下对写好的项目自动生成依赖清单,以及在新环境下解决依赖的方法: 一:生成所有依赖清单requirements.txt 这里需要使用到的工具 ...

  2. python项目生成及导入依赖的第三方库

    requirements.txt用来记录项目所有的依赖包和版本号,只需要一个简单的pip命令就能完成. pip freeze >requirements.txt 然后就可以用 pip insta ...

  3. Python一键安装全部依赖包

    requirements.txt用来记录项目所有的依赖包和版本号,只需要一个简单的pip命令就能完成. pip freeze >requirements.txt 然后就可以用 pip insta ...

  4. Python 一键安装全部依赖包

    使用 pip requirements.txt 用来记录项目所有的依赖包和版本号,只需要一个简单的 pip 命令就能完成. pip freeze > requirements.txt 生成的文件 ...

  5. 【Tomcat】使用Tomcat部署Spring Boot项目生成的jar包

    介绍 简单来说,Tomcat是一个免费的,用于Java Web应用以及其它Web应用的一个Web服务器.(简单地概括一下,可能有误) 下载与安装 本文章目标是把Spring Boot Web项目生成的 ...

  6. Gradle | Gradle项目无法导入依赖包

    Gradle | Gradle项目无法导入依赖包 背景 今天使用idea导入一个Gradle项目,使用 gradle build构建成功,但是项目还是无法正常导入依赖包,显示错误如下: 解决方案 后来 ...

  7. Python项目生成requirements.txt文件及pip升级问题解决及流程

    缘由:新项目使用Python, PC上的python包不全,需要通过requirements.txt文件指定安装所需包 pip安装遇到一些坑 一.直接使用pip包管理工具生成requirements. ...

  8. 使用VirtualEnvWrapper隔离python项目的库依赖

    是什么 VirtualEnv用于在一台机器上创建多个独立的python运行环境,VirtualEnvWrapper为前者提供了一些便利的命令行上的封装. 为什么要用 - 隔离项目之间的第三方包依赖,如 ...

  9. Python项目生成requirements.txt的多种方式

    我相信任何软件程序都会有依赖的类库,尤其现在开源如此的火爆,因为一个项目可能会有无很多的依赖的包 这个时候难道我们都要一个一个的去找到安装吗?即使你找到了依赖的包 但是呢模块的版本又有很多难道你都要装 ...

随机推荐

  1. 通过实例快速掌握k8s(Kubernetes)核心概念

    容器技术是微服务技术的核心技术之一,并随着微服务的流行而迅速成为主流.Docker是容器技术的先驱和奠基者,它出现之后迅速占领市场,几乎成了容器的代名词.但它在开始的时候并没有很好地解决容器的集群问题 ...

  2. MongoDB安装过程中出现service MongoDB failed to start,verify that you have sufficient privileges to start...

    win10系统下,安装MongoDB 64位, service MongoDB failed to start,verify that you have sufficient privileges t ...

  3. vue-cli 脚手架安装

    1.安装node;选择适合自己系统的文件,下载一路next , a安装成功后,打开运行输入cmd 进入命令行: 在命令行工具中输入 npm -v  检查版本号 如果出现 则安装成功:(npm为node ...

  4. 1.Eclipse下载、常用配置、快捷键

    Eclipse官网下载:https://www.eclipse.org/downloads/packages/ 自动补全 位置:Eclipse——Window——Perferences——Java—— ...

  5. idea 新建项目 coding上新建项目 idea推送到coding

    1. 注册coding a. 首先在(https://coding.net)上创建项目 ps:跳过注册 ![file](https://img2018.cnblogs.com/blog/1416679 ...

  6. Warfare And Logistics UVA - 1416

    题目链接:https://vjudge.net/problem/UVA-1416 题解: 这是一个最短路的好题,首先我们考虑如果暴力弗洛伊德,显然时间复杂度不对,如果做n次spfa好像复杂度也不对,所 ...

  7. 后门免杀工具-Backdoor-factory

    水一水最近玩的工具 弄dll注入的时候用到的 介绍这款老工具 免杀效果一般..但是简单实用  目录: 0x01 backdoor-factory简介 0x02 特点功能 0x03 具体参数使用 PS: ...

  8. css div 自适应内容

    .adapt-content{ display:inline-block; *display:inline; ; } 见:http://www.cnblogs.com/refe/p/5051661.h ...

  9. phpstorm 新加入项目的文件--全局搜索不到 ctrl + shift + R

    通过文件名查找文件 ,能搜到其他的现有文件,只是新加入的文件,无法出现在搜索到的结果中 . 总不可能在搜索的关键词一直拼写错误吧 , 那能想到的只有缓存出问题了. 新加入的文件,新加入的文件.... ...

  10. TensorFlow2.0(8):误差计算——损失函数总结

    .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px so ...