问题描述
请不要将此标记为如何调用python的副本.和matlab的sklearn?,因为我认为这个问题并未得到真正的回答.
我认为自Matlab R2014b版本以来,可以直接使用来自matlab的python .
简而言之,您只需将py
放在python调用之前.
我进行了设置(使用命令pyversion('PATH_TO_PYTHON')
向matlab提供python路径后,它运行良好.我什至可以使用dask
多重处理.非常酷.例如,执行py.dask.distributed.Client
会导致
Please do not mark this as a duplicate of how to call python and sklearn from matlab? as the question is in my opinion not really answered.
Since Matlab Release R2014b I think, it is possible to directly use python from matlab.
In short words, you only have to place py
in front of the python call.
I my setup (after giving matlab the python path with the command pyversion('PATH_TO_PYTHON')
, that is running fine. I can even use dask
multiprocessing. Quite cool. For example, executing py.dask.distributed.Client
results in
Python Client with properties:
asynchronous: 0
cluster: [1×1 py.distributed.deploy.local.LocalCluster]
get_futures_error: [1×1 py.method]
coroutines: [1×1 py.list]
scheduler_file: [1×1 py.NoneType]
loop: [1×1 py.tornado.platform.select.SelectIOLoop]
recreate_error_locally: [1×1 py.method]
refcount: [1×1 py.collections.defaultdict]
extensions: [1×1 py.dict]
scheduler: [1×1 py.distributed.core.rpc]
rpc: [1×1 py.distributed.core.ConnectionPool]
futures: [1×1 py.dict]
scheduler_comm: [1×1 py.distributed.batched.BatchedSend]
status: [1×7 py.str]
connection_args: [1×1 py.dict]
id: [1×43 py.str]
generation: [1×1 py.int]
io_loop: [1×1 py.tornado.platform.select.SelectIOLoop]
security: [1×1 py.distributed.security.Security]
<Client: scheduler='tcp://127.0.0.1:59795' processes=4 cores=4>
回到问题:我已经安装了sklearn,可以从引用的python安装中使用它.它的工作方式与dask相同.但是MATLAB R2017a无法找到sklearn.
对上面给出的py.sklearn.cluster.dbscan
的类似调用会导致
Coming back to the question: I have sklearn installed and can use it from the referenced python Installation. It is working the same way as dask. But MATLAB R2017a is not able to find sklearn.
A similiar call to the given above py.sklearn.cluster.dbscan
results in
Undefined variable "py" or class "py.sklearn.cluster.dbscan".
是否有任何python专家都能解释?
Is there any python expert being able to explain?
推荐答案
I got a solution from the mathworks Support.
It reads the way, that maybe the python environment is not completely setup. I was asked to start matlab from within the Anaconda Prompt
which has that complete arranged environment. Running matlab from there yielded the wanted results thus being able to use for example sklearn.
Further comparing the diffenrences from there showed up, that some more directories from python have to be added to the systems search path.
我进一步了解到,运行py.importlib.import_module(<MODULENAME>)
会显示该python模块及其依赖项是否可用的详细信息.
Further I learned, that running py.importlib.import_module(<MODULENAME>)
will show details if that python module and its dependencies are available or not.
这篇关于在Matlab中直接在python中使用sklearn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!