你如何组织Python模块?

时间:2023-01-16 16:57:24

When it comes to organizing python modules, my Mac OS X system is a mess. I've packages lying around everywhere on my hdd and no particular system to organize them.

在组织python模块时,我的Mac OS X系统很乱。我的硬盘上到处都是软件包,没有特定的系统来组织它们。

How do you keep everything manageable?

你如何保持一切可管理?

8 个解决方案

#1


12  

My advice:

  • Read Installing Python Modules.
  • 阅读安装Python模块。

  • Read Distributing Python Modules.
  • 阅读分发Python模块。

  • Start using easy_install from setuptools. Read the documentation for setuptools.
  • 从setuptools开始使用easy_install。阅读setuptools的文档。

  • Always use virtualenv. My site-packages directory contains setuptools and virtualenv only.
  • 始终使用virtualenv。我的site-packages目录仅包含setuptools和virtualenv。

  • Check out Ian Bicking's new project pyinstall.
  • 查看Ian Bicking的新项目pyinstall。

  • Follow everything Ian Bicking is working on. It is always goodness.
  • 关注Ian Bicking正在努力的一切。永远是善良。

  • When creating your own packages, use distutils/setuptools. Consider using paster create (see http://pythonpaste.org) to create your initial directory layout.
  • 创建自己的包时,请使用distutils / setuptools。考虑使用paster create(请参阅http://pythonpaste.org)来创建初始目录布局。

#2


5  

In addition to PEP8 and easy_install, you should check out virtualenv. Virtualenv allows you to have multiple different python library trees. At work, we use virtualenv with a bootstrapping environment to quickly set up a development/production environment where we are all in sync w.r.t library versions etc. We generally coordinate library upgrades.

除了PEP8和easy_install之外,你应该看看virtualenv。 Virtualenv允许您拥有多个不同的python库树。在工作中,我们使用virtualenv和bootstrapping环境来快速建立一个开发/生产环境,我们都在同步w.r.t库版本等。我们通常协调库升级。

#3


5  

There are several families of Python componentry.

有几个Python组件系列。

  1. The stuff that comes with Python. This takes care of itself.

    Python附带的东西。这照顾好自己。

  2. The stuff that you got with easy_install. This, also, takes care of itself.

    你用easy_install获得的东西。这也是自己照顾的。

  3. The packages that you had to get some other way, either as TARballs or SVN checkouts. Create a Components folder. Put the downloads or the SVN's in there first. Every Single Time. Do installs from there.

    您必须以其他方式获得的包,可以是TAR球或SVN签出。创建一个Components文件夹。首先将下载或SVN放在那里。每一次。从那里安装。

  4. The packages that you wrote that are reusable. I have a Projects folder with each project in that folder. If the project is a highly reusable thing, it has a setup.py and I actually run the install as if I downloaded it. I don't have many of these, but a few. Some of them might become open source projects.

    您编写的可重用的包。我有一个Projects文件夹,其中包含该文件夹中的每个项目。如果项目是一个高度可重用的东西,它有一个setup.py,我实际上运行安装,就像我下载它。我没有很多,但有一些。其中一些可能成为开源项目。

  5. The final applications you write. I have a folder in Projects with each of these top-level applications. These are usually big, rambling things (like Django sites) and don't have setup.py. Why? They're often pretty complex with only a few server installations to manage, and each of those server installations is unique. These generally rely on PYTHONPATH to identify their parts.

    你写的最后的应用程序。我在Projects中有一个文件夹,其中包含每个*应用程序。这些通常是大而漫无边际的东西(如Django网站),并且没有setup.py。为什么?它们通常非常复杂,只需要管理一些服务器安装,并且每个服务器安装都是独一无二的。这些通常依靠PYTHONPATH来识别它们的部件。

Notice the common theme. Either they're Components you downloaded or they're Projects you're working on.

注意共同的主题。它们是您下载的组件,或者它们是您正在处理的项目。

Also, I keep this separate (to an extent) from the client. I have a master directory of Client folders, each of which has Projects and each project has Sales and Delivery. Not all projects have both sales and delivery.

此外,我将此与客户分开(在一定程度上)。我有一个客户端文件夹的主目录,每个目录都有项目,每个项目都有销售和交付。并非所有项目都有销售和交付。

#4


2  

Maybe PEP8 and easy_install can help you?

也许PEP8和easy_install可以帮到你?

#5


2  

I keep all the source for my packages inside ~/Packages/ , and then I do a standard install with "python2.5 setup.py install" on them. This tosses into (for me) /Library/Frameworks/Python/Versions/current/lib/python2.5/site-packages/ . For the development of my own software, I have aliases set up to switch between trunk/ branches/1.0, etc, by pre-prending onto PYTHONPATH. (I have to run 'setup.py build_ext --inplace' in each of these directories before they will import properly.)

我在〜/ Packages /中保存了我的软件包的所有源代码,然后我在其上进行了“python2.5 setup.py install”的标准安装。这个(对我来说)扔进/Library/Frameworks/Python/Versions/current/lib/python2.5/site-packages/。为了开发我自己的软件,我通过预先添加到PYTHONPATH来设置别名以在trunk / branches / 1.0等之间切换。 (我必须在每个目录中运行'setup.py build_ext --inplace'才能正确导入。)

It's worth noting that Python2.6 has a per-user site-packages directory, which you may find more convenient.

值得注意的是,Python2.6有一个每用户的站点包目录,你可能会发现它更方便。

#6


1  

The "Modules" Python documentation page is a useful guide on organising code, specifically the "packages" sections

“模块”Python文档页面是组织代码的有用指南,特别是“包”部分

#7


1  

My advice is to try to put everything into your site-packages directory(ies) unless you have a good reason not to. And I try to avoid easy_install because I find that it tends to cruft up my sys.path with egg locations, but that's just me. Some people find it useful.

我的建议是尝试将所有内容放入您的站点包目录中,除非您有充分的理由不这样做。我尽量避免使用easy_install,因为我发现它往往会破坏我的带有鸡蛋位置的sys.path,但那只是我。有些人觉得它很有用。

If you have lots of programs that use different libraries that may conflict with each other, you may also want to check out virtualenv.

如果您有许多使用不同库的程序可能会相互冲突,您可能还想查看virtualenv。

#8


1  

Just ran across this site from another * question: http://infinitemonkeycorps.net/docs/pph/ This addresses more than just module placement, but once you place it write how you can easily handle documentation, testing, and distribution.

刚刚从另一个*问题中浏览了这个站点:http://infinitemonkeycorps.net/docs/pph/这不仅解决了模块放置问题,而且一旦放置它,就可以编写如何轻松处理文档,测试和分发的方法。

#1


12  

My advice:

  • Read Installing Python Modules.
  • 阅读安装Python模块。

  • Read Distributing Python Modules.
  • 阅读分发Python模块。

  • Start using easy_install from setuptools. Read the documentation for setuptools.
  • 从setuptools开始使用easy_install。阅读setuptools的文档。

  • Always use virtualenv. My site-packages directory contains setuptools and virtualenv only.
  • 始终使用virtualenv。我的site-packages目录仅包含setuptools和virtualenv。

  • Check out Ian Bicking's new project pyinstall.
  • 查看Ian Bicking的新项目pyinstall。

  • Follow everything Ian Bicking is working on. It is always goodness.
  • 关注Ian Bicking正在努力的一切。永远是善良。

  • When creating your own packages, use distutils/setuptools. Consider using paster create (see http://pythonpaste.org) to create your initial directory layout.
  • 创建自己的包时,请使用distutils / setuptools。考虑使用paster create(请参阅http://pythonpaste.org)来创建初始目录布局。

#2


5  

In addition to PEP8 and easy_install, you should check out virtualenv. Virtualenv allows you to have multiple different python library trees. At work, we use virtualenv with a bootstrapping environment to quickly set up a development/production environment where we are all in sync w.r.t library versions etc. We generally coordinate library upgrades.

除了PEP8和easy_install之外,你应该看看virtualenv。 Virtualenv允许您拥有多个不同的python库树。在工作中,我们使用virtualenv和bootstrapping环境来快速建立一个开发/生产环境,我们都在同步w.r.t库版本等。我们通常协调库升级。

#3


5  

There are several families of Python componentry.

有几个Python组件系列。

  1. The stuff that comes with Python. This takes care of itself.

    Python附带的东西。这照顾好自己。

  2. The stuff that you got with easy_install. This, also, takes care of itself.

    你用easy_install获得的东西。这也是自己照顾的。

  3. The packages that you had to get some other way, either as TARballs or SVN checkouts. Create a Components folder. Put the downloads or the SVN's in there first. Every Single Time. Do installs from there.

    您必须以其他方式获得的包,可以是TAR球或SVN签出。创建一个Components文件夹。首先将下载或SVN放在那里。每一次。从那里安装。

  4. The packages that you wrote that are reusable. I have a Projects folder with each project in that folder. If the project is a highly reusable thing, it has a setup.py and I actually run the install as if I downloaded it. I don't have many of these, but a few. Some of them might become open source projects.

    您编写的可重用的包。我有一个Projects文件夹,其中包含该文件夹中的每个项目。如果项目是一个高度可重用的东西,它有一个setup.py,我实际上运行安装,就像我下载它。我没有很多,但有一些。其中一些可能成为开源项目。

  5. The final applications you write. I have a folder in Projects with each of these top-level applications. These are usually big, rambling things (like Django sites) and don't have setup.py. Why? They're often pretty complex with only a few server installations to manage, and each of those server installations is unique. These generally rely on PYTHONPATH to identify their parts.

    你写的最后的应用程序。我在Projects中有一个文件夹,其中包含每个*应用程序。这些通常是大而漫无边际的东西(如Django网站),并且没有setup.py。为什么?它们通常非常复杂,只需要管理一些服务器安装,并且每个服务器安装都是独一无二的。这些通常依靠PYTHONPATH来识别它们的部件。

Notice the common theme. Either they're Components you downloaded or they're Projects you're working on.

注意共同的主题。它们是您下载的组件,或者它们是您正在处理的项目。

Also, I keep this separate (to an extent) from the client. I have a master directory of Client folders, each of which has Projects and each project has Sales and Delivery. Not all projects have both sales and delivery.

此外,我将此与客户分开(在一定程度上)。我有一个客户端文件夹的主目录,每个目录都有项目,每个项目都有销售和交付。并非所有项目都有销售和交付。

#4


2  

Maybe PEP8 and easy_install can help you?

也许PEP8和easy_install可以帮到你?

#5


2  

I keep all the source for my packages inside ~/Packages/ , and then I do a standard install with "python2.5 setup.py install" on them. This tosses into (for me) /Library/Frameworks/Python/Versions/current/lib/python2.5/site-packages/ . For the development of my own software, I have aliases set up to switch between trunk/ branches/1.0, etc, by pre-prending onto PYTHONPATH. (I have to run 'setup.py build_ext --inplace' in each of these directories before they will import properly.)

我在〜/ Packages /中保存了我的软件包的所有源代码,然后我在其上进行了“python2.5 setup.py install”的标准安装。这个(对我来说)扔进/Library/Frameworks/Python/Versions/current/lib/python2.5/site-packages/。为了开发我自己的软件,我通过预先添加到PYTHONPATH来设置别名以在trunk / branches / 1.0等之间切换。 (我必须在每个目录中运行'setup.py build_ext --inplace'才能正确导入。)

It's worth noting that Python2.6 has a per-user site-packages directory, which you may find more convenient.

值得注意的是,Python2.6有一个每用户的站点包目录,你可能会发现它更方便。

#6


1  

The "Modules" Python documentation page is a useful guide on organising code, specifically the "packages" sections

“模块”Python文档页面是组织代码的有用指南,特别是“包”部分

#7


1  

My advice is to try to put everything into your site-packages directory(ies) unless you have a good reason not to. And I try to avoid easy_install because I find that it tends to cruft up my sys.path with egg locations, but that's just me. Some people find it useful.

我的建议是尝试将所有内容放入您的站点包目录中,除非您有充分的理由不这样做。我尽量避免使用easy_install,因为我发现它往往会破坏我的带有鸡蛋位置的sys.path,但那只是我。有些人觉得它很有用。

If you have lots of programs that use different libraries that may conflict with each other, you may also want to check out virtualenv.

如果您有许多使用不同库的程序可能会相互冲突,您可能还想查看virtualenv。

#8


1  

Just ran across this site from another * question: http://infinitemonkeycorps.net/docs/pph/ This addresses more than just module placement, but once you place it write how you can easily handle documentation, testing, and distribution.

刚刚从另一个*问题中浏览了这个站点:http://infinitemonkeycorps.net/docs/pph/这不仅解决了模块放置问题,而且一旦放置它,就可以编写如何轻松处理文档,测试和分发的方法。