IntelliJのvenvにpyminizipをインストールしようとしたら躓いた話


IntellJのpython用 venvにpyminizipをインストールしようとしたところ、エラーが発生  
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/268923/9b7e1f85-716b-9938-1091-f5d2a9311149.png)

エラーログ全文はこんな感じ。  
```
Collecting pyminizip
  Using cached pyminizip-0.2.6.tar.gz (261 kB)
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Building wheels for collected packages: pyminizip
  Building wheel for pyminizip (setup.py): started
  Building wheel for pyminizip (setup.py): finished with status 'error'
  Running setup.py clean for pyminizip
Failed to build pyminizip
Installing collected packages: pyminizip
    Running setup.py install for pyminizip: started
    Running setup.py install for pyminizip: finished with status 'error'

  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\[username]\workspace\[appname]\venv\Scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\[username]\\AppData\\Local\\Temp\\pip-install-kav6k3r3\\pyminizip_de63b8b285284df38006a8051df8a6d1\\setup.py'"'"'; __file__='"'"'C:\\Users\\[username]\\AppData\\Local\\Temp\\pip-install-kav6k3r3\\pyminizip_de63b8b285284df38006a8051df8a6d1\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\[username]\AppData\Local\Temp\pip-wheel-5we2ogcq'
       cwd: C:\Users\[username]\AppData\Local\Temp\pip-install-kav6k3r3\pyminizip_de63b8b285284df38006a8051df8a6d1\
  Complete output (50 lines):
  running bdist_wheel
  running build
  running build_ext
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\[username]\AppData\Local\Temp\pip-install-kav6k3r3\pyminizip_de63b8b285284df38006a8051df8a6d1\setup.py", line 18, in <module>
      setup(
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\__init__.py", line 155, in setup
      return distutils.core.setup(**attrs)
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\_distutils\core.py", line 148, in setup
      return run_commands(dist)
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\_distutils\core.py", line 163, in run_commands
      dist.run_commands()
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\_distutils\dist.py", line 967, in run_commands
      self.run_command(cmd)
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\_distutils\dist.py", line 986, in run_command
      cmd_obj.run()
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\wheel\bdist_wheel.py", line 299, in run
      self.run_command('build')
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\_distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\_distutils\dist.py", line 986, in run_command
      cmd_obj.run()
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\_distutils\command\build.py", line 135, in run
      self.run_command(cmd_name)
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\_distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\_distutils\dist.py", line 986, in run_command
      cmd_obj.run()
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\command\build_ext.py", line 79, in run
      _build_ext.run(self)
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 339, in run
      self.build_extensions()
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 448, in build_extensions
      self._build_extensions_serial()
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 473, in _build_extensions_serial
      self.build_extension(ext)
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\command\build_ext.py", line 202, in build_extension
      _build_ext.build_extension(self, ext)
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 528, in build_extension
      objects = self.compiler.compile(sources,
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\_distutils\_msvccompiler.py", line 327, in compile
      self.initialize()
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\_distutils\_msvccompiler.py", line 224, in initialize
      vc_env = _get_vc_env(plat_spec)
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\msvc.py", line 316, in msvc14_get_vc_env
      return _msvc14_get_vc_env(plat_spec)
    File "C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\msvc.py", line 270, in _msvc14_get_vc_env
      raise distutils.errors.DistutilsPlatformError(
  setuptools._distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
  ----------------------------------------
  ERROR: Failed building wheel for pyminizip
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\[username]\workspace\[appname]\venv\Scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\[username]\\AppData\\Local\\Temp\\pip-install-kav6k3r3\\pyminizip_de63b8b285284df38006a8051df8a6d1\\setup.py'"'"'; __file__='"'"'C:\\Users\\[username]\\AppData\\Local\\Temp\\pip-install-kav6k3r3\\pyminizip_de63b8b285284df38006a8051df8a6d1\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\[username]\AppData\Local\Temp\pip-record-s41mcb8e\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\[username]\workspace\[appname]\venv\include\site\python3.10\pyminizip'
         cwd: C:\Users\[username]\AppData\Local\Temp\pip-install-kav6k3r3\pyminizip_de63b8b285284df38006a8051df8a6d1\
    Complete output (6 lines):
    running install
    C:\Users\[username]\workspace\[appname]\venv\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
      warnings.warn(
    running build
    running build_ext
    error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\[username]\workspace\[appname]\venv\Scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\[username]\\AppData\\Local\\Temp\\pip-install-kav6k3r3\\pyminizip_de63b8b285284df38006a8051df8a6d1\\setup.py'"'"'; __file__='"'"'C:\\Users\\[username]\\AppData\\Local\\Temp\\pip-install-kav6k3r3\\pyminizip_de63b8b285284df38006a8051df8a6d1\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\[username]\AppData\Local\Temp\pip-record-s41mcb8e\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\[username]\workspace\[appname]\venv\include\site\python3.10\pyminizip' Check the logs for full command output.
WARNING: You are using pip version 21.3.1; however, version 22.0.4 is available.
You should consider upgrading via the 'C:\Users\[username]\workspace\[appname]\venv\Scripts\python.exe -m pip install --upgrade pip' command.

```

どうも原因はこいつっぽい
> error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/

というわけでログにしたがって下記の対応をしてみた

https://visualstudio.microsoft.com/ja/visual-cpp-build-tools/
`Build Tools のダウンロード` をクリック

ダウンロードされたexeファイル実行  
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/268923/fbedadcd-23e2-2531-7569-d06f939cdaa3.png)

「C++によるデスクトップ開発」をチェックして「ダウンロードしながらインストールする」  
って思ったら必要な領域が馬鹿でかい  
よって「個別のコンポーネント > MSVC v142-VS 2019C++ x64/x86 ビルド ツール（最新）」「インストール」


> C:/Users/[username]/workspace/[appname]/venv/Scripts/python.exe -m pip install pyminizip

っが、だめ……！
というわけで、再度ダウンロードしたインストーラーを起動して、「C++によるデスクトップ開発」をチェックして「ダウンロードしながらインストールする」「変更」
完了後に再度同じコマンドを実行したら成功した。

> C:/Users/[username]/workspace/[appname]/venv/Scripts/python.exe -m pip install pyminizip