AstroNvimをインストールしてみる。

この2年ほどVS Codeを使っていたのだけれど、編集作業はVimのほうが馴染んでるというのもあって、ふと目にしたAstroNvimの記事に触発されて、またNeovimに戻ろうかな、などと思い立ち。

AstroNvimのGetting Startedの内容に従って進めていきます。

まず、事前に必要なもの。

  • Nerd Fonts (Optional with manual intervention: See Recipes/Customizing Icons) [1]
  • Neovim v0.8+ (Not including nightly)
  • Tree-sitter CLI (Note: This is only necessary if you want to use auto_install feature with Treesitter)
  • A clipboard tool is necessary for the integration with the system clipboard (see :help clipboard-tool for supported solutions)
  • Terminal with true color support (for the default theme, otherwise it is dependent on the theme you are using) [2]

Optional Requirements:

  • ripgrep - live grep telescope search (<leader>fw)
  • lazygit - git ui toggle terminal (<leader>tl or <leader>gg)
  • go DiskUsage() - disk usage toggle terminal (<leader>tu)
  • bottom - process viewer toggle terminal (<leader>tt)
  • Python - python repl toggle terminal (<leader>tp)
  • Node - Node is needed for a lot of the LSPs, and for the node repl toggle terminal (<leader>tn)

Neovimはリリースの一番新しい0.9.4をダウンロードして展開しました。

Nerd Fontは、すべて必要な記号フォントを含んでいるとのことで、自分好みのフォントを選択します。自分は普段はMyricaM Monoを使っているので、そのASCII文字フォントのベースとなっているInconsolataに近いNoto Nerd Fontを使ってみることにします。手間がかかりそうですが、記号部分だけを手持ちのフォントにマージして使うこともできるようですから、日本語を使う際にはそちらのほうがいいかもしれません。

Tre-sitter CLIはcargoまたはnpmでインストールできるようですが、pre-builtバイナリも提供されているようなので、そちらを使ってみます。pre-builtバイナリにはexe形式のバイナリが入っていますので、これを展開したnvim/binディレクトリに配置します。

フルカラーをサポートしたターミナルは、Windows Terminalを使えばいいかと思うのでそのままで。

クリップボードツールは、Windowsの場合にはwin32yankを使うようです。これはデフォルトでneovimのアーカイブに含まれているのでそのままで。

その他のオプションでは、ripgrepは常用しているのでOK、Pythonも常用しているのでOK、あとは追追という事にします。

次に、Installationに従って、古いNeovimの設定をバックアップしておきます。

Move-Item $env:LOCALAPPDATA\nvim $env:LOCALAPPDATA\nvim.bak

ただし、$XDG_CONFIG_HOMEが設定されていると、nvimディレクトリは $HOME/.config/nvimになります。

Move-Item $env:XDG_CONFIG_HOME\nvim $env:XDG_CONFIG_HOME\nvim.bak

nvim-dataもバックアップしておきます。

Move-Item $env:LOCALAPPDATA\nvim-data $env:LOCALAPPDATA\nvim-data.bak

最後に、AstroNvimのリポジトリをクローンします。

git clone --depth 1 https://github.com/AstroNvim/AstroNvim $env:LOCALAPPDATA\nvim

ここでも、$XDG_CONFIG_HOMEが設定されている場合には変更します。

git clone --depth 1 https://github.com/AstroNvim/AstroNvim $env:XDG_CONFIG_HOME\nvim

起動してもいいのですが、とりあえず使用したいLSPとしてpyrightを、またNeovimのPythonバインディングのpynvimをインストールします。

pip install pyright pynvim

そしてWindows TerminalのPowerShellプロンプトからnvimを起動すると、いろいろと裏で設定してくれます。

一部文字が化けているので、Windows TerminalでAstroNvim専用のプロファイルを作成し、インストールしたNerd Fontを使用するように設定を変更します。

それから、ccかgccかclangかなんかのCコンパイラが見つからない、と言われるので、Visual Studioはインストールしてあるのだけれどzigというのを入れてみました。ダウンロードしたアーカイブを展開してパスを通すだけですみます。

使い方は徐々に覚えねば。


WindowsのPython3にmysqlclientをインストールする。

単純に
$ pip install mysqlclient
ではエラーを吐いてインストールできなかったので、やったことメモ。

コンソールからpipすると、以下のような感じでエラーになってしまいます。
> pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-2.2.0.tar.gz (89 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for mysqlclient (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [46 lines of output]
      # Options for building extention module:
        library_dirs: ['C:/mariadb-connector\\lib\\mariadb', 'C:/mariadb-connector\\lib']
        libraries: ['kernel32', 'advapi32', 'wsock32', 'shlwapi', 'Ws2_32', 'crypt32', 'secur32', 'bcrypt', 'mariadbclient']
        extra_link_args: ['/MANIFEST']
        include_dirs: ['C:/mariadb-connector\\include\\mariadb', 'C:/mariadb-connector\\include']
        extra_objects: []
        define_macros: [('version_info', (2, 2, 0, 'final', 0)), ('__version__', '2.2.0')]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-312
      creating build\lib.win-amd64-cpython-312\MySQLdb
      copying src\MySQLdb\connections.py -> build\lib.win-amd64-cpython-312\MySQLdb
      copying src\MySQLdb\converters.py -> build\lib.win-amd64-cpython-312\MySQLdb
      copying src\MySQLdb\cursors.py -> build\lib.win-amd64-cpython-312\MySQLdb
copying src\MySQLdb\release.py -> build\lib.win-amd64-cpython-312\MySQLdb copying src\MySQLdb\times.py -> build\lib.win-amd64-cpython-312\MySQLdb copying src\MySQLdb\_exceptions.py -> build\lib.win-amd64-cpython-312\MySQLdb copying src\MySQLdb\__init__.py -> build\lib.win-amd64-cpython-312\MySQLdb creating build\lib.win-amd64-cpython-312\MySQLdb\constants copying src\MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-cpython-312\MySQLdb\constants copying src\MySQLdb\constants\CR.py -> build\lib.win-amd64-cpython-312\MySQLdb\constants copying src\MySQLdb\constants\ER.py -> build\lib.win-amd64-cpython-312\MySQLdb\constants copying src\MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-cpython-312\MySQLdb\constants copying src\MySQLdb\constants\FLAG.py -> build\lib.win-amd64-cpython-312\MySQLdb\constants copying src\MySQLdb\constants\__init__.py -> build\lib.win-amd64-cpython-312\MySQLdb\constants running egg_info writing src\mysqlclient.egg-info\PKG-INFO writing dependency_links to src\mysqlclient.egg-info\dependency_links.txt writing top-level names to src\mysqlclient.egg-info\top_level.txt reading manifest file 'src\mysqlclient.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' adding license file 'LICENSE' writing manifest file 'src\mysqlclient.egg-info\SOURCES.txt' copying src\MySQLdb\_mysql.c -> build\lib.win-amd64-cpython-312\MySQLdb running build_ext building 'MySQLdb._mysql' extension creating build\temp.win-amd64-cpython-312 creating build\temp.win-amd64-cpython-312\Release creating build\temp.win-amd64-cpython-312\Release\src creating build\temp.win-amd64-cpython-312\Release\src\MySQLdb "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD "-Dversion_info=(2, 2, 0, 'final', 0)" -D__version__=2.2.0 -IC:/mariadb-connector\include\mariadb -IC:/mariadb-connector\include -IC:\Apps\Python312\include -IC:\Apps\Python312\Include "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\ATLMFC\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /Tcsrc/MySQLdb/_mysql.c /Fobuild\temp.win-amd64-cpython-312\Release\src/MySQLdb/_mysql.obj _mysql.c src/MySQLdb/_mysql.c(29): fatal error C1083: include ファイルを開けません。'mysql.h':No such file or directory error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.37.32822\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for mysqlclient Failed to build mysqlclient ERROR: Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects
PyPIのmysqlclientのページには、wheelがどっかにあるのでそれ使ってね、でももし使ってるバージョンのPython用のバイナリがなければ、自分でビルドしてね、と書いてあります。
To build from source, download the MariaDB C Connector and install it. It must be installed in the default location (usually "C:\Program Files\MariaDB\MariaDB Connector C" or "C:\Program Files (x86)\MariaDB\MariaDB Connector C" for 32-bit).
なので、上記のリンクから MariaDB Connector/C の Windows 64bit 用をダウンロードしてインストールします。
ところが、上記のエラーメッセージを見ると、ヘッダファイルとライブラリを探しにくのは 'C:/mariadb-connector' となっているので、デフォルトの 'C:/Program Files/mariadb-connector/MariaDB/MariaDB Connector C 64-bit'へは探しに行ってくれません。
別の場所にインストールしたら環境変数 MYSQLCLIENT_CONNECTOR を設定しろと書いてありますが、それもめんどくさいので、指定されている 'C:/mariadb-connector' に中身をまるごとコピーしてから pip します。

> pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-2.2.0.tar.gz (89 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (pyproject.toml) ... done
  Created wheel for mysqlclient: filename=mysqlclient-2.2.0-cp312-cp312-win_amd64.whl size=193628 sha256=1f5f38e2b183905d5b39f7edf7542c7b530123c3031016a460379cbc50d45de1
  Stored in directory: c:\users\kats\appdata\local\pip\cache\wheels\03\31\a0\f0056b8be9d1dc4eb1287b268b5d5dbbe0b206362d8aa35967
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.2.0
ということでインストールできました。…などと書いている途中で、MariaDBなどというパッケージを見つけてしまいました。

どっちがいいんでしょうか…。

ついでにもうちょっと探したら、PyMySQLというのも見つけました。どうやら皆さん、こちらを使っている模様。

Windowsでシンボリックリンクを試してみる。

きっかけは、1つのファイルを別の名前で起動したら違う動きになるようなスクリプトを書く、でした。  busybox なんかでは、同じ実行形式ファイルの名前を、lsにすればlsと同じ、cpとすればcpと同じ動作をするようにしてますが、Pythonスクリプトでそれと同じように argv...