用 pylint, 写好代码

赖勇浩(http://laiyonghao.com)

简介

Pylint 是一个 Python 代码分析工具,它分析 Python 代码中的错误,查找不符合代码风格标准(Pylint 默认使用的代码风格是 PEP 8)和有潜在问题的代码。

  • Pylint 是一个 Python 工具,除了平常代码分析工具的作用之外,它提供了更多的功能:如检查一行代码的长度,变量名是否符合命名标准,一个声明过的接口是否被真正实现等等。
  • Pylint 的一个很大的好处是它的高可配置性,高可定制性,并且可以很容易写小插件来添加功能。
  • 如果运行两次 Pylint,它会同时显示出当前和上次的运行结果,从而可以看出代码质量是否得到了改进。
  • 目前在 eclipse 的 pydev 插件中也集成了 Pylint。

目前最好的介绍 pylint 的文章应该是这篇《如何使用 Pylint 来规范 Python 代码风格 》(上面那段文字的来源),但里面讲到的安装方式有点过时了,而且在 windows 下安装的时候,有点小状况:使用 Easy_install 安装完毕之后报告成功安装,但执行时出错:

后来我解决了这个问题,在这里备份一下:

Windows 下的安装

  1. 确保 Python 的安装目录和相应的 Scripts 目录已经在环境变量 path 中
  2. 先到 http://pypi.python.org/pypi/pylint下载安装包,然后解压到某目录,这里假定在 D:/pylint-0.22.0
  3. 进入 D:/pylint-0.22.0 目录,然后在命令行执行以下指令:python setup.py install
  4. 在上一步会出错,但会报告成已经成功安装,这时候需要打开 D:/pylint-0.22.0/bin 目录,然后把那里的所有文件拷贝到 Python 的 Scripts 目录下(如:D:/Python26/Scripts)
  5. 在命令行尝试执行 pylint,如果输出帮助,则表示已经安装成功

 

与 PyDev 集成

PyDev 的安装略过...以下是集成配置的过程:

  1. Window -> preferences -> Pydev -> Pylint,选中 "Use pylint?"
  2. 在 Location of pylint 处输入你安装的 lint.py 的地址,如:D:/pylint-0.22.0/lint.py
  3. 在下方的 Arguments to pass to pylint 处输入 --rcfile="E:/svn/misc/pylint.conf",以使用自己的 pylintrc 配置
  4. Project -> Properties -> PyDev?-PYTHONPATH 增添项目的源文件目录到"Project Source Folders"。
发布了211 篇原创文章 · 获赞 640 · 访问量 363万+
展开阅读全文

安装 tensorflow cpu 版出问题, 求解决办法。 谢谢

11-04

安装 tensorflow cpu 版出问题, 求解决办法。 谢谢 Windows 10 64bits, anaconda-3.4.2(Python3.5.2), tensorflow version 1.11-0, 第一次运行时报错: ImportError: DLL load failed: 动态链接库(DLL)初始化例程失败。 Environment parameter path: C:\Program Files\Microsoft MPI\Bin\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\CUDA\bin64;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\dotnet\;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\lib\x64;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\extras\CUPTI\libx64;C:\Program Files\Microsoft VS Code;C:\Program Files\Anaconda3;C:\Program Files\Anaconda3\Scripts;C:\Program Files\Anaconda3\Library\bin; MSVCP140.DLL在以下2个目录 C:\Program Files\Anaconda3 C:\Program Files\Anaconda3\Library\bin C:\Windows\system32>python Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> C:\Windows\system32>pip install tensorflow Collecting tensorflow Using cached https://files.pythonhosted.org/packages/af/5b/695e2e66feb27742a78f938d8369cc874b5fc7082193c3352c9db599af01/tensorflow-1.11.0-cp35-cp35m-win_amd64.whl Requirement already satisfied: grpcio>=1.8.6 in c:\program files\anaconda3\lib\site-packages (from tensorflow) (1.16.0) Requirement already satisfied: astor>=0.6.0 in c:\program files\anaconda3\lib\site-packages (from tensorflow) (0.7.1) Requirement already satisfied: numpy>=1.13.3 in c:\program files\anaconda3\lib\site-packages (from tensorflow) (1.15.3) Requirement already satisfied: keras-applications>=1.0.5 in c:\program files\anaconda3\lib\site-packages (from tensorflow) (1.0.6) Requirement already satisfied: absl-py>=0.1.6 in c:\program files\anaconda3\lib\site-packages (from tensorflow) (0.6.1) Requirement already satisfied: six>=1.10.0 in c:\program files\anaconda3\lib\site-packages (from tensorflow) (1.10.0) Requirement already satisfied: setuptools<=39.1.0 in c:\program files\anaconda3\lib\site-packages\setuptools-27.2.0-py3.5.egg (from tensorflow) (27.2.0) Requirement already satisfied: protobuf>=3.6.0 in c:\program files\anaconda3\lib\site-packages (from tensorflow) (3.6.1) Requirement already satisfied: keras-preprocessing>=1.0.3 in c:\program files\anaconda3\lib\site-packages (from tensorflow) (1.0.5) Requirement already satisfied: termcolor>=1.1.0 in c:\program files\anaconda3\lib\site-packages (from tensorflow) (1.1.0) Requirement already satisfied: gast>=0.2.0 in c:\program files\anaconda3\lib\site-packages (from tensorflow) (0.2.0) Requirement already satisfied: wheel>=0.26 in c:\program files\anaconda3\lib\site-packages (from tensorflow) (0.29.0) Requirement already satisfied: tensorboard<1.12.0,>=1.11.0 in c:\program files\anaconda3\lib\site-packages (from tensorflow) (1.11.0) Requirement already satisfied: h5py in c:\program files\anaconda3\lib\site-packages (from keras-applications>=1.0.5->tensorflow) (2.6.0) Requirement already satisfied: markdown>=2.6.8 in c:\program files\anaconda3\lib\site-packages (from tensorboard<1.12.0,>=1.11.0->tensorflow) (3.0.1) Requirement already satisfied: werkzeug>=0.11.10 in c:\program files\anaconda3\lib\site-packages (from tensorboard<1.12.0,>=1.11.0->tensorflow) (0.11.11) Installing collected packages: tensorflow Successfully installed tensorflow-1.11.0 错误信息: --------------------------------------------------------------------------- ImportError Traceback (most recent call last) C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>() 57 ---> 58 from tensorflow.python.pywrap_tensorflow_internal import * 59 from tensorflow.python.pywrap_tensorflow_internal import __version__ C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in <module>() 27 return _mod ---> 28 _pywrap_tensorflow_internal = swig_import_helper() 29 del swig_import_helper C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in swig_import_helper() 23 try: ---> 24 _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) 25 finally: C:\Program Files\Anaconda3\lib\imp.py in load_module(name, file, filename, details) 241 else: --> 242 return load_dynamic(name, filename, file) 243 elif type_ == PKG_DIRECTORY: C:\Program Files\Anaconda3\lib\imp.py in load_dynamic(name, path, file) 341 name=name, loader=loader, origin=path) --> 342 return _load(spec) 343 ImportError: DLL load failed: 动态链接库(DLL)初始化例程失败。 During handling of the above exception, another exception occurred: ImportError Traceback (most recent call last) <ipython-input-1-41389fad42b5> in <module>() ----> 1 import tensorflow as tf C:\Program Files\Anaconda3\lib\site-packages\tensorflow\__init__.py in <module>() 20 21 # pylint: disable=g-bad-import-order ---> 22 from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import 23 24 try: C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\__init__.py in <module>() 47 import numpy as np 48 ---> 49 from tensorflow.python import pywrap_tensorflow 50 51 # Protocol buffers C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>() 72 for some common reasons and solutions. Include the entire stack trace 73 above this error message when asking for help.""" % traceback.format_exc() ---> 74 raise ImportError(msg) 75 76 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long ImportError: Traceback (most recent call last): File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module> from tensorflow.python.pywrap_tensorflow_internal import * File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module> _pywrap_tensorflow_internal = swig_import_helper() File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "C:\Program Files\Anaconda3\lib\imp.py", line 242, in load_module return load_dynamic(name, filename, file) File "C:\Program Files\Anaconda3\lib\imp.py", line 342, in load_dynamic return _load(spec) ImportError: DLL load failed: 动态链接库(DLL)初始化例程失败。 Failed to load the native TensorFlow runtime. See https://www.tensorflow.org/install/install_sources#common_installation_problems for some common reasons and solutions. Include the entire stack trace above this error message when asking for help. 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 游动-白 设计师: 上身试试

分享到微信朋友圈

×

扫一扫,手机浏览