如何执行我的"exe"来自PyCharm项目 [英] How to my "exe" from PyCharm project

查看:84
本文介绍了如何执行我的"exe"来自PyCharm项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过PyCharm在Python上编写一些项目. 我想从中获取一个exe文件. 我尝试另存为->.XXX.exe" -但是,当我尝试执行它时,出现错误此类操作系统不支持文件" p.s. 我有win7 x64,它也不能在x32上使用.

解决方案

您无法直接将Python文件另存为exe并期望它能正常工作-计算机无法自动理解您碰巧在文本文件中键入的任何代码.相反,您需要使用其他程序将Python代码转换为exe.

我建议使用 Pyinstaller 之类的程序.它实际上需要Python解释器并将其与脚本捆绑在一起,以将其变成独立的exe,可以在未安装Python的任意计算机上运行(通常是Windows计算机,因为Linux往往预装了Python).

要安装它,您可以从链接的网站下载它,也可以使用以下命令:

pip install pyinstaller

...从命令行开始.然后,在大多数情况下,您只需通过命令行导航到包含源代码的文件夹并运行:

pyinstaller myscript.py

您可以通过文档找到有关如何使用Pyinstaller和自定义构建过程的更多信息.. >


不过,您不一定必须使用Pyinstaller.这是各种程序的比较,可用于将您的Python代码转换为可执行文件.

Writing some project on Python via PyCharm. I want to get an exe file from it. I've tried to "Save as->XXX.exe" - but ,when i'm trying to execute it there is an error "file is not supported with such kind of OS" p.s. i've got win7 x64,it doesn't work on x32 too.

解决方案

You cannot directly save a Python file as an exe and expect it to work -- the computer cannot automatically understand whatever code you happened to type in a text file. Instead, you need to use another program to transform your Python code into an exe.

I recommend using a program like Pyinstaller. It essentially takes the Python interpreter and bundles it with your script to turn it into a standalone exe that can be run on arbitrary computers that don't have Python installed (typically Windows computers, since Linux tends to come pre-installed with Python).

To install it, you can either download it from the linked website or use the command:

pip install pyinstaller

...from the command line. Then, for the most part, you simply navigate to the folder containing your source code via the command line and run:

pyinstaller myscript.py

You can find more information about how to use Pyinstaller and customize the build process via the documentation.


You don't necessarily have to use Pyinstaller, though. Here's a comparison of different programs that can be used to turn your Python code into an executable.

这篇关于如何执行我的"exe"来自PyCharm项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆