知行编程网知行编程网  2022-10-16 09:00 知行编程网 隐藏边栏  310 
文章评分 0 次,平均分 0.0
导语: 本文主要介绍了关于别人怎么用我的Python程序的相关知识,包括python写的程序别人电脑用,以及写好python代码如何在其他电脑运行这些编程知识,希望对大家有参考作用。

其他人如何使用我的 Python 程序


别人怎么用我的Python程序

这里供其他人使用,而不是开源你的代码,也不是给其他程序员。比如你写了一个小工具,想给别人用,就不能让别人也安装python

为了让其他人在不安装Python环境的情况下使用Python编写的程序,可以将Python程序打包成.exe可执行程序发送给其他人。

推荐学习《
》。


Python打包生成.exe文件的工具有:


1、py2exe

使用:

先写一个简单的脚本,文件名:helloworld.py

#!/usr/bin/env python  # -*- coding: utf-8 -*-  
  def say_hello(name):  
    print("Hello, " + name)
  if __name__ == "__main__":  
    name = input("What's your name:")
    say_hello(name)

我们还需要一个用于发布程序的设置脚本:mysetup.py,在其中的设置函数之前插入语句import py2exe。

from distutils.core import setupimport py2exe
setup(console=["helloworld.py"])


2、cx_Freeze

使用:cxfreeze main.py --target-dir dist

Usage: cxfreeze [options] [SCRIPT]

Freeze a Python script and all of its referenced modules to a base
executable which can then be distributed without requiring a Python
installation.

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -O                    optimize generated bytecode as per PYTHONOPTIMIZE; use
                        -OO in order to remove doc strings
  -c, --compress        compress byte code in zip files
  -s, --silent          suppress all output except warnings and errors
  --base-name=NAME      file on which to base the target file; if the name of
                        the file is not an absolute file name, the
                        subdirectory bases (rooted in the directory in which
                        the freezer is found) will be searched for a file
                        matching the name
  --init-script=NAME    script which will be executed upon startup; if the
                        name of the file is not an absolute file name, the
                        subdirectory initscripts (rooted in the directory in
                        which the cx_Freeze package is found) will be searched
                        for a file matching the name
……
……
……


3、PyInstaller

使用:pyinstaller demo.py

其他人如何使用我的 Python 程序

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写
扫一扫二维码分享