sys.pathを書かなくてもライブラリをimportできるようにしたい
ここ数日でPythonに触り始めました。
動画を観ながらライブラリをインストールしてみたもののimport出来ず、様々なサイトを見てなんとか動くようにはなりました。
しかし、sys.path.appendという一行を書かないといけず、これを書かないでライブラリのimportを行えるようにしたいです。
発生している問題・エラーメッセージ
#ライブラリの場所 pip show jpholiday Name: jpholiday Version: 0.1.8 Summary: Pure-Python Japan Public Holiday Generate Home-page: https://github.com/Lalcs/jpholiday Author: Vatis Author-email: vatis@lalcs.com License: MIT License Location: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages #which python3実行結果 /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 #python実行時 /Users/username/.pyenv/versions/3.7.11/bin/python
試したこと
sys.path.appendを記入することで、なんとかimportはできるようになった。
しかし、numpyのimoprtが上手くいかない。
補足情報(FW/ツールのバージョンなど)
numpy実行時のエラー
/Users/username/.pyenv/versions/3.7.11/bin/python /Users/username/Desktop/python_lesson/#4Library.py ['/Users/username/Desktop/python_lesson', '/Users/username/.pyenv/versions/3.7.11/lib/python37.zip', '/Users/username/.pyenv/versions/3.7.11/lib/python3.7', '/Users/username/.pyenv/versions/3.7.11/lib/python3.7/lib-dynload', '/Users/username/.pyenv/versions/3.7.11/lib/python3.7/site-packages'] username@usernameMacBook-Pro-2 ~ % /Users/username/.pyenv/versions/3.7.11/bin/python /Users/username/Desktop/python_lesson/#4Library.py Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/__init__.py", line 23, in <module> from . import multiarray File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/multiarray.py", line 10, in <module> from . import overrides File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/overrides.py", line 6, in <module> from numpy.core._multiarray_umath import ( ModuleNotFoundError: No module named 'numpy.core._multiarray_umath' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/username/Desktop/python_lesson/#4Library.py", line 5, in <module> import numpy as np File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/__init__.py", line 144, in <module> from . import core File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/__init__.py", line 49, in <module> raise ImportError(msg) ImportError: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed. We have compiled some common reasons and troubleshooting tips at: https://numpy.org/devdocs/user/troubleshooting-importerror.html Please note and check the following: * The Python version is: Python3.7 from "/Users/username/.pyenv/versions/3.7.11/bin/python" * The NumPy version is: "1.22.0" and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help. Original error was: No module named 'numpy.core._multiarray_umath'
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/10 10:22