编辑pip安装的软件包 [英] Edit package installed by pip

查看:141
本文介绍了编辑pip安装的软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编辑通过pip安装的名为py_mysql2pgsql的软件包(将数据库从mysql转换为postgre时出现错误,就像

I'm trying to edit a package that I installed via pip, called py_mysql2pgsql (I had an error when converting my db from mysql to postgre, just like this.

但是,当我进入文件夹/user/local/lib/python2.7/dist-packages/py_mysql2pgsql-0.1.5.egg-info时,找不到该包的源代码.我只找到PKG-INFO和文本文件.

However, when I got to the folder /user/local/lib/python2.7/dist-packages/py_mysql2pgsql-0.1.5.egg-info, I cannot find the source code for the package. I only find PKG-INFO and text files.

如何找到包(或特别是此包)的实际源代码?

How can I find the actual source code for a package (or in particular, this package)?

谢谢

推荐答案

TL; DR:

在原位进行修改很危险.修改源代码,然后从修改后的版本然后安装.

pip是用于管理软件包安装的工具.您不应该修改在软件包安装过程中创建的文件.充其量,这意味着pip会相信未安装软件包的特定版本.这将与升级功能无法很好地交互.我怀疑pip会覆盖您的自定义设置,并将其永久丢弃,但我尚未确认.另一种可能性是,它检查文件是否已更改,如果更改,则抛出错误. (我认为这不太可能.)这也会误导系统的其他用户.他们看到您已经安装了一个软件包,但实际上并没有指示该版本.您有一个自定义的版本.如果他们尝试将未修改的版本安装到其他地方,或者期望安装的版本有某些特定行为,则可能会造成混乱.

pip is a tool for managing the installation of packages. You should not modify files creating during package installation. At best, doing so would mean pip will believe that a particular version of the package is installed when it isn't. This would not interact well with the upgrade function. I suspect pip would just overwrite your customizations, discarding them forever, but I haven't confirmed. The other possibility is that it checks if files have changed and throws an error if so. (I don't think that's likely.) It also misleads other users of the system. They see that you have a package installed, but you don't actually have that version indicated; you have a customized version. This is likely to result in confusion if they try to install the unmodified version somewhere else or if they expect some particular behavior from the version installed.

如果要修改源代码,正确的做法是修改源代码,然后构建新的自定义程序包或仅从源代码安装. py-mysql2pgsql 提供了执行源代码安装的说明:

If you want to modify the source code, the right thing to do is modify the source code and either build a new, custom package or just install from source. py-mysql2pgsql provides instructions for performing a source install:

> git clone git://github.com/philipsoutham/py-mysql2pgsql.git
> cd py-mysql2pgsql
> python setup.py install

您可以克隆源代码,对其进行修改,然后在不使用pip的情况下进行安装.如果需要在内部重新分发,则可以选择构建自己的定制版本的软件包.该项目使用setuptools来构建其软件包,因此您只需要熟悉setuptools即可使用它们的setup.py文件.确保以这种方式安装它不会在pip的软件包列表中创建任何误导性条目.如果是这样,请找到一种方法来确保条目更加清晰,或者找到另一种安装方法.

You can clone the source, modify it, and then install without using pip. You could alternatively build your own customized version of the package if you need to redistribute it internally. This project uses setuptools for building its packages, so you only need to familiarize yourself with setuptools to make use of their setup.py file. Make sure that installing it this way doesn't create any misleading entries in pip's package list. If it does, either find a way to make sure the entry is more clear or find an alternative install method.

由于您已发现该软件中的错误,因此我强烈建议您在Github上对其进行分叉,并在修复后提交拉取请求.如果这样做,只需将存储库URL更改为fork即可使用上述安装说明.如果您不进行分叉,请至少提出一个问题并描述解决该问题的更改.

Since you've discovered a bug in the software, I also highly recommend forking it on Github and submitting a pull request once you have it fixed. If you do so, you can use the above installation instructions just by changing the repository URL to your fork. If you don't fork it, at least file an issue and describe the changes that fix it.

替代品:

  • 您可以将所有源代码复制到您的项目中,在此处进行修改,然后将修改后的版本与其余代码一起分发. (请确保您没有违反许可证.)
  • 您也许可以在运行时解决问题.如果您团队中的其他人可能不希望行为发生变化,则用猴子修补该模块会有些冒险,但是可以通过全局修改该模块的行为来完成.您还可以创建其他代码,以包装错误代码:它可以接受输入,调用错误代码,并阻止或处理错误(例如,修改输入以使其工作或捕获错误).异常并进行处理等).
  • You could copy all the source code into your project, modify it there, and then distribute the modified version with the rest of your code. (Make sure you don't violate the license if you do so.)
  • You might be able to solve you problem at runtime. Monkey-patching the module is a little risky if other people on your team might not expect the change in behavior, but it could be done for global modification of the module's behavior. You could also create some additional code that wraps the buggy code: it can take input, call the buggy code, and either prevents or handles the bug (e.g., modifying the input to make it work or catching an exception and handling it, etc.).

这篇关于编辑pip安装的软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆