Can't import numpy or other Python libraries

90 ビュー (過去 30 日間)
Brian Barry
Brian Barry 2020 年 10 月 2 日
コメント済み: Ron 2024 年 2 月 28 日
I am trying to use a matlab wrapper for a Python library that requires numpy, along with some other dependencies. I do not have admistrator permissions on this computer (so cannot use pip or other protocols to install numpy) and have to resort to installing these libraries on user space rather than system space. I have started this process by downloading the numpy library from github. Next, I added the path where I downloaded numpy. Then I used py.importlib.import_module() with arguments 'numpy' and even the full location of numpy and both times received an error:
Error using <frozen importlib>_find_and_load_unlocked (line 953)
Python Error: ModuleNotFoundError: No module named '/home/brian/Packages/numpy'
Error in <frozen importlib>_find_and_load (line 971)
Error in <frozen importlib>_gcd_import (line 994)
Error in __init__>import_module (line 126)
return _bootstrap._gcd_import(name[level:], package, level)
I'm not sure I'm doing the right thing here, and was wondering what I'm doing wrong or if there are alternatives that will solve my issue.

回答 (1 件)

Kojiro Saito
Kojiro Saito 2020 年 10 月 2 日
You need to add your packages directory in your python's search path.
Here is an example.
pysys = py.sys.path;
pysys.append('/home/brian/Packages')
np = py.importlib.import_module('numpy');
np.array(10)
Or, instead of using py.sys.path.append, you can use PYTHONPATH enviroment.
  8 件のコメント
Kojiro Saito
Kojiro Saito 2024 年 2 月 28 日
The post was in 2020. In those days, setup.py was included in numpy. You can find it in the other branches, for example, https://github.com/numpy/numpy/tree/maintenance/1.26.x.
You can change the package directory with pip install..
pip install --target=C:\Temp\Packages numpy
Ron
Ron 2024 年 2 月 28 日
Sir thankyou so much for your kind attention. I want to use acoular, a python library, in matlab but i dont know how to do it. I have downloaded the file from Github Acoular, I have installed python 3.10 for my matlab 2023a. Can you help me for the same?? thankyou so much. The command " pip " will it work in matlab too? Sorry but i have no idea about python.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by