Python开发环境搭建

1、软件准备

cx_Freeze-4.3.win32-py3.2.msi   --打包用

PySide-1.2.2.win32-py3.2.exe    --跨平台用,QT

python-3.2.4.msi  --解析器

pywin32-217.win32-py3.2.exe --支持win32平台

2、遇到问题

Python执行exe程序时出现报错,因为cmd为utf-8,而python要求unicode,所以要先切换回unicode,我这里试了下:

切换cmd到中文编码格式:chcp 936

活动代码页: 936

C:\Users\tao>G:\Svn\Tool\Python\Hello\build\exe.win32-3.2\hello.exe
系统找不到指定的路径。

C:\Users\tao>G:\Svn\Tool\Python\Hello\build\exe.win32-3.2\hello.exe
hello

C:\Users\tao>G:\Svn\Tool\Python\Hello\build\exe.win32-3.2\hello.exe
hello

C:\Users\tao>z

  

还有cmd 命令行执行Python时出现问题:

报错,后面新增环境变量:

PYTHONIOENCODING

utf-8

运行python就OK了;

不能删除,应该是python运行时要切换到utf-8

后面这步可以删除,但是cmd的编码方式统一改成:

cmd默认的编码是采用GBK

regedit

HKEY_CURRENT_USER\Console\%SystemRoot%_system32_cmd.exe\CodePage
十进制:936 GBK

 

基本就这些了,需要注意的;

例子代码:--测试用

hello.py

import datetime
import sys
print ("hello")

setup.py

# A very simple setup script to create a single executable
#
# hello.py is a very simple "Hello, world" type script which also displays the
# environment in which the script runs
#
# Run the build process by running the command 'python setup.py build'
#
# If everything works well you should find a subdirectory in the build
# subdirectory that contains the files needed to run the script without Python

from cx_Freeze import setup, Executable

setup(
        name = "hello",
        version = "0.1",
        description = "Sample cx_Freeze script",
        executables = [Executable("hello.py")])

  

打包批处理:command.bat

python setup.py build

pause
continue

  

 

你可能感兴趣的:(Python开发环境搭建)