Calling octave .m function from python not executing - python-3.x

I understand this question has been asked multiple times and answered in different forums but it looks like there are variants of the issue and mine is probably, slightly different.
Let me explain. I am trying to call a octave function which I had written for plotting and I don't want to re-write it again python. Therefore I did the following:-
1. install the oct2py
2. setup the OCTAVE_EXECUTABLE= c:\Octave\Octave-4.2.1\bin\octave-gui.exe
3. did the following in the code:-
#importing oct2py
from oct2py import octave as oc
oc.addpath("C:\\personal\\learning\\octave-lib") #containing my octave .m files
#Now I am trying to call a plot function written in octave called displayData.m
oc.displayData(X) # where X is a numpy matrix for plotting
However on executing call to the method gives no errors - but it does not do anything. I see a windows shell prompt opening & closing but nothing else.
I have also tried to replace octave-gui-4.2.1.exe with octave-cli-4.2.1.exe following the suggesting from some sites but I was getting errors that bulk of the windows dll required were not found.
I started with the advice from the oct2py site asking me to just add the path to the folder containing octave.exe ( note that this folder contains all the octave executable) , but that resulted in windows permission errors. There should not be any reason for this error since I am the only user on my windows laptop and have administrative privileges. I am getting the following errors:-
File "mcclassifier.py", line 21, in <module>
from oct2py import octave as oc
File "C:\Users\Sam\Anaconda3\lib\site-packages\oct2py\__init__.py", line
38, in <module>
octave = Oct2Py()
File "C:\Users\Sam\Anaconda3\lib\site-packages\oct2py\core.py", line 73,
in __init__self.restart()
File "C:\Users\Sam\Anaconda3\lib\site-packages\oct2py\core.py", line 508, in restart logger=self.logger)
File "C:\Users\Sam\Anaconda3\lib\site-packages\octave_kernel\kernel.py",
line 144, in __init__
self.repl = self._create_repl()
File "C:\Users\Sam\Anaconda3\lib\site-packages\octave_kernel\kernel.py",
line 338, in _create_repl
version = subprocess.check_output(version_cmd).decode('utf-8')
File "C:\Users\Sam\Anaconda3\lib\subprocess.py", line 336, in check_output
**kwargs).stdout
File "C:\Users\Sam\Anaconda3\lib\subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\Sam\Anaconda3\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\Sam\Anaconda3\lib\subprocess.py", line 990, in
_execute_child startupinfo)
PermissionError: [WinError 5] Access is denied
I tried to run it from Spyder IDE and also from the command line. Both have the identical behavior. Its been frustrating , so any suggestion to get me past this issue will be a big help !!
ADDITIONAL INFORMATION:-
Probably I was not very clear above, but what I am trying to do is to execute a plotting function which i had implemented in octave, & is working.
I made some changes to my python code to see if I can instantiate the Oct2Py class and then call feval function. I commented the previous lines of code above and added the following:-
octave=oct2py.Oct2Py()
octave.feval('C:\\personal\\learning\\octave-lib\displayData',Xmat,timeout=80)
I can see from the windows taskbar that octave-gui.exe being invoked and is seen as running in the background. But it is still not plotting and there is no error.
How do I make it run as foreground process and render the plot. What I want to do is similar to what is shown in the oct2py demo example at:-
http://blink1073.github.io/oct2py/source/demo.html.
As you can see that oc.plot([1,2,3],...) renders the plot.
I will greatly appreciate any help here ?

Related

Able to start module in terminal but not with PyCharm's run config

General Problem
I have already been able to run a certain module from the terminal. No I want to run the module with the run config on PyCharm. However it fails, even though I think I use the same configurations as in the terminal command. Or am I wrong?
The terminal command is:
lukas#lukas-XXXX:~/PycharmProjects/synapse$ source ./env/bin/activate
(env) lukas#lukas-XXXX:~/PycharmProjects/synapse$ python -m synapse.app.homeserver --config-path homeserver.yaml
For the run config I used the basic Python template and only changed the Module name, Parameters and Working directory. The Python interpreter should be the same as the environment that I have activated in the above command. Here is the config:
Running this produces the following error:
Traceback (most recent call last):
File "/usr/lib/python3.8/runpy.py", line 185, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/lib/python3.8/runpy.py", line 111, in _get_module_details
__import__(pkg_name)
File "/home/lukas/PycharmProjects/synapse/synapse/app/__init__.py", line 18, in <module>
from synapse import python_dependencies # noqa: E402
File "/home/lukas/PycharmProjects/synapse/synapse/python_dependencies.py", line 29, in <module>
logger = logging.getLogger(__name__)
AttributeError: module 'logging' has no attribute 'getLogger'
Used Module
The module is from the synapse project from matrix.org. The terminal command can be found here.
Assumptions and Observations I have so far
My assumption is that the logging module accessed in python_dependencies.py line 29 is resolved differently, depending on whether I start the module via the terminal or via PyCharm's run config. Using the terminal, it probably resolves to Python's standard libary module. Using the Run Config, it definitively uses synapse's logging package. Also, when using PyCharm to navigate to the logging package referenced to in python_dependencies.py, PyCharm gets me to synapse's custom logging module.
Question
The big question is: Why? Shouldn't my Run Configuration do exactly the same as my terminal command? What am I missing?
Ok, somehow removing the marks at
Add content roots to PYTHONPATH and
Add source roots to PYTHONPATH
solved the issue.

ffmpeg-python wrapper ffmpeg.run() getting FILENOTFOUNDERROR

I'm trying to figure out and learn how to use the ffmpeg-python wrapper and am getting a file not found error. both the mp4 file I'm trying to process and the python file are both in a folder on my desktop. I'm not sure if I'm using it correctly here.
I'm running windows 10 32bit, python 3.6 and have ffmpeg-python 0.16.0 installed. Is there additional packages I need installed in order for this to work? I tried the same code on my 64 bit windows 10 desktop and got the same error.
import ffmpeg
videoInput = ffmpeg.input('vid.mp4')
videoOutput = videoInput.output('test.avi')
videoOutput.run()
This is the error that I get in python shell
Traceback (most recent call last):
File "C:\Users\geral\Desktop\PythonPrograms\ffmpegexample.py", line 7, in <module>
videoOutput.run()
File "C:\Users\geral\AppData\Local\Programs\Python\Python36-32\lib\site-packages\ffmpeg\_run.py", line 300, in run
overwrite_output=overwrite_output,
File "C:\Users\geral\AppData\Local\Programs\Python\Python36-32\lib\site-packages\ffmpeg\_run.py", line 272, in run_async
args, stdin=stdin_stream, stdout=stdout_stream, stderr=stderr_stream)
File "C:\Users\geral\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Users\geral\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Well I figured it out and it was actually really quite simple. Hopefully this will help anyone who is new to ffmpeg or ffmpeg-python.
After reading through the traceback: Probably 100 times. I realised that ffmpeg probably wasn't packaged with ffmpeg-python and I never installed ffmpeg myself. So I simply installed ffmpeg using This Installation Guide and everything worked.
I Probably have this memorised by now, Ive read it enough times.
ffmpeg-python API Reference
So Long story short you must have ffmpeg installed before ffmpeg-python will work.

Reading .doc files in python on windows 10

Note: This was flagged as a potential duplicate of this, but the point of my question is that using textract doesn't work. I am looking either for (a) a way to get textract to work on windows 10 or (b) an alternate solution.
I am building a system that needs to read various types of files. I have set up pdfminer to read the .pdfs, and based on the process outlined here I installed textract, and I can now also read .docx files. However textract relies on antiword for reading .doc files and I cannot get this to work, even after following the directions here I could not find and install a working version of antiword. I do not have microsoft word installed on my machine, and I am running windows 10 with python 3.6.5. Is there any other way to read .doc files?
Here is the bug when running textract.process('d.doc') (ignore the first error, the file is definitely there):
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\textract\parsers\utils.py", line 84, in run
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\textract\parsers\__init__.py", line 77, in process
return parser.process(filename, encoding, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\textract\parsers\utils.py", line 46, in process
byte_string = self.extract(filename, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\textract\parsers\doc_parser.py", line 9, in extract
stdout, stderr = self.run(['antiword', filename])
File "C:\ProgramData\Anaconda3\lib\site-packages\textract\parsers\utils.py", line 91, in run
' '.join(args), 127, '', '',
textract.exceptions.ShellError: The command antiword d.doc failed with exit code 127
From the 'Windows installation problem' series: https://github.com/deanmalmgren/textract/issues/194#issuecomment-507243521
After following the steps to 'install' antiword, I was facing the same problem as yours.
Restarting windows after setting up the environment path variable entirely solved this exact error message for me. (This was the last error I was facing for handling .doc files with textract)
Installation instructions extracted from https://github.com/deanmalmgren/textract/issues/194#issuecomment-506065817
"Install Antiword
(I followed Reading .doc file in Python using antiword in Windows (also .docx))
Go to https://www.softpedia.com/get/Office-tools/Other-Office-Tools/Antiword.shtml
Extract to c:\antiword (yes it's required to be in the root directory)
Add location to path like we did tesseract-ocr [basically add c:\antiword to the system path (environment variable)]"
I was able to get part of the text using olefile, but olefile ultimately only handles bytes and does not handle the encoding of Word .doc files. The solution is to use LibreOffice, see my other question here

Error in using pyexiv2 metadata.read() method

I am trying to follow the tutorials in the pyexiv2 tutorials page
But due to some unknown reasons, it refuses to run, and I thought of seeking some advice from you.
`#this is my code
import pyexiv2
metadata = pyexiv2.ImageMetadata('test.png')
metadata.read()`
when I try to run this code in the terminal, with the python interpreter, in the folder which contains the image, 'test.png', following error is given.
`Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/pyexiv2/metadata.py", line 107,
in read
self.__image = self._instantiate_image(self.filename)
File "/usr/lib/python2.7/dist-packages/pyexiv2/metadata.py", line 74,
in
_instantiate_image
raise IOError(ENOENT, os.strerror(ENOENT), filename)
IOError: [Errno 2] No such file or directory: 'test.png'
`
This is my setup. I am running ubuntu 16.04LTS on virtual machine on a Mac book, with macOS sierra. Python version is 2.7.12.
I used this guide to install pyexiv2. when I inspect the /usr/local/lib folder, it shows that the libexiv2 is installed there.
What am I doing wrong here? and is there a better version of pyexiv2 to use?
I am fairly new to using python.:) and thanks in advance
This can be solved in two ways
1) Copy the file test.png in the same directory you have your python file with the code.
2) Provide a complete path. If, for example, you have test.png on your desktop, replace
metadata = pyexiv2.ImageMetadata('test.png')
with
metadata = pyexiv2.ImageMetadata('C:\\Users\\MYUSERPROFILENAME\\Desktop\\test.jpg')
where MYUSERPROFILENAME is your user profile. Hope this helps

errors with pyautogui on Windows 7

I am wanting to use pyautogui to automate some tasks but i am having trouble getting the package to work on Windows 7.
I am currently using anaconda and spyder (i have also tried python IDLE). I can install the pyautogui package without any errors, but when i try to run a simple command:
import pyautogui
pyautogui.displayMousePosition()
The above i got from a youtube video of Al Sweigart doing a demo of pyautogui, and from the outcome i would expect to see the x, y coordinates of the mouse pointer and the R,G,B numbers.
But when I run it I get the following messages:
runfile('C:/Users/david/.spyder-py3/temp.py', wdir='C:/Users/david/.spyder-py3')
Reloaded modules: pymsgbox, pyautogui, pyautogui._pyautogui_win, pymsgbox._native_win, pymsgbox.native, pyscreeze, pytweening
Press Ctrl-C to quit.
Traceback (most recent call last):
File "<ipython-input-5-0007268e4f6f>", line 1, in <module>
runfile('C:/Users/david/.spyder-py3/temp.py', wdir='C:/Users/david/.spyder-py3')
File "C:\Users\david\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "C:\Users\david\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/david/.spyder-py3/temp.py", line 2, in <module>
pyautogui.displayMousePosition()
File "C:\Users\david\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\pyautogui\__init__.py", line 1027, in displayMousePosition
pixelColor = pyscreeze.screenshot().getpixel((x, y))
File "C:\Users\david\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\pyscreeze\__init__.py", line 309, in _screenshot_win32
im = ImageGrab.grab()
NameError: name 'ImageGrab' is not defined
I have tried manually installing the dependenciies (pillow) in case that was the issue, but I cannot figure out how to fix the problem. I know the above message give a lot of info but I don't understand well enough to fix the issue.
Can anyone help? or tell me where i'm going wrong?

Resources