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的一些问题及解决办法的更多相关文章

  1. python2含有中文路径报错解决办法[\xe4\xbf\xa1\xe6\x81\xaf]

    如图所示 百度的解决办法大多数是针对python3版本的,在脚本开头加# -*- coding:utf-8 -*-,但是python2版本加了编码格式,还是报错,具体解决办法是:path =unico ...

  2. 安装了Python2.X和Python3.X后Python2.X IDLE打不开解决办法总结

    安装了Python2.X和Python3.X后Python2.X IDLE打不开,两个版本都卸载后重装仍然打不开,在网上找了几种办法,希望对大家能有所帮助 1.首先查看环境变量是否配置正确 配置方法网 ...

  3. 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 == "一年级": ...

  4. Python: 编程遇到的一些问题以及网上解决办法?

    0.Python: TypeError: 'str' does not support the buffer interface,(点我) fp.write(url.encode("utf- ...

  5. 安装Django,运行django-admin.py startproject 工程名,后不出现指定的工程解决办法!!

       第一次写博客,,,,, 在看我这篇教程的前提是你应该已经正确装好python和Django了,好了,废话不说了,正题走你!你现在是不是很纠结自己运行django-admin.py startpr ...

  6. 关于web2py外网访问,图形界面不显示等问题的解决办法

    首先系统版本是ubuntu 15.04,系统默认安装了两个版本的python, sudo python web2py.py 默认会调用python2.7版本来执行 会提示 pydo@planpls:/ ...

  7. Python在安装第三方模块遇到的问题及解决办法

    今天在安装第一个模块psutil的时候出现了以下问题: 1.找不到Python.h文件 解决办法:重新安装python环境:sudo apt-get install python-dev 说明:网上有 ...

  8. [转]编译Android源代码常见错误解决办法

    1. 编译时出现/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libz.so when ...

  9. 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: ...

随机推荐

  1. DLNg[结构化ML项目]第二周迁移学习+多任务学习

    1.迁移学习 比如要训练一个放射科图片识别系统,但是图片非常少,那么可以先在有大量其他图片的训练集上进行训练,比如猫狗植物等的图片,这样训练好模型之后就可以转移到放射科图片上,模型已经从其他图片中学习 ...

  2. python浮窗

    import wx; app = wx.App(); win = wx.Frame(None,title="老穆视频",pos=(900,20),size=(300,60),sty ...

  3. Elasticsearch5.x Head插件安装

    在5.0版本中不支持直接安装head插件,需要启动一个服务. 由于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包.(npm可以理解为maven) 1.安装 ...

  4. .Net拾忆:从List去除重复-拾忆集合

    方法1: private static List<int> DistinctList(List<int> list) {//去除重复 HashSet<int> ha ...

  5. cocos2d-x JS 利用重复动作实现动画播放(实现倒计时)

    cocos2d-js: cc.delayTime() and cc.repeatForever() don't work together in cc.sequence() this.numm = 1 ...

  6. Selenium基础知识(八)文本域处理textarea

    textarea文本域selenium有时处理不了,但是我们可以采用迂回,解决这个问题 那么,我们用到了execute_script()方法来调用javascript来解决这个问题 这其中涉及DOM, ...

  7. Solaris 10主机名和IP地址步骤

    1.修改主机名: hostname newname vi /etc/hosts vi /etc/hostname.e1000g0 vi /etc/nodename init 6 #重启 --confi ...

  8. Lambda表达式语法2

    package airycode_java8.nice3; import airycode_java8.nice1.Employee; import org.junit.Test; import ja ...

  9. Unity shader学习之逐顶点漫反射光照模型

    公式如下: Cdiffuse = Clight * mdiffuse * max(0, dot(n,l)); 其中,n 为表面法线,l 为指向光源的单位向量,mdiffuse 为材质温反射颜色,Cdi ...

  10. html5-移动端布局模板

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...