在哪里手动安装 python 文件
我在一个较大的项目中遇到了 setuptools 的问题,其中必须从多个 debian 包(每个包包含“主”包的子包)“构建”一个 python 包。因此,我们决定手动安装这些文件,而不是使用“setup.py install”,但我们不确定要使用的位置。我们首先使用 /usr/share 中的一个目录,我们已经将其用于安装的其他内容。除了在启动任何应用程序之前我们必须搞乱 PYTHONPATH 之外,这工作得很好。
默认 sys.path 中是否有任何地方可以安装软件包?我正在考虑 /usr/lib/python2.6/dist-packages (当您使用 setuptools 时,文件也应该在那里结束,不是吗?),但我有点不愿意写到像这样的地方这与自定义安装脚本...另外,如果 Ubuntu 切换到 2.7,我们也必须移动吗?任何“最佳实践”如何做这样的事情?整个 site-packages/dist-packages 概念的记录很少:(
I'm having trouble with setuptools in a larger project where a python package has to be "constructed" from several debian packages (each containing a subpackage of the "main" package). Thus we decided to install the files manully instead of using "setup.py install", but we are unsure of the location to use. We first used a directory in /usr/share that we already use for other stuff we install. This works fine except for the fact that we have to mess around with PYTHONPATH before starting any application.
Is there any place that is in the default sys.path where we could install packages instead? I was thinking about /usr/lib/python2.6/dist-packages (which is where the files should end up when you use setuptools as well, shouldnt they?), but I'm kind of reluctant of writing to a place like this with custom install scripts... Also, what if Ubuntu switches to 2.7, do we have to move as well then? Any "best practice" how to do something like this? This whole site-packages/dist-packages concept is so under-documented :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很难说你需要在哪里安装 Python 包,事实上,你可以将它安装在任何你想要的地方。我认为最好的地方是将它们放入 /usr/local/share/YOURPACKAGENAME 中,以防它不是由 apt-get 安装的(aptitude 等...)。无论哪种情况,您都必须在 python 脚本周围创建一个小包装器,它将包所在的路径插入到“sys.path”变量中。例如,Ubuntu 的“yum”默认将其文件放置到“/usr/share/yum-cli”,“/usr/bin/yum”脚本包含以下行:
或者,您必须设置 PYTHONPATH 环境变量。这并没有什么问题。
It is kind of hard to say where you need to install your Python packages taking into account that, in fact, you can install it anywhere you want. The best place in my opinion is to put them into /usr/local/share/YOURPACKAGENAME in case it was not installed by apt-get (aptitude etc...). In either case, you have to create a small wrapper around you python script(s) which inserts a path(s) to where your package(s) are located into "sys.path" variable. For example, "yum" for Ubuntu puts its files to "/usr/share/yum-cli" by default and "/usr/bin/yum" script contains the following lines:
Alternatively, you have to set PYTHONPATH environment variable. There is nothing wrong with that.