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

查看:70
本文介绍了如何使我的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天全站免登陆