Python:如何编辑已安装的包?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23075397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python: how to edit an installed package?
提问by KJW
I installed some package via pip install something
. I want to edit the source code for the package something
. Where is it (on ubuntu 12.04) and how do I make it reload each time I edit the source code and run it?
我通过pip install something
. 我想编辑包的源代码something
。它在哪里(在 ubuntu 12.04 上)以及如何在每次编辑源代码并运行它时重新加载它?
Currently I am editing the source code, and then running python setup.py again and again, which turns out to be quite a hassle.
目前我正在编辑源代码,然后一遍又一遍地运行python setup.py,结果证明很麻烦。
回答by Oz123
You can edit the files installed in /usr/local/lib/python2.7/dist-packages/
. Do note that you will have to use sudo
or become root
.
The better option would be to use virtual environmentfor your development. Then you can edit the files installed with your permissions inside your virtual environment.
您可以编辑安装在/usr/local/lib/python2.7/dist-packages/
. 请注意,您必须使用sudo
或成为root
. 更好的选择是使用虚拟环境进行开发。然后,您可以在虚拟环境中编辑使用您的权限安装的文件。
回答by Leonardo.Z
You should never edit an installed package. Instead, install a forked version of package.
您永远不应该编辑已安装的软件包。相反,安装包的分叉版本。
If you need to edit the code frequently, DO NOT install the package via pip install something
and edit the code in '.../site_packages/...'
如果您需要经常编辑代码,请勿通过安装包pip install something
并在“.../site_packages/...”中编辑代码
Instead, put the source code under a development directory, and install it with
相反,将源代码放在开发目录下,并使用
python setup.py develop
# or
pip install -e path/to/SomePackage
# Or use a vcs at the first place
$ pip install -e git+https://github.com/lakshmivyas/hyde.git#egg=hyde
Put your changes in a version control system, and tell pip to install it explicitly.
将您的更改放在版本控制系统中,并告诉 pip 显式安装它。
Reference: Edit mode
参考: 编辑模式