如何使我的 Python 模块在 Linux 系统范围内可用? [英] How to make my Python module available system wide on Linux?

查看:13
本文介绍了如何使我的 Python 模块在 Linux 系统范围内可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为自己制作了一个小模块,我碰巧经常使用它.每当我需要它时,我只需将它复制到我想使用它的文件夹中.由于我很懒,我想安装它以便我可以从任何地方调用它,甚至是交互式提示.所以我读了一些关于在此处安装的内容,并得出结论我需要将文件复制到/usr/local/lib/python2.7/site-packages.然而,这似乎没有任何作用.

I made myself a little module which I happen to use quite a lot. Whenever I need it I simply copy it to the folder in which I want to use it. Since I am lazy I wanted to install it so that I can call it from anywhere, even the interactive prompt. So I read a bit about installing here, and concluded I needed to copy the file over to /usr/local/lib/python2.7/site-packages. That however, doesn't seem to do anything.

有人知道我需要在哪里复制我的模块才能使其在系统范围内工作吗?

Does anybody know where I need to copy my module for it to work system wide?

推荐答案

有一些方法可以在系统范围内安装 Python 模块.您可能想看看 distutils.可以在此处找到有关 distutils2(当前版本)的优秀教程.

There are methods to install Python modules system-wide. You may want to take a look at distutils. A good tutorial for distutils2 (the current version) can be found here.

您基本上必须编写一个文件 setup.py 来告诉 distutils 要做什么.然后你可以简单地

You basically have to write a file setup.py which tells distutils what to do. Then you can simply

python setup.py install

具有 root 权限以在系统范围内安装您的模块.有很好的和简单的例子,而且这是我能想象到的最干净的方式.

with root permissions to install your module systemwide. There are good and easy examples, plus it's the cleanest way I can imagine.

这篇关于如何使我的 Python 模块在 Linux 系统范围内可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆