ImportError: No module named serial
M5stack シリーズのモジュールを使おうと思って、コードをコンパイルしたら怒られた。
code:log
File "/Users/username/Library/Arduino15/packages/m5stack/tools/esptool_py/3.0.0/esptool.py", line 39, in <module>
import serial
ImportError: No module named serial
環境
macOS Catalina 10.15.7
Arduino IDE 1.8.13
M5Stack ボードマネージャ 1.0.5
直接関係ないと思うが、pyenvを使用していて、global環境にanaconda3-2019.03を設定している
解決策
おそらく現象はmac特有のもの
実際
パスを調べる
/Library/Python/2.7/site-packages等のpathを見つける
code:zsh
% python2
WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.
Python 2.7.16 (default, Jun 5 2020, 22:59:21)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
>> import sys
>> print sys.path
'/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC'
>> quit()
pyserialをインストールする
code:zsh
% sudo pip install --target /Library/Python/2.7/site-packages pyserial
Password:
The directory '/Users/username/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/username/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pyserial
100% |████████████████████████████████| 92kB 463kB/s
Installing collected packages: pyserial
Successfully installed pyserial-3.5