python开发的软件必须提供源码,如何部署具有库的Python应用程序作为源代码,无需进一步的依赖?...

Background: I have a small Python application that makes life for developers releasing software in our company a bit easier. I build an executable for Windows using py2exe. The application as well as the binary are checked into Subversion. Distribution happens by people just checking out the directory from SVN. The program has about 6 different Python library dependencies (e.g. ElementTree, Mako)

The situation: Developers want to hack on the source of this tool and then run it without having to build the binary. Currently this means that they need a python 2.6 interpreter (which is fine) and also have the 6 libraries installed locally using easy_install.

The Problem

This is not a public, classical open source environment: I'm inside a corporate network, the tool will never leave the "walled garden" and we have seriously inconvenient barriers to getting to the outside internet (NTLM authenticating proxies and/or machines without direct internet access).

I want the hurdles to starting to hack on this tool to be minimal: nobody should have to hunt for the right dependency in the right version, they should have to execute as little setup as possible. Optimally the prerequisites would be having a Python installation and just checking out the program from Subversion.

Anecdote: The more self-contained the process is the easier it is to repeat it. I had my machine swapped out for a new one and went through the unpleasant process of having to reverse engineer the dependencies, reinstall distutils, hunting down the libraries online and getting them to install (see corporate internet restrictions above).

解决方案

I sometimes use the approach I describe below, for the exact same reason that @Boris states: I would prefer that the use of some code is as easy as a) svn checkout/update - b) go.

But for the record:

I use virtualenv/easy_install most of the time.

I agree to a certain extent to the critisisms by @Ali A and @S.Lott

Anyway, the approach I use depends on modifying sys.path, and works like this:

Require python and setuptools (to enable loading code from eggs) on all computers that will use your software.

Organize your directory structure this:

project/

*.py

scriptcustomize.py

file.pth

thirdparty/

eggs/

mako-vNNN.egg

... .egg

code/

elementtree\

*.py

...

In your top-level script(s) include the following code at the top:

from scriptcustomize import apply_pth_files

apply_pth_files(__file__)

Add scriptcustomize.py to your project folder:

import os

from glob import glob

import fileinput

import sys

def apply_pth_files(scriptfilename, at_beginning=False):

"""At the top of your script:

from scriptcustomize import apply_pth_files

apply_pth_files(__file__)

"""

directory = os.path.dirname(scriptfilename)

files = glob(os.path.join(directory, '*.pth'))

if not files:

return

for line in fileinput.input(files):

line = line.strip()

if line and line[0] != '#':

path = os.path.join(directory, line)

if at_beginning:

sys.path.insert(0, path)

else:

sys.path.append(path)

Add one or more *.pth file(s) to your project folder. On each line, put a reference to a directory with packages. For instance:

# contents of *.pth file

thirdparty/code

thirdparty/eggs/mako-vNNN.egg

I "kind-of" like this approach. What I like: it is similar to how *.pth files work, but for individual programs instead of your entire site-packages. What I do not like: having to add the two lines at the beginning of the top-level scripts.

Again: I use virtualenv most of the time. But I tend to use virtualenv for projects where I have tight control of the deployment scenario. In cases where I do not have tight control, I tend to use the approach I describe above. It makes it really easy to package a project as a zip and have the end user "install" it (by unzipping).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"python web开发,点餐系统源码,django实战.rar" 是一个压缩文件,其中包含用Python和Django框架开发的一个点餐系统的源代码Python是一种高级的、面向对象的编程语言,广泛应用于Web开发、数据分析、人工智能等领域。它具有简单易学、代码可读性高和大量的第三方等优点,因此被很多开发者所喜爱和使用。 Web开发是创建和维护网站的过程,可以使用多种编程语言和框架来实现。而Django是一个被广泛使用的Python Web框架,它提供了丰富的工具和函数,帮助开发者简化Web应用程序开发过程。 点餐系统是一种用于餐厅或餐饮行业的应用程序,它封装了顾客点餐的过程,让点餐更加方便和高效。这个点餐系统的源代码使用Python和Django来实现,通过网页界面提供给顾客选择菜单、下订单和支付等功能。同时,该系统也可以方便餐厅管理人员管理菜单、订单和顾客信息等。 通过下载并解压这个压缩文件,您可以获得整个点餐系统的源代码文件。您可以通过查看源代码来学习Python和Django的开发技术,了解如何搭建一个简单的Web应用程序,以及如何使用Django框架提供的便捷工具和函数来简化开发过程。 总之,“python web开发,点餐系统源码,django实战.rar”是一个可以学习和研究的实例,通过研究该源码,您可以更深入地了解Python与Django在Web开发中的应用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值