使用Geany编辑器运行
# encoding=utf-8 import jieba seg_list = jieba.cut("我来到北京清华大学", cut_all=True) print("Full Mode: " + "/ ".join(seg_list)) # 全模式执行提示,SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xce in position 0: invalid continuation byte
一般解决办法是在代码中加# encoding=utf-8,同时需要对Geany编辑器设置,文档—>设置文件编码—>Unicode—>Unicode(UTF-8)
创建RandomWalk()类,函数fill_walk()来调用,使用Geany编辑器运行
# encoding=utf-8 from random import choice class RandomWalk(): """一个生成随机漫步数据的类""" def _init_(self, num_points = 500): """初始化随机漫步的属性""" self.num_points = num_points # 所有随机漫步都始于(0,0) self.x_values = [0] self.y_values = [0] .... # encoding=utf-8 import matplotlib.pyplot as plt from random_walk import RandomWalk #创建一个RandomWalk实例,并将其包含的点位都绘制出来 rw = RandomWalk() rw.fill_walk() plt.scatter(rw.x_values,rw.y_values, s=15) plt.show()执行提示,while len(self.x_values)< self.num_points: AttributeError: 'RandomWalk' object has no attribute 'x_values'
Python创建类的__init__一定要两边是双下划线!!!
执行提示,ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接
怀疑是requests过于频繁,被api.github认为是攻击行为。可以修改如下:
# encoding=utf-8 import requests import pygal import socket import time from pygal.style import LightColorizedStyle as LCS,LightenStyle as LS # 执行API调用并存储响应 url = 'https://api.github.com/search/repositories?q=language:python&sort=stars' time.sleep(2) requests.packages.urllib3.disable_warnings() r = requests.get(url,verify=False) print("Status code:",r.status_code) ....CreateFile() Error: 5是win10系统经常会出现的,就是权限问题。 所以这里我们去注册表把权限给关闭掉。 打开注册表: regedit HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System 修改这个路径下的键值:EnableLUA 从1 设置为0
ImportError: Could not find the DLL(s) 'msvcp140_1.dll'. TensorFlow requires that these DLLs be installed in a directory that is named in your %PATH% environment variable.
https://support.microsoft.com/zh-cn/help/2977003/the-latest-supported-visual-c-downloads 重新下载64位的vc_redist.x64.exe 文件,安装后重启就好了
D:\Python\Keras\Lib\site-packages\tensorflow\python\keras\datasets\mnist.py 里面的mnist.npz文件默认是从https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz下载的,可能大陆网无法登录获取,可以自己定义文件路径。Downloading data from mnist.npz文件下载地址如下,我们可以将该文件替换到mnist.py中。 https://s3.amazonaws.com/img-datasets/mnist.npz
改成
path = 'D:/Python/machinemnist.npz' f = np.load(path) x_train, y_train = f['x_train'], f['y_train'] x_test, y_test = f['x_test'], f['y_test'] f.close()提示ModuleNotFoundError: No module named 'urllib2' 在python3里面,用urllib.request代替urllib2
关于解决’\u’开头的字符串转中文的方法。
print(content)改成
print(content.decode('unicode_escape'))