2018/10/16
今日写了一个书上Python的“外星人入侵”的小游戏,在一步的时候出现报错,错误部分:



该对象对应的类的方法
在对象调用该方法的时候,这里我对象的方法的实参是这么写的:
gf.update_aliens(ai_setting,sb,screen,stats,ship,aliens,bullets),
我类的方法的形参是这么写的:
def update_aliens(ai_setting,screen,stats,sb,ship,aliens,bullets)
错误的原因是形参实参的参数顺序没有一一对应。
2018/10/17
今天在import numpy的时候,出现报错:No module named numpy
这个错误的原因是:pycharm所使用的解释器并不是我电脑上的python3.7,而是自带了python.exe解释器,并且只有两个模块pip和setuptools,这样一来许多第三方库就无法在pycharm中使用。这时候只需要在PyCharm的settings( File->settings->project:当前项目名->Project Interpreter->show all)中设置一下Interpreter就可以了。

2018/10/17 --------2
今天在用pip下载IPython的时候下载超时报错了,查了一下可能是从国外下载速度太慢导致超时,更换成国内的镜像源就好了,然后查了一下,大致操作流程(前提是windows操作系统)是:
在每次下载的时候,命令行写成:pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
永久修改方式:
windows下: 在user目录中创建一个pip目录,如:C:\Users(用户)\xx\pip,新建文件pip.ini,输入代码:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
2018/10/18
今天copy的时候,有句话出现错误,%matplotlib inline这句话显示报错Unresolved reference 'matplotlib'
原因:IPython有一组预先定义好的所谓的魔法函数(Magic Functions),你可以通过命令行的语法形式来访问它们。“%matplotlib inline”就是模仿命令行来访问magic函数的在IPython中独有的形式。
magic函数分两种:一种是面向行的,另一种是面向单元型的。 行magic函数是用前缀“%”标注的,很像我们在系统中使用命令行时的形式,例如在Mac中就是你的用户名后跟着“$”。“%”后面就是magic函数的参数了,但是它的参数是没有被写在括号或者引号中来传值的。单元型magic函数是由两个“%%”做前缀的,它的参数不仅是当前“%%”行后面的内容,也包括了在当前行以下的行。关于%matplotlib inline:
1,是在使用jupyter notebook 或者 jupyter qtconsole的时候,才会经常用到%matplotlib,也就是说那一份代码可能就是别人使用jupyter notebook 或者 jupyter qtconsole进行编辑的。
2,而%matplotlib具体作用是当你调用matplotlib.pyplot的绘图函数plot()进行绘图的时候,或者生成一个figure画布的时候,可以直接在你的python console里面生成图像。
我们在spyder或者pycharm实际运行代码的时候,可以直接注释掉这一句,也是可以运行成功的。
2018/10/18-----2

光标变粗
这种情况是按了键盘上的insert键,再按一下就好了
2018/10/8-----3

跑起来的图横坐标脚注和下一个表的标题重叠了
这种问题大概是因为窗口尺寸巴拉巴拉问题,百度半天没找到解决方法。但是我通过使用如图1的按钮,改变了各个表的位置或者大小

图1

通过改变图2的hspace,窗口中的各个表之间的纵向距离会拉大,修改后,图像就合理多了(见图3)

emmm,后来查到了,可以修改,在matplotlib的官网上有https://matplotlib.org/api/_as_gen/matplotlib.pyplot.subplots_adjust.html
plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None)
left = 0.125 # the left side of the subplots of the figure
right = 0.9 # the right side of the subplots of the figure
bottom = 0.1 # the bottom of the subplots of the figure
top = 0.9 # the top of the subplots of the figure
wspace = 0.2 # the amount of width reserved for blank space between subplots,
# expressed as a fraction of the average axis width
hspace = 0.2 # the amount of height reserved for white space between subplots,
# expressed as a fraction of the average axis height
2018/10/23
今天的问题是,数据分析的代码里,df['Layout'].value_counts()这句话,人家的显示是这样的:

而我在pycharm编辑区弄半天没有显示,

然后我发现是我没有print。。。。。。。。mmp。。今天的问题就是这些

2018/10/25
今天在导入一个库的时候(from Crypto.Cipherimport AES),pip下载下载不了该库:PyCrypto
原因是:PyCrypto 已死,请替换为 PyCryptodome()
这回安装成功了,可是import时候又报错,这回是怎么回事,打开这个库的目录:
AppData\Local\Programs\Python\Python37-32\Lib\site-packages
发现将目录下的crypto文件夹,重命名为Crypto,再import,就不报错了。
2018/10/26
解决问题:

是因为:

我在这里加入encoding='utf-8",即以encoding='utf-8"方式打开文件

不报错了
2018/10/26
今天用pycharm在D:下建立一个项目,发现之前下载的库都没有被导入

问题在于创建项目没有导入本地包
操作如图:


这样子就ok了
如果手贱已经创建好项目了。。。就File==>Settings==>Project:xxx(项目名)==>Project Interpreter==>选择c盘的那个python环境
2018/10/26
今天写的程序不知道哪错了,得调试。。。。。。pycharm的调试是按F8,点击debug。。这点和eclipse像啊,,,好不习惯
转载请注明作者及原链接谢谢合作~~~~~~~~~
网友评论