Python 3:安装自己的和第三方软件包的好位置?

发布于 2024-10-20 22:22:27 字数 680 浏览 1 评论 0原文

对于 Python 3.x:

我希望获得有关在多个项目(以及任何相关因素)中查找我想要使用的模块的最佳目录的建议。我了解 import 语句和 PYTHONPATH,以及使任何位置“工作”的各种方法,但我希望符合标准实践。

那么:

  1. 我应该将我的模块放入“Pythonxx\Lib\site-packages”中的包中吗?

  2. site-packages 目录是否得到特殊处理,或者它与其他可能的模块位置没有什么不同?我很困惑它是否有特殊的“.pth”和/或 __init__.py 行为。

  3. 约定在多大程度上受到 distutils 所做的影响,它似乎还没有真正为 Python 3 做好准备...这是否意味着我应该关注未来的一些其他约定?

  4. 我应该怎么做:http://docs.python.org/py3k /install/index.html 其中“安装工作原理”似乎声称(在表中)“site-packages”与 Windows 无关,尽管我在 Windows Python 中看到一个空的 site-packages 目录3.1 安装。

- 谢谢!

For Python 3.x:

I'd like advice on best directory in which to locate modules that I want to use across multiple projects (and any related factors). I know about the import statement and PYTHONPATH, and various ways to make any location "work", but I want to be in line with standard practice.

So:

  1. Should I be putting my modules in a package in "Pythonxx\Lib\site-packages"?

  2. Does the site-packages directory get special treatment, or is it no different than other possible locations for modules? I'm confused as to whether it has special ".pth" and/or __init__.py behavior.

  3. To what extent are conventions influenced by what distutils does, which doesn't seem to be really ready for Python 3... and does that mean that I should be attending to some other conventions going forward?

  4. What should I make of this: http://docs.python.org/py3k/install/index.html in which "How installation works" seems to claim (in the table) that 'site-packages' is not relevant to Windows, though I see an empty site-packages directory in my Windows Python 3.1 installation.

-- Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

慕烟庭风 2024-10-27 22:22:27
  1. 是的 - 但让你的 setup.py 来完成

  2. 你认为为什么会有问题?

  3. 文档需要修复。默认的 Python 安装目录是 C:\PythonXY,而不是 C:\Python。默认包安装目录是 C:\PythonXY\Lib\site-packages。

  1. Yes -- but let your setup.py do it

  2. No

  3. Why do you think there is a problem?

  4. The docs need fixing. The default Python install directory is C:\PythonXY, not C:\Python. The default package install directory is C:\PythonXY\Lib\site-packages.

篱下浅笙歌 2024-10-27 22:22:27

您可能希望考虑设置 virtualenv,这是捆绑一组模块的标准方法用于跨项目和平台。

You might wish to consider setting up a virtualenv, which is the standard way of bundling a set of modules for use across projects and platforms.

叹梦 2024-10-27 22:22:27

巧合的是,今天是我问这个问题的周年纪念日。尽管受访者试图提供帮助,但我最终还是对这个问题进行了更深入的调查。这导致我在此处发布了注释:Python- 常见模块的组织
还有 python.org 上的一些问题报告(相同的用户名),以及对其文档的一些修订。我希望这能帮助其他同样陷入困境的人。

Coincidentally, it's the anniversary of my asking this question. Though the respondents attempted to be helpful, I ended up investigating this issue in substantially more depth. That led to notes which I posted here: Python- Organization for common modules.
Also some issue reports at python.org (same user name), and some revisions to their documentation. I hope that helps others who are similarly stumped.

放赐 2024-10-27 22:22:27

每用户站点包目录是另一种选择。您可以尝试一下:

python setup.py install --user

安装到 %APPDATA%\Python\Python32 比创建全新的 virtualenv 轻量得多。这就是 PyPM 默认情况下所做的事情。

Per-user site-packages directory is another option. You can try it with:

python setup.py install --user

Installing to %APPDATA%\Python\Python32 is much more lightweight than creating a whole new virtualenv. This is what PyPM does by default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文