I installed the matlab module for python using this tutorial. Now I'm trying to import matlab.engine module in a .py file that's going to be executed inside Matlab. Here is the process and files:
My test.py file:
# test.py
import matlab.engine
On Matlab, I do:
>> mod = py.importlib.import_module('test');
>> py.reload(mod)
Error msg:
Error using test><module> (line 1)
Python Error: ImportError: No module named engine
In my python file, even inside Matlab, when I just import matlab module, it works, but when I try to import engine, it fails...
How can I import matlab.engine module inside Matlab?
Obs.:
Module matlab imported inside Matlab:
>> py.importlib.import_module('matlab')
ans =
Python module with properties:
Buffer: [1×1 py.type]
<module 'libmwbuffer' from 'C:\MATLAB\R2018b\bin\win64\libmwbuffer.pyd'>
Module matlab imported outside Matlab (cmd.exe, for instance):
>>> import matlab
>>> matlab
<module 'matlab' from 'C:\Python27\lib\site-packages\matlab\__init__.pyc'>
Look at the paths. Is it a conflict?
The import matlab.engine works outside Matlab, if I run in the cmd.exe, for example, it works.
Using Matlab 2018b, Python 2.7. Everything x64. Windows 7.
Related
In a python script file I have:
import sklearn
iris=sklearn.datasets.load_iris()
This works:
$ ipython <this script file>
But now I do in the script file:
import sklearn as sk
iris=sk.datasets.load_iris()
If I do the same as above, I see:
AttributeError: module 'sklearn' has no attribute 'datasets'
This is what I do not understand. Also in interactive ipython the last import and assignment work!
Also:
import scipy as sp
p1=sp.special.expit(Phi#w)
works in a script file (given to ipython)! Looks like the same as above with sklearn where it did not work.
There is a custom module "ETPython" generated by SWIG (consists of ETPython.py and binary _ETPython.so) and a simple script that invokes this module
sample.py
import ETPython
...
There aren't any problems if the script is run in an IDE (pycharm, internal python's IDLE, squish by froglogic so on). But if I'm trying to launch it in python shell in interactive mode or via terminal using
python3 sample.py
there is an error message like:
File "<path_to_file>/example.py", line 12, in <module>
import ETPython
File "<path_to_file>/ETPython.py", line 15, in <module>
import _ETPython
ImportError: dlopen(<path_to_file>/_ETPython.so, 2): Symbol not found: _NSLog
Referenced from: <path_to_file>/_ETPython.so
Expected in: flat namespace
Searching topics, I found that problem is related to wrong paths. So I added some code:
import os, sys
os.chdir("<path_to_dir>")
sys.path.append('<path_to_dir>')
os.system('export PYTHONPATH=<path_to_dir>:$PYTHONPATH')
This code helped to import the module in python shell in interactive mode but launching in terminal is still failing.
So the question is how to make it to work?
I found solution. The SWIG module was compiled incorrectly.
There was option for CMake that suppressed errors for undefined symbols
set(PLATFORM_LIBS "-undefined dynamic_lookup" )
That why the module doesn't contain NSLOG symbol.
The module was recompiled with additional
"-framework Foundation"
in swig_link_libraries statement. And now the module is imported correctly
I've included this line in a script I'm writing:
from skvideo.io import VideoCapture
My script doesn't like this and gives me back:
ImportError: cannot import name 'VideoCapture'
However, when I go into the REPL for Python 3.6 (what I'm using to run my script), I can import skvideo.io just fine. So the trouble lies with VideoCapture, I'm just not sure why it can't import it...
Any ideas?
Thanks!
I'm trying to use the Tensor flow Python module in RStudio using the package rPython. I am able to use the tensor flow module directly from Python.
I have a Python file called "run.py" which imports tensor flow, and I can successfully call it in the command line using "python run.py". However, when I use the rPython package and run the following
> python.load("python/run.py")
Error in python.exec(code, get.exception) : No module named tensorflow
Using the following code produces the same error
python.exec("
import sys
sys.argv = ['']
import tensorflow as tf
")
Error in python.exec("\n import sys\n sys.argv = ['']\n import tensorflow as tf\n ") :
No module named tensorflow
Does anyone know why I get this error?
when i write import win32print in my python command line (IDLE) it works fine and it is imported...
but when i write import win32print in my py file then it gives an error
says no module named win32print
why am i not able to load the module when writing the same statement in a py script...im using windows XP
Check if you are running on the same installation. I'd do that by looking the path:
import sys
print sys.path
And compare the output on IDLE and when you run the .py