Running python script in Matlab: importError: no module named requests

4 ビュー (過去 30 日間)
Erlend Barstad
Erlend Barstad 2020 年 11 月 12 日
コメント済み: Erlend Barstad 2020 年 11 月 13 日
Hi!
Im trying to run a python script in Matlab through: system('python path/fileName.py');
But i'm getting the following error:
"import requests ImportError: No module named requests".
After some reading at the forums i redefined the "pyversion"-path as seen below:
The python script is containing the following libraries:
"import requests import datetime import json"
By comparing the pyversion.library to the path of the pip-installed library "requests" i can see a differense:
path of installed 'request': Location: /Users/Erl3nd/opt/anaconda3/lib/python3.7/site-packages.
How to i redefine the library definition in pyversion?
or is it another way to import the result of the pythonscript?
pls help me :)
  2 件のコメント
Clyde James Felix
Clyde James Felix 2020 年 11 月 12 日
Hi,
I encountered a problem like this and here are some of the ways I handled it. You can try these and see if it solves your problem.
  • Add the following line in your MATLAB code
py.sys.setdlopenflags(int32(10));
py.importlib.import_module('ssl');
If you are trying to run a python script filename.py and it exist in your path, add this in the following line
py.importlib.import_module('filename');
Then run your python code.
  • You can set a LD_PRELOAD environment variable first to launch MATLAB by running the following in your terminal. Something like this
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6 matlab
Then run your code
Hope this helps:)
Erlend Barstad
Erlend Barstad 2020 年 11 月 13 日
Thanks for helping.
it did not quite solve the problem...
I solved it by dowloading the newest matlab version 2020b, and used the "pyenv" function to set the executable path.
in addtidion, i added the .py-file in the same folder as the matlab-script, and include "mod = py.importlib.import_module('requests')" before the system function.

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

回答 (0 件)

カテゴリ

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

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by