I've installed a Python based package in my site-packages directory. However, I'm trying to learn how the code works so I'd like to hack it a bunch by putting in lots of print statements so I can understand what the code is doing. But at the end of the day I want a clean installation without all my hacks in it.
我在我的site-packages目录中安装了一个基于Python的包。但是,我正在尝试学习代码是如何工作的,所以我想通过输入大量的print语句来破解它,以便我能够理解代码在做什么。但是在一天结束时,我想要一个干净的安装,而不是我的所有黑客。
Of course I could just copy the original files to something else, make some hacks, and then at the end copy all the original files back over. But that's really tedious. At the very least, I'd like to install a local copy of the Python package and then have the python script use this copy preferentially (perhaps by suitable statements at the top of the script). But perhaps this isn't even the best way to do python development/hacking.
当然,我可以将原始文件复制到其他东西,制作一些黑客,然后在最后复制所有原始文件。但这真的很乏味。至少,我想安装Python包的本地副本,然后让python脚本优先使用此副本(可能通过脚本顶部的适当语句)。但也许这甚至不是进行python开发/黑客攻击的最佳方式。
What's the best solution for my problem? I want to be able to hack on the package (and use that package) but without messing up my clean version.
什么是我的问题的最佳解决方案?我希望能够破解包(并使用该包),但不会弄乱我的干净版本。
3 个解决方案
#1
1
The virtualenv-advice given is correct, depending on your actual package you can even go beyond that and not mess with the site-packages inside the virtualenv at all.
给出的virtualenv建议是正确的,取决于你的实际包装,你甚至可以超越它,而不是混乱virtualenv内的网站包。
If the package is setuptools-based, a simple
如果包是基于setuptools的,那很简单
$ python setup.py develop
from within a working-copy of it's source, it won't be installed, but instead just hooked into the virtualenv pointing to the working-copy. Advantage: you can edit (and e.g. rollback using GIT or whatever SCM the package maintainer uses) files in a well-defined and non-volatile location.
从它的源代码的工作副本中,它不会被安装,而只是挂在指向工作副本的virtualenv上。优点:您可以在定义良好且非易失性的位置编辑(例如使用GIT或软件包维护人员使用的任何SCM进行回滚)文件。
#2
6
Take a look at virtualenv. You can basically setup a local python environment in which you can install anything you like without having to mess around with the system environment.
看看virtualenv。您基本上可以设置一个本地python环境,您可以在其中安装任何您喜欢的东西,而不必乱用系统环境。
#3
1
This is what the Python virtualenv tool is for. It allows you to create a local Python environment with a set of packages distinct from your system installation. For example, I could do something like this:
这就是Python virtualenv工具的用途。它允许您使用与系统安装不同的一组软件包创建本地Python环境。例如,我可以做这样的事情:
$ virtualenv myenv
$ . myenv/bin/activate
$ pip install nifty-module
The activate
script modifies your PATH
so that any script that starts with:
激活脚本会修改您的PATH,以便以下列内容开头的任何脚本:
#!/usr/bin/env python
will use the Python from your virtual environment, rather than the system Python, and will see the modules installed in that environment.
将使用您的虚拟环境中的Python而不是系统Python,并将看到在该环境中安装的模块。
#1
1
The virtualenv-advice given is correct, depending on your actual package you can even go beyond that and not mess with the site-packages inside the virtualenv at all.
给出的virtualenv建议是正确的,取决于你的实际包装,你甚至可以超越它,而不是混乱virtualenv内的网站包。
If the package is setuptools-based, a simple
如果包是基于setuptools的,那很简单
$ python setup.py develop
from within a working-copy of it's source, it won't be installed, but instead just hooked into the virtualenv pointing to the working-copy. Advantage: you can edit (and e.g. rollback using GIT or whatever SCM the package maintainer uses) files in a well-defined and non-volatile location.
从它的源代码的工作副本中,它不会被安装,而只是挂在指向工作副本的virtualenv上。优点:您可以在定义良好且非易失性的位置编辑(例如使用GIT或软件包维护人员使用的任何SCM进行回滚)文件。
#2
6
Take a look at virtualenv. You can basically setup a local python environment in which you can install anything you like without having to mess around with the system environment.
看看virtualenv。您基本上可以设置一个本地python环境,您可以在其中安装任何您喜欢的东西,而不必乱用系统环境。
#3
1
This is what the Python virtualenv tool is for. It allows you to create a local Python environment with a set of packages distinct from your system installation. For example, I could do something like this:
这就是Python virtualenv工具的用途。它允许您使用与系统安装不同的一组软件包创建本地Python环境。例如,我可以做这样的事情:
$ virtualenv myenv
$ . myenv/bin/activate
$ pip install nifty-module
The activate
script modifies your PATH
so that any script that starts with:
激活脚本会修改您的PATH,以便以下列内容开头的任何脚本:
#!/usr/bin/env python
will use the Python from your virtual environment, rather than the system Python, and will see the modules installed in that environment.
将使用您的虚拟环境中的Python而不是系统Python,并将看到在该环境中安装的模块。