鱼C论坛

 找回密码
 立即注册
查看: 2215|回复: 6

[已解决]如何象这个程序一样发布python?

[复制链接]
发表于 2017-10-16 11:27:27 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
比如象xx-net一样发布源码文件,用bat启动,在没装python的电脑上运行?谢谢先。
最佳答案
2017-10-16 12:55:03
隐约记得原理就是把python解释器编译成最小化.你可以Google一下python解释器最小化
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-10-16 12:02:40 | 显示全部楼层
不知所云
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-10-16 12:50:40 | 显示全部楼层

没用过 xx-net?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-10-16 12:55:03 | 显示全部楼层    本楼为最佳答案   
隐约记得原理就是把python解释器编译成最小化.你可以Google一下python解释器最小化
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-10-16 12:57:40 | 显示全部楼层
tmkuej 发表于 2017-10-16 12:55
隐约记得原理就是把python解释器编译成最小化.你可以Google一下python解释器最小化

我试一下。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-10-17 13:10:16 | 显示全部楼层
google没找到想要的,有一个portable python网站居然关闭,百度了这篇文章
http://blog.csdn.net/yao_yu_126/article/details/7951331
#coding=gbk
#
#最小Python3.2环境, 可以在miniPython目录下,直接运行python.exe(或pythonw.exe)。
#
#前提:
#    需要安装vcredist_x86.exe包
#
#制作原理:
#    1. 把PythonXXX目录完整拷贝到制作目录,修改原有的PythonXXX目录为其它名称,使Python不直接使用。
#    2. 删除制作目录及子目录里的pyc,pyo文件
#    3. 运行制作目录下的python,然后退出
#    4. 根据重新生成的pyc文件找到需要的py文件到对应目录
#    5. 从而得到了最小的python运行环境
#
#示例:
#    1. 把Python32目录下的文件拷贝到C:\temp\Python32
#    2. 删除C:\temp\Python32目录及其子目录下的所有pyc,pyo文件
#    3. 在控制台下运行:
#        C:\temp\Python32\python.exe E:\2012\Setup\findMinPython.py
#    4. 上面的命令会将需要的py文件拷贝到E:\2012\Setup\miniPython目录下
#    5. 将python.exe, pythonw.exe, python32.dll拷贝到E:\2012\Setup\miniPython目录下
#    精简的Python32使用环境就找出来了,
#

# 导入基础模块
import os
import shutil

def visitDirFile(dir, visitor):
    '''递归访问目录及其子目录下的文件'''
    assert(os.path.isdir(dir)), dir
    for i in os.listdir(dir):
        fullPathName = os.path.join(dir, i)
        if os.path.isfile(fullPathName):
            if visitor(fullPathName):
                return True
        elif os.path.isdir(fullPathName):
            # 访问子目录
            if visitDirFile(fullPathName, visitor):
                return True

def findPyFile(file):
    '''查找相应的Py文件(不考虑pyo文件)'''
    if file[-4:] == '.pyc':
        # 得到编译文件对应的源文件
        dir = os.path.dirname(file)
        if dir.endswith('__pycache__'):
            dir = dir[:-11]
        # 文件中可能有点存在,要排除3.2之后的缓存
        name, ext = os.path.splitext(os.path.basename(file))
        name2, ext = os.path.splitext(name)
        if ext.startswith('.cpython'):
            name = name2
        srcFile = os.path.join(dir, '%s.py' % name)
        # 源文件可能是pyw文件
        if not os.path.isfile(srcFile):
            srcFile += 'w'
        destFile = srcFile.replace(srcDir, destDir)
        print(srcFile)
        # 保证目标目录存在
        dir = os.path.dirname(destFile)
        if not os.path.isdir(dir):
            os.makedirs(dir)
        # 拷贝文件及状态
        shutil.copy2(srcFile, destFile)

if __name__ == '__main__':
    import sys
    srcDir = os.path.dirname(sys.executable)
    destDir = os.path.join(os.path.dirname(__file__), 'miniPython')
    visitDirFile(srcDir, findPyFile)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-10-18 12:16:53 | 显示全部楼层
https://docs.python.org/3.5/using/windows.html#finding-modules
XX-net应该是照这个来发布的。
3.8.1. Python Application
An application written in Python does not necessarily require users to be aware of that fact. The embedded distribution may be used in this case to include a private version of Python in an install package. Depending on how transparent it should be (or conversely, how professional it should appear), there are two options.

Using a specialized executable as a launcher requires some coding, but provides the most transparent experience for users. With a customized launcher, there are no obvious indications that the program is running on Python: icons can be customized, company and version information can be specified, and file associations behave properly. In most cases, a custom launcher should simply be able to call Py_Main with a hard-coded command line.

The simpler approach is to provide a batch file or generated shortcut that directly calls the python.exe or pythonw.exe with the required command-line arguments. In this case, the application will appear to be Python and not its actual name, and users may have trouble distinguishing it from other running Python processes or file associations.

With the latter approach, packages should be installed as directories alongside the Python executable to ensure they are available on the path. With the specialized launcher, packages can be located in other locations as there is an opportunity to specify the search path before launching the application.
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-26 22:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表