How to import python package with sdk
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I followed the instructions here (https://www.mathworks.com/help/compiler_sdk/ml_code/create-a-python-application-with-matlab-code.html) and successfully created a python package. While I can import the package, when I try to initialize it I get an error saying Pkg.initialize() does not exist. I'm also not sure it installed correctly. When I ran sudo python setup.py install (w/o sudo i get a permissions error) I get the following output.
"running install
running build
running build_py
running install_lib
running install_egg_info
Removing /Library/Python/2.7/site-packages/matlabruntimeforpython-R2017b-py2.7.egg-info
Writing /Library/Python/2.7/site-packages/matlabruntimeforpython-R2017b-py2.7.egg-info
removing 'build/lib' (and everything under it)
'build/bdist.macosx-10.12-intel' does not exist -- can't clean it
'build/scripts-2.7' does not exist -- can't clean it
removing 'build'"
4 comentarios
Kojiro Saito
el 9 de Ag. de 2018
What's you Python codes for calling compiled package? I have tried the document's steps and works without an error.
Respuestas (2)
Kojiro Saito
el 9 de Ag. de 2018
I don't have Mac OS now, so I can't test module installation, but I have tested in Linux OS.
python ./setup.py install
displayed the following output.
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/MagicSquarePkg
copying MagicSquarePkg/__init__.py -> build/lib.linux-x86_64-2.7/MagicSquarePkg
copying MagicSquarePkg/MagicSquarePkg.ctf -> build/lib.linux-x86_64-2.7/MagicSquarePkg
running install_lib
running install_egg_info
Removing /usr/local/lib/python2.7/dist-packages/matlabruntimeforpython-R2018a.egg-info
Writing /usr/local/lib/python2.7/dist-packages/matlabruntimeforpython-R2018a.egg-info
removing 'build/lib.linux-x86_64-2.7' (and everything under it)
'build/bdist.linux-x86_64' does not exist -- can't clean it
'build/scripts-2.7' does not exist -- can't clean it
removing 'build'
I have a concern that in your case, there's no "creating" and "copying" descriptions, so I guess your module was not installed properly.
Could you clean-up the module first,
python ./setup.py clean
and reinstall it again?
python ./setup.py install
3 comentarios
Kojiro Saito
el 11 de Ag. de 2018
Editada: Kojiro Saito
el 13 de Ag. de 2018
Two things I want to confirm.
(1) Is there any MagicSqrPkg.py file in your current direcotry? It would cause module conflict.
(2) Does this 'no attribute initialize' error occur in Python command line (call 'python TestPkg.py' in Terminal, not via iPython)? As this document says, rather than python commands, we need to use mwpython command, so, matlabroot/bin/mwpython ./TestPkg.py is a correct command.
Joseph Ziminski
el 9 de Dic. de 2019
Editada: Joseph Ziminski
el 9 de Dic. de 2019
I had the same problem, not sure if this solution would work for you but what (at least has initially) seemed to fix it:
Finding package at 'C:\Users\Owner\Anaconda3\envs\RealptoMatlab\Lib\site-packages\magSq' there is a 'magic_square' folder (my mat file was 'magic_square.m', I set the namespace to 'magSq' when compiling), '_pycache_' and '__init__.py'. However the files contained in other working modules are all found only in the 'magic_square' folder, including a .ctf file. As such in the ..\magSq folder I deleted '_pycache_' and '__init__.py'. Then I copied the contents of 'magic_square' (which also includes a _pycache _ and the init file) into the magSq folder and deleted the empty 'magic_square' folder. Then it seems to find .initilise() etc.
Not sure why this happened, the only difference between this and other working modules is that I compiled it with a namespace, but feels unlikely that is the cause.
UPDATE: to finally get it working I had to change the file name of 'magic_square.ctf' to 'magSq.ctf' and it worked.
0 comentarios
Ver también
Categorías
Más información sobre Python Client Programming en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!