如何将Python 3.3+编译为字节代码并暂停程序 [英] How to compile Python 3.3+ to byte code and pause program

查看:90
本文介绍了如何将Python 3.3+编译为字节代码并暂停程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚学习了一些C ++ 14后开始学习python并遇到了问题。我已经使用正确版本的py2exe成功地将python 2.7脚本编译成独立的可执行文件,这些可执行文件在程序关闭之前也会暂停,以便用户可以查看输出。我也能够使用相应版本的py2exe创建一个python 3.3字节码可执行文件,但它在收盘前顽固地拒绝暂停。我已经使用python 3的正确语法来暂停以下应该工作的程序:x = input(按回车)

但是在编译成.pyc文件之后程序仍然没有暂停。

请帮我完成这项任务,非常感谢你的帮助。真诚的,亚当。



我的尝试:



我有查找,下载并安装了正确版本的py2exe,用于编译python 3.3+。我还确保我使用了python 3.3的正确语法,但没有成功。我无法想象我可能做错了什么,并对此事的任何帮助表示感谢。谢谢。

I have just started learning python after learning some C++14 and have encountered a problem. I have used the correct version of py2exe to successfully compile python 2.7 scripts to standalone executables which also pause before the program closes so user can view output. I have also been able to create a python 3.3 bytecode executable using the corresponding version of py2exe, but it stubbornly refuses to pause before closing. I have used the correct syntax for python 3 to pause program where the following should work: x = input("press enter")
But the program still does not pause before closing after compiling to .pyc file.
Please help me to accomplish this task, I greatly appreciate all of your help. Sincerely, Adam.

What I have tried:

I have looked up, downloaded, and installed the correct version of py2exe for compiling python 3.3+. I have also made sure I used the correct syntax for python 3.3 but have had no success. I cannot conceive of what I may be doing wrong, and would be grateful for any assistance in this matter. Thank you.

推荐答案

首先检查您的代码(如果正确,请按照以下步骤在您的问题上发布您的代码)



根据我的经验:



我目前正在使用Python 3.5.2而Py2exe更适合Python 2,但我发现有几个困难因为它没有对Python -3特别是3.5版本有很好的支持。对于这个简单的东西,我不能将我的Python 3.5降级到2.7。



我为解决这个问题所做的是:我已经下载了名为PyInstaller的库

为2.x和3.x版本的python提供了出色的支持。



我建议你使用相同的编译python进入二进制文件。你可以编译windows的独立exe,MAC的包(我没有mac book,但我知道Pyinstaller能够这样做)以及linux。



随意提出疑问



更新:

1.要从Python脚本构建Windows二进制文件必须已经在合适的建筑中安装了PyWin32。



Python for Windows Extensions - 在SourceForge.net上浏览/ pywin32 / Build 220 [ ^ ]



选择适当的Windows体系结构并从上面给出的链接安装它。



2.下载Pyinstaller(不要使用PIP或easy_install等安装它),下载压缩包并将其解压缩到您选择的文件夹您可以在你想要的任何驱动器中提取它br />


3.提取后你会发现Pyinstaller文件夹打开它。



4.考虑示例.py 是您构建可执行文件的脚本的名称。



5.打开Pyinstaller文件夹并粘贴example.py(有没有粘贴它的其他方法,但这是最简单的方法)。



6.按 SHIFT 然后右键单击鼠标(右键单击鼠标时不应松开移位按钮)在那里找到打开命令窗口选项。



7.选择它将打开命令提示符。



< b>如果您已将Python设置为您的环境变量,请按照8(a),然后按照8(b)



8(a)。输入这个命令



Pyinstaller.py --onefile example.py



example.py是您脚本的名称。



8(b)。输入这个命令



python的路径Pinstaller.py --onefile example.py



替换路径python到你的python路径



示例为Python 3.5.2:

C:\ Users \ User \ AppData\Local\Programs\Python\Python35-32\python.exe Pinstaller.py --onefile example.py



你将找到放在dist文件夹中的exe。



更新2:

如果您使用的是两个版本的python按照以下步骤操作。



1.确保为2.7和3.5.2版本安装了正确版本的PyWin32。



2.解压缩Pyinstaller文件夹(我认为你已经解压缩了)



3.环境变量可能设置为Python 2.7所以更好你按照步骤1到7并按照 8(b)即使用你的Python3位置来构建可执行文件





如果你好你还有任何问题随时可以问我。
First check your code (If correct follow the below steps else post your code on your question)

From my experience:

I am currently using Python 3.5.2 and Py2exe is more suitable for Python 2 and but I found several difficulties since it doesn't have good support for Python -3 especially 3.5 versions. I can't downgrade my Python 3.5 to 2.7 for this simple stuff.

What I have done to solve the problem is: I have downloaded the Library called PyInstaller
which provides excellent support for both 2.x and 3.x versions of python.

I would suggest you to use the same for compiling python into binaries. You can compile standalone exe's for windows ,packages for MAC(I don't have mac book but I know Pyinstaller is capable of doing so) and also for linux.

Feel free to ask doubts

UPDATE:
1. To build binaries for Windows from Python script one must have installed PyWin32 in suitable architechture.

Python for Windows Extensions - Browse /pywin32/Build 220 at SourceForge.net[^]

select your appropriate Windows architecture and install it from the link given above.

2. Download Pyinstaller(Don't install it using PIP or easy_install etc.,) Download the compressed package and extract it to a folder of your choice You can extract it in any drive you want.

3. After extraction you will find Pyinstaller folder open it.

4. consider example.py is the name of the script you ant to build an executable.

5. Open the Pyinstaller folder and paste example.py there(there are other ways to do without pasting it here but this is easiest one).

6. Press SHIFT and hit right click and your mouse(you should not release the shift button when right clicking the mouse) you will find open command window option there.

7. Select it command prompt will be opened.

If you have set Python to your environment variables follow 8(a) else follow 8(b)

8(a). Type this command

Pyinstaller.py --onefile example.py

example.py is the name of your script.

8(b). Type this command

Path of python Pinstaller.py --onefile example.py

Replace path of python to your python path

example shown for Python 3.5.2:
C:\Users\User\AppData\Local\Programs\Python\Python35-32\python.exe Pinstaller.py --onefile example.py

You will find exe placed in dist folder.

Update 2:
If you are using two versions of python follow the below steps.

1. Make sure you have installed correct version of PyWin32 for both 2.7 and 3.5.2 version.

2. Extract the Pyinstaller folder(I think you have extracted already)

3. Environment variable may have set to Python 2.7 so better you follow step 1 to 7 and follow 8(b) i.e use your Python3 location to build the executable


If you still face any problems feel free to ask me.


这篇关于如何将Python 3.3+编译为字节代码并暂停程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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