pip install, python setup.py, egg-info的说明--以Nvidia Apex安装为例
发布日期:2021-11-21 04:41:13 浏览次数:28 分类:技术文章

本文共 1840 字,大约阅读时间需要 6 分钟。

Install Nvidia Apex

若第一次安装需要把项目从github克隆到本地

Clean the old install before rebuilding:

pip uninstall apex

cd apex_repo_dir
rm -rf build (if present)
rm -rf apex.egg-info (if present)

Install package:

注:–no-cache-dir功能: 1. 不使用缓存在pip目录下的cache中的文件;2.也不保存在安装过程中需要的或者下次重新安装时需要的一些文件

pip install -v --no-cache-dir --global-option="–cpp_ext" --global-option="–cuda_ext" ./

或者
python setup.py install --cuda_ext --cpp_ext

扩展1. pip install --editable . vs python setup.py develop

Try to avoid calling setup.py directly, it will not properly tell pip that you’ve installed your package.

With pip install -e:

其中 -e 选项全称是–editable. For local projects, the “SomeProject.egg-info” directory is created relative to the project path (相对于此项目目录的路径). This is one advantage over just using setup.py develop, which creates the “egg-info” directly relative the current working directory (相对于当前工作环境目录的路径).

扩展2. 弄懂一个命令 pip3 install --editable '.[train,test]'

When you then did pip install --editable ., the command installs the Python package in the current directory
(signified by the dot .) with the optional dependencies needed for training and
testing (’[train,test]’). 上面的安装命令中,-e选项全称是–editable,也就是可编辑的意思,以可继续开发的模式进行安装, ‘.’ 表示当前目录,也就是setup.py存在的
那个目录,此时pip install将会把包安装在当前文件目录下,而不是安装到所使用的python环境中的-site-packages。
[train,test] 只是我们举的一个例字,是可选参数,在setup.py中可以找到这两个选项(也可能叫其他名字或者根本就没有)之下包含了哪些第三方包。

扩展3. 关于egg-info

注意⚠️:选则本地安装pip install .成功安装完成后,apex.egg-info文件夹可以只处于当前项目文件夹下而不是安装在系统环境中,只需要在当前使用的python虚拟环境-site-packages中一个指向该egg-info文件的超链接即可(这个是在本地安装自动的行为,不需要我们关心操作),这样就能找到使用Apex包时所需的apex.egg-info文件夹里的信息。

PS: 如果遇到Cuda版本不兼容的问题,解决办法见(升级pytoch 1.3后 cuda10.1不匹配版本的警告已经消失):

如果没有出现其他error,可以直接使用上面链接的建议,删除版本检查抛出的报错。见以下讨论:

Apex的使用

命令行启动训练

—也是如何Pycharm运行时添加命令行参数的例子

python -m torch.distributed.launch --nproc_per_node=4 train_distributed.py

不使用命令行运行,而是使用Pycharm启动同步夸卡训练的配置

在这里插入图片描述

转载地址:https://blog.csdn.net/xiaojiajia007/article/details/104283450 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:python class __init__() 外部定义属性
下一篇:SSD学习笔记

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月07日 08时36分31秒