Python中如何使用pip安装远程仓库上的依赖
是这样 我司一直有一个自己做的依赖包 长期放在 gitlab 上 安装时通过 pip install git+ssh git@xxxxxx 来进行安装
最近在用阿里云的一个 sdk 这个 sdk 只能通过下载到本地之后使用 python setup install 来安装 如果使用 pip install git+ssh 就会报错
Complete output from command python setup.py egg_info:
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: ‘install_requires’
warnings.warn(msg)
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] …]
or: -c --help [cmd1 cmd2 …]
or: -c --help-commands
or: -c cmd --help
error: invalid command ‘egg_info’
----------------------------------------
Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-_Uz0Zr-build/
我尝试去除了 setup 文件中的 distribution.croe.setup 并用 setuptools.setup 替代
但仍然报这个错
我后来直接删除了 install_requires 这个参数
仍然报错 (只是报错信息里没有 /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'install_requires’了)
请问该如何解决这个问题 让这个模块可以通过 pip install git+ssh 安装呢?
模块地址:https://github.com/aliyun/aliyun-log-python-sdk
Python中如何使用pip安装远程仓库上的依赖
用pip装远程仓库的包很简单,主要有两种方式:
1. 直接指定git仓库地址
pip install git+https://github.com/username/repo.git
或者指定分支:
pip install git+https://github.com/username/repo.git@branch_name
2. 通过requirements.txt文件 在requirements.txt里这样写:
git+https://github.com/username/repo.git
git+https://github.com/username/repo.git@branch_name
git+https://github.com/username/repo.git@tag_name
然后运行:
pip install -r requirements.txt
3. 如果是私有仓库,需要在URL里带上认证信息:
pip install git+https://username:token@github.com/username/repo.git
4. 其他版本控制系统也支持:
- SVN:
pip install svn+svn://svn.repo/svn/project/trunk - Mercurial:
pip install hg+https://hg.repo/project - Bazaar:
pip install bzr+lp:project
注意:安装git仓库时,pip会先克隆整个仓库,然后运行setup.py来安装。如果仓库没有正确的setup.py文件,安装会失败。
总结建议:直接用git+https链接最方便。
setuptools 导入了项目里面的 pkg_resources, 而这个 pkg_resources.py 可能有问题或者比较老了,现在的 setuptools 是自带 pkg_resources 的,可以把项目里的那个删掉
握草厉害 非常感谢

