Python 3:安装自己的和第三方软件包的好位置?
对于 Python 3.x:
我希望获得有关在多个项目(以及任何相关因素)中查找我想要使用的模块的最佳目录的建议。我了解 import 语句和 PYTHONPATH,以及使任何位置“工作”的各种方法,但我希望符合标准实践。
那么:
我应该将我的模块放入“Pythonxx\Lib\site-packages”中的包中吗?
site-packages 目录是否得到特殊处理,或者它与其他可能的模块位置没有什么不同?我很困惑它是否有特殊的“.pth”和/或
__init__.py
行为。约定在多大程度上受到 distutils 所做的影响,它似乎还没有真正为 Python 3 做好准备...这是否意味着我应该关注未来的一些其他约定?
我应该怎么做: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:
Should I be putting my modules in a package in "Pythonxx\Lib\site-packages"?
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.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?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的 - 但让你的 setup.py 来完成
否
你认为为什么会有问题?
文档需要修复。默认的 Python 安装目录是 C:\PythonXY,而不是 C:\Python。默认包安装目录是 C:\PythonXY\Lib\site-packages。
Yes -- but let your setup.py do it
No
Why do you think there is a problem?
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.
您可能希望考虑设置 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.
巧合的是,今天是我问这个问题的周年纪念日。尽管受访者试图提供帮助,但我最终还是对这个问题进行了更深入的调查。这导致我在此处发布了注释: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.
每用户站点包目录是另一种选择。您可以尝试一下:
安装到
%APPDATA%\Python\Python32
比创建全新的 virtualenv 轻量得多。这就是 PyPM 默认情况下所做的事情。Per-user site-packages directory is another option. You can try it with:
Installing to
%APPDATA%\Python\Python32
is much more lightweight than creating a whole new virtualenv. This is what PyPM does by default.