Python2的一些问题及解决办法
1. 无法注释中文的解决办法
# -*- coding:utf8 -*- # 添加这一行就行了 from django.contrib import admin
from myapp.models import * # 尽量不用用星号,这里就不改了
# Register your models here.
# admin.site.register(Member) # Django默认后台样式
在py文件添加
2. 无法显示中文的问题
import sys
reload(sys)
sys.setdefaultencoding('utf8') 摘自:
http://blog.csdn.net/crazyhacking/article/details/39375535
引入sys模块
3. 解决版本兼容问题
from __future__ import unicode_literals 摘自:
http://python-future.org/unicode_literals.html
导入__future__模块
4. 当安装第三方库的时候出现Python version 2.7 required, which was not found in the registry
#!C:/Python27/python2.exe
import sys from _winreg import * # tweak as necessary
version = sys.version[:3]
installpath = sys.prefix regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
installpath, installpath, installpath
) def RegisterPy():
try:
reg = OpenKey(HKEY_CURRENT_USER, regpath)
except EnvironmentError as e:
try:
reg = CreateKey(HKEY_CURRENT_USER, regpath)
SetValue(reg, installkey, REG_SZ, installpath)
SetValue(reg, pythonkey, REG_SZ, pythonpath)
CloseKey(reg)
except:
print "*** Unable to register!"
return
print "--- Python", version, "is now registered!"
return
if (QueryValue(reg, installkey) == installpath and
QueryValue(reg, pythonkey) == pythonpath):
CloseKey(reg)
print "=== Python", version, "is already registered!"
return
CloseKey(reg)
print "*** Unable to register!"
print "*** You probably have another Python installation!" if __name__ == "__main__":
RegisterPy() 摘自:
http://blog.csdn.net/zklth/article/details/8117207
建立一个register.py文件,然后python2执行脚本
5. 安装Python2之后,pip不能用的问题,如pip -V ,会报如下的错误
# 解释器为Python2.7.14,win10企业版,Python2和3共存
# 在安装完解释器之后,cmd窗口执行:pip2 list或者pip2 -V会报如下错误: Fatal error in launcher: Unable to create process using '"' 解决办法为
用Python2解释器cmd执行如下命令: python2 -m pip install --upgrade pip 就好了 摘自:
http://blog.csdn.net/yu757371316/article/details/54962305 Python多版本共存添加环境变量:
http://www.cnblogs.com/Neeo/p/8393805.html
解决办法
End
Python2的一些问题及解决办法的更多相关文章
- python2含有中文路径报错解决办法[\xe4\xbf\xa1\xe6\x81\xaf]
如图所示 百度的解决办法大多数是针对python3版本的,在脚本开头加# -*- coding:utf-8 -*-,但是python2版本加了编码格式,还是报错,具体解决办法是:path =unico ...
- 安装了Python2.X和Python3.X后Python2.X IDLE打不开解决办法总结
安装了Python2.X和Python3.X后Python2.X IDLE打不开,两个版本都卸载后重装仍然打不开,在网上找了几种办法,希望对大家能有所帮助 1.首先查看环境变量是否配置正确 配置方法网 ...
- python2.7运行报警告:UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal解决办法
1. 程序源代码报错部分: #选择年级if grade == '幼升小': outline.nianji().pop(0).click()elif grade == "一年级": ...
- Python: 编程遇到的一些问题以及网上解决办法?
0.Python: TypeError: 'str' does not support the buffer interface,(点我) fp.write(url.encode("utf- ...
- 安装Django,运行django-admin.py startproject 工程名,后不出现指定的工程解决办法!!
第一次写博客,,,,, 在看我这篇教程的前提是你应该已经正确装好python和Django了,好了,废话不说了,正题走你!你现在是不是很纠结自己运行django-admin.py startpr ...
- 关于web2py外网访问,图形界面不显示等问题的解决办法
首先系统版本是ubuntu 15.04,系统默认安装了两个版本的python, sudo python web2py.py 默认会调用python2.7版本来执行 会提示 pydo@planpls:/ ...
- Python在安装第三方模块遇到的问题及解决办法
今天在安装第一个模块psutil的时候出现了以下问题: 1.找不到Python.h文件 解决办法:重新安装python环境:sudo apt-get install python-dev 说明:网上有 ...
- [转]编译Android源代码常见错误解决办法
1. 编译时出现/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libz.so when ...
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128) 解决办法
最近在用Python处理中文字符串时,报出了如下错误: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 0: ...
随机推荐
- Py中re.sub学习【转载】
转自:https://www.crifan.com/python_re_sub_detailed_introduction/ //这个网址讲的不错. 1.re.sub的功能 re是regular ex ...
- 【LeetCode每天一题】 Merge k Sorted Lists(合并K个有序链表)
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. E ...
- 如何学Python
如何学习Python? Python上手很容易, 基本有其他语言编程经验的人可以在1周内学会Python最基本的内容.它们包括:1.常用内置类型(int, float, bool, bytes, st ...
- jQuery UI 中Tabs Ajax载入时出现Http 304的问题
最近发现jQueryUI中tabs的ajax载入,总是会出现304未修改的情况,明明数据有变化的么~应该返回200才对. 于是尝试在beforeLoad中设置: ui.ajaxSettings.cac ...
- PHP json_encode/json_decode与serialize/unserializ性能测
PHP里面,有时候出于实际需求考虑,需要将某些信息以数组的方式进行存储,甚至有时候介于数组.字符串两者之间,很难确定是数组还是字符串,如果最终还需要将这些信息存储到文件系统中,而且要保证正确无误的存储 ...
- VS 应用模板 所交税和实发工资的运算
double SFGZ, SL, SSKCS, YFGZ,a,YJS; //应发工资(基本工资),税率,速算扣除数,应发工资,判断标准,交多少税 //double QZD = 3500;//起征点 无 ...
- python subprocess中ssh命令的特殊性
今天尝试使用python 的 subprocess 模块 使用类似如下语句: p=subprocess.Popen(['ssh','root@localhost'],stdout=subprocess ...
- <1>lua编译环境 数据类型和局部变量
1.编译环境 http://www.lua.org/download.html下载 解压后 bin目录中lua.exe运行 luac.exe编译成lua字节码 2.基本数据类型 整数,小数,布尔值 ...
- 6.Daemon线程
1.如下代码: package com.bawei.multithread; public class Recursive { private static int counter = 0; publ ...
- Java基础(basis)-----抽象类和接口详解
1.抽象类 1.1 abstract修饰类:抽象类 不可被实例化 抽象类有构造器 (凡是类都有构造器) 抽象方法所在的类,一定是抽象类 抽象类中可以没有抽象方法 1.2 abstract修饰方法:抽象 ...