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: ...
随机推荐
- Centos的升级与更新
系统升级(6.5->7.2): 这里拿Centos6升级到Centos7为例: 1.查看当前CentOS版本cat /etc/redhat-release 2.更新源vim /etc/yum.r ...
- cocos2dx 3.x(游戏中的储存-UserDefault)
引擎提供的UserDefault可以简单地储存游戏中的信息,例如背景音乐音效的开关状态,用户名等等. UserDefault是一个单例对象,可以用getInstance方法来获得. 如果是第一次调 ...
- 49.CSS--- 特殊css3效果展示
1.设置多行文本超出显示省略号<div class="caption"> <p>显示超过两行就显示省略号,其余隐藏,隐藏不了的情况下给这个模块添加一个高度和 ...
- Hibernate.编写xml文件无自动提示信息
Hibernate.编写xml文件无自动提示信息 注意: 配置 xxxx.hbm.xml 文件的自动提示.和配置 hibernate.cfg.xml 文件的提示,操作步骤是一样的.只是复制的文件内容. ...
- 图片和base64互转
最近项目需要将图片以base64编码,这里记录下相关的一些东西. 需要导入两个类:sun.misc.BASE64Encoder sun.misc.BASE64Decoder 下面是相关java代码: ...
- 有关g++的Xlinker选项
事情的起因是,在使用Eclipse配置opencv的库时,发现使用-Wl 选项需要自己在Linker flags的输入框里指定.并不是像使用-l选项或-I选项那样可以直接添加选项的条目就可以了.但是在 ...
- 解决sqlserver修改被阻止的提示
https://jingyan.baidu.com/article/f79b7cb3664f299144023ef8.html 工具——选项——选择designers---表设计器和数据库设计器,将阻 ...
- Java IO留存查看
IO也可以写作为 "i/O" ,也可以理解为In和Out,即输入与输出.所以,IO体系的基本功能就是: 读和写. IO流作用:读写设备上的东西,硬盘文件.内存.键盘.网络... 根 ...
- 《A Structured Self-Attentive Sentence Embedding》(注意力机制)
Background and Motivation: 现有的处理文本的常规流程第一步就是:Word embedding.也有一些 embedding 的方法是考虑了 phrase 和 sentence ...
- 激活win10
网盘地址 http://pan.baidu.com/s/1nvc5I1V 里面是2个东西,一个是rar解压缩软件,一个是激活工具本体 一个解压缩软件,一个激活工具的压缩包 安装解压软件,就是WINRA ...