python3学习笔记及常见问题
1,mac自带的python是2.7版本,我们需要按照python3,这样在terminal下可以直接使用,但是编译打包的时候会默认使用python2.7
解决办法:安装virtualenv,一个管理包的虚拟环境。
$ [sudo] pip install virtualenv
如果遇到错误:IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/virtualenv.py'
解决:sudo chmod +a 'user:lichanghong allow add_subdirectory,add_file,delete_child,directory_inherit' /Library/python/2.7/site-packages/
1)virtualenv 的使用可以参考:http://www.cnblogs.com/tk091/p/3700013.html
创建python3环境: virtualenv -p /usr/local/Cellar/python3/3.5.1/bin/python3 py
启动:source activate
关闭:deactivate
2,适配python2,3
import sys
if sys.version_info < (3, 0):
# Python 2
import Tkinter as tk
else:
# Python 3
import tkinter as tk
3,If you build with virtualenv --system-site-packages ENV,
-------------------以上尝试能够行得通,但是在python3的环境下在pyinstaller里一直找不到tkinter,故改用cx_freeze
安装: pip3 install cx_freeze
cxfreeze hello.py --target-dir dist 编译到了dist
在cmd窗口输入cxfreeze-quickstart可以自动生成setup.py
例如:setup.py:
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = ["os"], excludes = ["tkinter"])
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('my.py', base=base, targetName = 'my.app')
]
setup(name='testproj',
version = '1.0',
description = 'testproj 1.0 desc',
options = dict(bdist_exe = buildOptions),
executables = executables)
python setup.py bdist_msi
On Mac OS X, you can use bdist_dmg to build a Mac disk image.
python3学习笔记及常见问题的更多相关文章
- Python3学习笔记(urllib模块的使用)转http://www.cnblogs.com/Lands-ljk/p/5447127.html
Python3学习笔记(urllib模块的使用) 1.基本方法 urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, ...
- Python3学习笔记 - 准备环境
前言 最近乘着项目不忙想赶一波时髦学习一下Python3.由于正好学习了Docker,并深深迷上了Docker,所以必须趁热打铁的用它来创建我们的Python3的开发测试环境.Python3的中文教程 ...
- python3学习笔记(7)_listComprehensions-列表生成式
#python3 学习笔记17/07/11 # !/usr/bin/env python3 # -*- conding:utf-8 -*- #通过列表生成式可以生成格式各样的list,这种list 一 ...
- python3学习笔记(6)_iteration
#python3 学习笔记17/07/10 # !/usr/bin/env python3 # -*- coding:utf-8 -*- #类似 其他语言的for循环,但是比for抽象程度更高 # f ...
- python3学习笔记(5)_slice
#python3 学习笔记17/07/10 # !/usr/bin/env python3 # -*- coding:utf-8 -*- #切片slice 大大简化 对于指定索引的操作 fruits ...
- Python3学习笔记01-环境安装和运行环境
最近在学习Python3,想写一些自己的学习笔记.方便自己以后看,主要学习的资料来自菜鸟教程的Python3教程和廖雪峰官方网站的Python教程. 1.下载 1)打开https://www.pyth ...
- python3学习笔记(9)_closure
#python 学习笔记 2017/07/13 # !/usr/bin/env python3 # -*- conding:utf-8 -*- #从高阶函数的定义,我们可以知道,把函数作为参数的函数, ...
- python3学习笔记(8)_sorted
# python学习笔记 2017/07/13 # !/usr/bin/env python3 # -*- coding:utf-8 -*- #python 内置sorted()函数 可以对list进 ...
- python3学习笔记(4)_function-参数
#python学习笔记 17/07/10 # !/usr/bin/evn python3 # -*- coding:utf-8 -*- import math #函数 函数的 定义 #定义一个求绝对值 ...
随机推荐
- 学习node.js的一些笔记
最近看了几眼node.js,以前曾听说它用途很大. 在菜鸟教程上,已看了过半的内容:http://www.runoob.com/nodejs/nodejs-web-module.html,如今看到了这 ...
- centos6.0和7.4默认网卡配置
6.0 vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" NM_CONTROLLED="yes&qu ...
- SGD、GD
GD参考: https://blog.csdn.net/CharlieLincy/article/details/70767791 SGD参考:https://blog.csdn.net/Charli ...
- Tomcat并发优化和缓存优化
Tomcat并发优化 1.调整连接器connector的并发处理能力 在Tomcat 配置文件 server.xml 中的 <Connector ... /> 配置中 1.参数说明 max ...
- 类型限定词——const
类型限定词有三个:const volatile restrict. const:一般也叫常量修饰符. 作用:是修饰变量,被修饰的变量就变成常量了,不能被二次修改了. const int a=12:a ...
- 从excel表中生成批量SQL,将数据录入到数据库中
excel表格中有许多数据,需要将数据导入数据库中,又不能一个一个手工录入,可以生成SQL,来批量操作. 1.首先在第二行的H列,插入函数:=CONCATENATE("INSERT ...
- 2018网站Https升级完全攻略
这篇文章主要讲下HTTPs升级的全部流程,包括SSL/TLS证书获取,证书安装,网站调试(将站内http资源全部改为https+重定向等),升级成功后向谷歌webmaster和GA的重新提交新的网站. ...
- 14. Longest Common Prefix ★
题目内容:Write a function to find the longest common prefix string amongst an array of strings 题目分析:本题目利 ...
- MyBatis工具类
package cn.word.util; import java.io.IOException;import java.io.InputStream;import java.util.Enumera ...
- python文件(概念、基本操作、常用操作、文本文件的编码方式)
文件 目标 文件的概念 文件的基本操作 文件/文件夹的常用操作 文本文件的编码方式 01. 文件的概念 1.1 文件的概念和作用 计算机的 文件,就是存储在某种 长期储存设备 上的一段 数据 长期存储 ...