Can't import numpy or other Python libraries

88 vues (au cours des 30 derniers jours)
Brian Barry
Brian Barry le 2 Oct 2020
Commenté : Ron le 28 Fév 2024
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.

Réponses (1)

Kojiro Saito
Kojiro Saito le 2 Oct 2020
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 commentaires
Kojiro Saito
Kojiro Saito le 28 Fév 2024
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 le 28 Fév 2024
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by