不会起名字的我 发表于 2020-12-3 17:39:54

怎么把.py转为.exe

我的Python版本是3.8.2
怎么把.py转为.exe?
谢谢!

默默者 发表于 2020-12-3 17:49:05

ptinstaller

笨鸟学飞 发表于 2020-12-3 18:02:50

最简单的办法是用工具咯
某度:pyinstaller_GUI
有惊喜

风过无痕1989 发表于 2020-12-3 18:12:55

你在编译运行时,软件就会产生一个 .exe 文件,你到程序目录里找找

我用过那么多个 C 语言的编译器,都会产生一个可执行程序,我就不信 Py 会是个例外

qiuyouzhi 发表于 2020-12-3 18:20:21

风过无痕1989 发表于 2020-12-3 18:12
你在编译运行时,软件就会产生一个 .exe 文件,你到程序目录里找找

我用过那么多个 C 语言的编译器,都 ...

...
你是真没用过Python吧

风过无痕1989 发表于 2020-12-3 18:39:00

本帖最后由 风过无痕1989 于 2020-12-3 18:41 编辑

qiuyouzhi 发表于 2020-12-3 18:20
...
你是真没用过Python吧

确实没有,我去一个 py 程序,到 VS2015 里运行一下看看,是不是真的这么邪乎

qiuyouzhi 发表于 2020-12-3 18:44:48

风过无痕1989 发表于 2020-12-3 18:39
确实没有,我去一个 py 程序,到 VS2015 里运行一下看看,是不是真的这么邪乎

。。这就是Python语言的特性啊
你不能把C语言和其他类型的语言像比较
除了C-like类型的,我没见过别的可以编译出可执行文件的

永恒的蓝色梦想 发表于 2020-12-3 19:23:25

风过无痕1989 发表于 2020-12-3 18:12
你在编译运行时,软件就会产生一个 .exe 文件,你到程序目录里找找

我用过那么多个 C 语言的编译器,都 ...

Python 不编译。

不会起名字的我 发表于 2020-12-3 19:34:44

风过无痕1989 发表于 2020-12-3 18:12
你在编译运行时,软件就会产生一个 .exe 文件,你到程序目录里找找

我用过那么多个 C 语言的编译器,都 ...

你用的是C语言的编译器,就是C语言,我这个是Python,这是另一个语言

风过无痕1989 发表于 2020-12-3 19:36:09

永恒的蓝色梦想 发表于 2020-12-3 19:23
Python 不编译。

我刚才在 Python 区找了一个已解决的程序,想去 VS2015 运行,结果,VS2015 让我安装,安装完成以后,一大堆的 Py 让我选,我不知选哪一个,也就只好作罢

kogawananari 发表于 2020-12-3 19:59:13

风过无痕1989 发表于 2020-12-3 19:36
我刚才在 Python 区找了一个已解决的程序,想去 VS2015 运行,结果,VS2015 让我安装,安装完成以后,一 ...

选 cpython 3.9

胡鸣谦 发表于 2020-12-3 20:09:32

pip install pyinstaller
pyinstaller -F 文件名.py (-w取消和那个黑乎乎的CMD,-i 图片名.ico更改文件图标)

风过无痕1989 发表于 2020-12-3 20:13:45

永恒的蓝色梦想 发表于 2020-12-3 19:23
Python 不编译。

@永恒的蓝色梦想我安装了 Python 后,现在 C 语言的程序不能用了,怎么办?

永恒的蓝色梦想 发表于 2020-12-3 20:31:37

风过无痕1989 发表于 2020-12-3 20:13
@永恒的蓝色梦想我安装了 Python 后,现在 C 语言的程序不能用了,怎么办?

我很想知道你对你的编译器做了什么……

永恒的蓝色梦想 发表于 2020-12-3 20:33:45

风过无痕1989 发表于 2020-12-3 18:12
你在编译运行时,软件就会产生一个 .exe 文件,你到程序目录里找找

我用过那么多个 C 语言的编译器,都 ...

下次有不懂得不要乱说……

风过无痕1989 发表于 2020-12-3 20:47:21

永恒的蓝色梦想 发表于 2020-12-3 20:33
下次有不懂得不要乱说……

我只是想试试,算了,重新安装吧

不会起名字的我 发表于 2020-12-4 19:43:41

胡鸣谦 发表于 2020-12-3 20:09
pip install pyinstaller
pyinstaller -F 文件名.py (-w取消和那个黑乎乎的CMD,-i 图片名.ico更改文件图 ...

看起来可行,我试试

不会起名字的我 发表于 2020-12-4 19:47:11

胡鸣谦 发表于 2020-12-3 20:09
pip install pyinstaller
pyinstaller -F 文件名.py (-w取消和那个黑乎乎的CMD,-i 图片名.ico更改文件图 ...

报错
Traceback (most recent call last):
File "c:\users\deli\appdata\local\programs\python\python38\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
File "c:\users\deli\appdata\local\programs\python\python38\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
File "C:\Users\deli\AppData\Local\Programs\Python\Python38\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\build_main.py", line 720, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\build_main.py", line 667, in build
    exec(code, spec_namespace)
File "C:\Users\deli\Desktop\2.1\UU-US`OS.spec", line 6, in <module>
    a = Analysis(['UU-US`OS.py', 'UU-US`OS.ico'],
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\build_main.py", line 242, in __init__
    self.__postinit__()
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
    self.assemble()
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\build_main.py", line 413, in assemble
    priority_scripts.append(self.graph.run_script(script))
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\depend\analysis.py", line 320, in run_script
    return super(PyiModuleGraph, self).run_script(
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1411, in run_script
    contents = fp.read() + '\n'
File "c:\users\deli\appdata\local\programs\python\python38\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 46: invalid continuation byte
怎么办???

叼辣条闯世界 发表于 2020-12-5 09:52:14

先打开cmd(推荐win+r cmd)
输入pip install pyinstaller
安装好后用cd命令切换到.py文件的文件夹
最后输入pyinstaller -F --onefile ******.py
*******是你.py的文件名

不会起名字的我 发表于 2020-12-5 11:59:05

叼辣条闯世界 发表于 2020-12-5 09:52
先打开cmd(推荐win+r cmd)
输入pip install pyinstaller
安装好后用cd命令切换到.py文件的文件夹


报错
Traceback (most recent call last):
File "c:\users\deli\appdata\local\programs\python\python38\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
File "c:\users\deli\appdata\local\programs\python\python38\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
File "C:\Users\deli\AppData\Local\Programs\Python\Python38\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\build_main.py", line 720, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\build_main.py", line 667, in build
    exec(code, spec_namespace)
File "C:\Users\deli\Desktop\2.1\UU-US`OS.spec", line 6, in <module>
    a = Analysis(['UU-US`OS.py', 'UU-US`OS.ico'],
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\build_main.py", line 242, in __init__
    self.__postinit__()
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
    self.assemble()
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\build_main.py", line 413, in assemble
    priority_scripts.append(self.graph.run_script(script))
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\depend\analysis.py", line 320, in run_script
    return super(PyiModuleGraph, self).run_script(
File "c:\users\deli\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1411, in run_script
    contents = fp.read() + '\n'
File "c:\users\deli\appdata\local\programs\python\python38\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 46: invalid continuation byte
怎么办???
页: [1] 2
查看完整版本: 怎么把.py转为.exe