问题描述
我喜欢编辑安装有 pip
的python模块。但是,我不知道如何在升级模块时避免本地更新和原始更新之间的冲突。
例如,
$ pip install some_module
$ vim〜/.../ some_module / something.py#更新文件
$ pip install --upgrade some_module
由于本地资源库和原始资源库之间存在冲突,应该会发生一些麻烦。 (原始repo在github上的假设是OK的)
我猜想其中一个替代方法是在github上分发版本库, pip install git +< repo_url>
,但我没有信心。
避免这种麻烦的好方法是什么?
你不应该编辑模块的核心文件,如果你需要修改它,你应该扩展(继承)它并覆盖功能和添加你自己的函数,这样你的代码与repo的代码是分开的,不会被更新或升级覆盖。
你也可以使用虚拟环境,一个虚拟环境是一个孤立的Python安装/环境,它可以很容易地管理依赖和不同版本的库/ Python的版本
这应该让你开始
p>
I like to edit python modules installed with pip
. But, I do not know good way to avoid conflicts between local update and original one when upgrade a module.
For example,
$ pip install some_module
$ vim ~/.../some_module/something.py # update the file
$ pip install --upgrade some_module
It should occurs some trouble because of conflicts between local and original repository. (The assumption that original repo is on github is OK)
I guess One of alternatives is forking repository on github and pip install git+<repo_url>
, but I'm not have confident.
What is good way to avoid this trouble?
You should not be editing the core files of a module, if you need to modify it you should be extending (subclassing) it and over-riding the functionality and adding your own functions, that way your code is separate from the repo's code and won't be over-written by an update or upgrade
You could also Use a virtual environment, a virtual environment is an isolated python installation/environment, it makes it easy to manage dependencies and different version of libraries/ version of python
this should get you started
http://docs.python-guide.org/en/latest/dev/virtualenvs/
这篇关于管理本地和原始库中反复更新的python模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!