dehio3’s diary

仕事、生活、趣味のメモ

atomにatom-beautify入れてSQL整形しようとしてらエラーが出た

atom-beautifyとは?

atomのパッケージでコードを整形してくれる。

atom.io

事象

sqlを整形しようと.sql拡張子のファイルを開いて、Ctl+Alt+bを実行したところ以下のエラーが出力

Could not find 'sqlformat'. The program may not be installed.
See https://github.com/andialbrecht/sqlparse for program installation instructions.
Your program is properly installed if running 'where.exe sqlformat' in your CMD prompt returns an absolute path to the executable. If this does not work then you have not installed the program correctly and so Atom Beautify will not find the program. Atom Beautify requires that the program be found in your PATH environment variable. 
Note that this is not an Atom Beautify issue if beautification does not work and the above command also does not work: this is expected behaviour, since you have not properly installed your program. Please properly setup the program and search through existing Atom Beautify issues before creating a new issue. See https://github.com/Glavin001/atom-beautify/search?q=sqlformat&type=Issues for related Issues and https://github.com/Glavin001/atom-beautify/tree/master/docs for documentation. If you are still unable to resolve this issue on your own then please create a new issue and ask for help.
Hide Stack Trace
Error: Could not find 'sqlformat'. The program may not be installed.

sqlformatが入っていない?

対応

sqlformatをダウンロード

メッセージに従い「https://github.com/andialbrecht/sqlparse」をダウンロード

modules配下においてみたけど変わらず。

C:\Users\****\.atom\packages\atom-beautify\node_modules

ただsqlformatはダウンロードした中に入っているからうまく認識されていないだけ?

再度エラーを確認してみると以下の記述

あなたのCMDプロンプトが戻るの「where.exe sqlformat」実行ファイルへの絶対パスを実行している場合は、あなたのプログラムが正しくインストールされています。

コマンドへのパス確認

C:\Users\*****>where.exe sqlformat
情報: 与えられたパターンのファイルが見つかりませんでした。

やはりパスが通ってない。

Windows環境変数pathsqlformatのパスを追加

環境変数の設定画面にてpathに以下を追加

C:\Users\tom_tanaka\.atom\packages\atom-beautify\node_modules\sqlparse-master\bin

atom再起動後再実行したところエラーが変わった

'python' �́A�����R�}���h�܂��͊O���R�}���h�A �����\�ȃv���O�����܂��̓o�b�` �t�@�C���Ƃ��ĔF�������Ă��܂����B
'python' �́A�����R�}���h�܂��͊O���R�}���h�A
�����\�ȃv���O�����܂��̓o�b�` �t�@�C���Ƃ��ĔF�������Ă��܂����B

sqlformatを動かすにはpythonが必要

https://github.com/andialbrecht/sqlparseREADMEにインストール方法書いてあった。。

f:id:dehio3:20160324233811p:plain

python使ってインストールしてる。

pythonインストール

以下からダウンロード。手順は割愛。

https://www.python.org/downloads/

C:\Users\tom_tanaka>where python
情報: 与えられたパターンのファイルが見つかりませんでした。

pythonコマンドのパスがとってないから通す。

Windows環境変数pathpythonのパスを追加

環境変数の設定画面にてpathに以下を追加

C:\Python34

READMEの手順に従いインストール

setup.pyのあるディレクトリに移動

cd C:\Users\*****\.atom\packages\atom-beautify\node_modules\sqlparse-master

install実行

C:\Users\****\.atom\packages\atom-beautify\node_modules\sqlparse-master>python setup.py install
running install
running bdist_egg
running egg_info
creating sqlparse.egg-info
writing top-level names to sqlparse.egg-info\top_level.txt
writing sqlparse.egg-info\PKG-INFO
writing dependency_links to sqlparse.egg-info\dependency_links.txt
writing manifest file 'sqlparse.egg-info\SOURCES.txt'
reading manifest file 'sqlparse.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'sqlparse.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build
creating build\lib
creating build\lib\sqlparse
copying sqlparse\compat.py -> build\lib\sqlparse
copying sqlparse\exceptions.py -> build\lib\sqlparse
copying sqlparse\filters.py -> build\lib\sqlparse
copying sqlparse\formatter.py -> build\lib\sqlparse
copying sqlparse\functions.py -> build\lib\sqlparse
copying sqlparse\keywords.py -> build\lib\sqlparse
copying sqlparse\lexer.py -> build\lib\sqlparse
copying sqlparse\pipeline.py -> build\lib\sqlparse
copying sqlparse\sql.py -> build\lib\sqlparse
copying sqlparse\tokens.py -> build\lib\sqlparse
copying sqlparse\utils.py -> build\lib\sqlparse
copying sqlparse\__init__.py -> build\lib\sqlparse
creating build\lib\sqlparse\engine
copying sqlparse\engine\filter.py -> build\lib\sqlparse\engine
copying sqlparse\engine\grouping.py -> build\lib\sqlparse\engine
copying sqlparse\engine\__init__.py -> build\lib\sqlparse\engine
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\sqlparse
copying build\lib\sqlparse\compat.py -> build\bdist.win-amd64\egg\sqlparse
creating build\bdist.win-amd64\egg\sqlparse\engine
copying build\lib\sqlparse\engine\filter.py -> build\bdist.win-amd64\egg\sqlparse\engine
copying build\lib\sqlparse\engine\grouping.py -> build\bdist.win-amd64\egg\sqlparse\engine
copying build\lib\sqlparse\engine\__init__.py -> build\bdist.win-amd64\egg\sqlparse\engine
copying build\lib\sqlparse\exceptions.py -> build\bdist.win-amd64\egg\sqlparse
copying build\lib\sqlparse\filters.py -> build\bdist.win-amd64\egg\sqlparse
copying build\lib\sqlparse\formatter.py -> build\bdist.win-amd64\egg\sqlparse
copying build\lib\sqlparse\functions.py -> build\bdist.win-amd64\egg\sqlparse
copying build\lib\sqlparse\keywords.py -> build\bdist.win-amd64\egg\sqlparse
copying build\lib\sqlparse\lexer.py -> build\bdist.win-amd64\egg\sqlparse
copying build\lib\sqlparse\pipeline.py -> build\bdist.win-amd64\egg\sqlparse
copying build\lib\sqlparse\sql.py -> build\bdist.win-amd64\egg\sqlparse
copying build\lib\sqlparse\tokens.py -> build\bdist.win-amd64\egg\sqlparse
copying build\lib\sqlparse\utils.py -> build\bdist.win-amd64\egg\sqlparse
copying build\lib\sqlparse\__init__.py -> build\bdist.win-amd64\egg\sqlparse
byte-compiling build\bdist.win-amd64\egg\sqlparse\compat.py to compat.cpython-34.pyc
byte-compiling build\bdist.win-amd64\egg\sqlparse\engine\filter.py to filter.cpython-34.pyc
byte-compiling build\bdist.win-amd64\egg\sqlparse\engine\grouping.py to grouping.cpython-34.pyc
byte-compiling build\bdist.win-amd64\egg\sqlparse\engine\__init__.py to __init__.cpython-34.pyc
byte-compiling build\bdist.win-amd64\egg\sqlparse\exceptions.py to exceptions.cpython-34.pyc
byte-compiling build\bdist.win-amd64\egg\sqlparse\filters.py to filters.cpython-34.pyc
byte-compiling build\bdist.win-amd64\egg\sqlparse\formatter.py to formatter.cpython-34.pyc
byte-compiling build\bdist.win-amd64\egg\sqlparse\functions.py to functions.cpython-34.pyc
byte-compiling build\bdist.win-amd64\egg\sqlparse\keywords.py to keywords.cpython-34.pyc
byte-compiling build\bdist.win-amd64\egg\sqlparse\lexer.py to lexer.cpython-34.pyc
byte-compiling build\bdist.win-amd64\egg\sqlparse\pipeline.py to pipeline.cpython-34.pyc
byte-compiling build\bdist.win-amd64\egg\sqlparse\sql.py to sql.cpython-34.pyc
byte-compiling build\bdist.win-amd64\egg\sqlparse\tokens.py to tokens.cpython-34.pyc
byte-compiling build\bdist.win-amd64\egg\sqlparse\utils.py to utils.cpython-34.pyc
byte-compiling build\bdist.win-amd64\egg\sqlparse\__init__.py to __init__.cpython-34.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
installing scripts to build\bdist.win-amd64\egg\EGG-INFO\scripts
running install_scripts
running build_scripts
creating build\scripts-3.4
copying and adjusting bin\sqlformat -> build\scripts-3.4
creating build\bdist.win-amd64\egg\EGG-INFO\scripts
copying build\scripts-3.4\sqlformat -> build\bdist.win-amd64\egg\EGG-INFO\scripts
copying sqlparse.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying sqlparse.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying sqlparse.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying sqlparse.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist\sqlparse-0.2.0.dev0-py3.4.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing sqlparse-0.2.0.dev0-py3.4.egg
Copying sqlparse-0.2.0.dev0-py3.4.egg to c:\python34\lib\site-packages
Adding sqlparse 0.2.0.dev0 to easy-install.pth file
Installing sqlformat script to C:\Python34\Scripts

Installed c:\python34\lib\site-packages\sqlparse-0.2.0.dev0-py3.4.egg
Processing dependencies for sqlparse==0.2.0.dev0
Finished processing dependencies for sqlparse==0.2.0.dev0

atomを再起動して再実行したところ正常に整形されたことを確認