Task: Call a function from Matlab 2013b using Python 3.x on Windows 7 (all x64).
Question: Is there a Python package that allows me to do that?
I already tried:
mlabwrap
python-matlab-bridge
pymatlab
but none of these work with the configuration given above.
Any information about a working configuration using Python 3.x is appreciated.
If you need more detailed information, please let me know.
Update: I am currently trying to get this working using Matlab2011b and Pyhton 2.7 as these seem to be the most used Versions. For now i am stuck at the following:
python-matlab-bridge
I can import the module without problems but as soon as is start a Session a Matlab Command Window pops up and nothing else happens. The Python Window shows:
Starting MATLAB on ZMQ socket tcp://127.0.0.1:55555
Send 'exit' command to kill the server
............................................................Matlab session timed
out after 60 seconds
MATLAB failed to start
Press any key to continue . . .
This happens every single time and no error is given.
mlabwrap
I tried to install mlabwrap using this guide. On typing 'python setup.py install' a Matlab Command Window pops up and again nothing happens. If i close the Command Window the Python output shows:
WINDOWS SPECIFIC ISSUE? Unable to remove c:\users\martin\appdata\local\temp\tmp1
y2kdk; please delete it manually
[Error 32] Der Prozess kann nicht auf die Datei zugreifen, da sie von einem ande
ren Prozess verwendet wird: 'c:\\users\\martin\\appdata\\local\\temp\\tmp1y2kdk'
INSTALL ABORT: 'matlab -nodesktop -nosplash -wait -r "fid = fopen(\'c:\\users\\m
artin\\appdata\\local\\temp\\tmp1y2kdk\', \'wt\');fprintf(fid, \'%s%c%s%c%s%c\',
version, 10, matlabroot, 10, computer, 10);fclose(fid); quit"' RETURNED ERROR C
ODE -805306369
PLEASE MAKE SURE matlab IS IN YOUR PATH!
My %Path% looks like this (only the important parts ;):
D:\MATLAB\R2011b\bin;C:\Program Files\ZeroMQ 4.0.4\lib;D:\Python27;D:\Python27\scripts;D:\MATLAB\R2011b\runtime\win64;D:\MATLAB\R2011b\extern\lib\win64\microsoft;D:\MATLAB\R2011b\bin\win64
Any help to get any connection between Matlab and Python on Windows is appreciated! I really can´t see why none of this is working...
Update2: I can install mlabwrap now but i can´t start it.
When i try to import mlabwrap a Matlab Command Window opens up and closes after a minute.
The Python output is:
>>> import mlabwrap
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Python27\lib\site-packages\mlabwrap.py", line 645, in <module>
mlab = MlabWrap()
File "D:\Python27\lib\site-packages\mlabwrap.py", line 405, in __init__
self._session = mlabraw.open(os.getenv("MLABRAW_CMD_STR", ""))
mlabraw.error: Unable to start MATLAB(TM) engine
I double checked that the engdemo from Matlab is working.
I now got it working using python-matlab-bridge.
I converted it by hand to Python3 and the changes have been merged into the official repo so it should work out of the box now.
If you get an error that 'messenger init' could not be found, make sure that Lib\site-packages\pymatbridge\matlab is in your PATH.
If you have any questions or additional information fell free to comment this answer and i will add it to help users get started with python-matlab-bridge.
Related
I am trying to make a python script that runs the command line for turning a file into a .zip using python3 on my Mac.
However, whenever I run: os.system('zip -er file.zip /Users/mymac/Desktop/file.py') in python3, I get the error:
zip I/O error: Read-only file system
zip error: Could not create output file (file.zip)
I have tried disabling SIP on my Mac, as well as trying to use subprocess but I get the same message every time. I am really unsure why this happens... Is anyone able to help out?
i will suggest 3 steps !
first run :
fsck -n -f
then reboot !
make sure to run the python file as root
import os
try:
os.system('zip mag.zip mag.ppk')
print ('success')
except:
print ('problem')
screnshoot for my test
I have a python environment called nem that I created using Conda, however in VS Code when I right click and select 'Run Python File in Terminal' I get the below error. BUT I know this package is not an issue as I can open up a new windows terminal outside of VS Code and run the commands below and everything works great.
activate nem
python index.py
I have also had issues where the output in the terminal is being suppressed even though the application is running. I'm not sure what the root cause of this is, and whether its directly related to Conda. However does anyone know of a solution to this? Or how to configure VS Code's 'Run Python File in Terminal' to just use the commands above.
Windows PowerShell Copyright (C) Microsoft Corporation. All rights
reserved.
PS C:\Users\nikhil\Git Repos\natatorium-energy-model> conda
activate nem PS C:\Users\nikhil\Git
Repos\natatorium-energy-model> &
C:/Users/nikhil/AppData/Local/Continuum/anaconda3/envs/nem/python.exe
"c:/Users/nikhil/Git Repos/natatorium-energy-model/index.py"
Traceback (most recent call last): File "c:/Users/nikhil/Git
Repos/natatorium-energy-model/index.py", line 8, in
from apps import analyse File "c:\Users\nikhil\Git Repos\natatorium-energy-model\apps\analyse.py", line 17, in
import pyarrow.parquet as pq File "C:\Users\nikhil\AppData\Local\Continuum\anaconda3\envs\nem\lib\site-packages\pyarrow__init__.py",
line 49, in
from pyarrow.lib import cpu_count, set_cpu_count ImportError: DLL load failed: The specified module could not be found. PS
C:\Users\nikhil\Git Repos\natatorium-energy-model>
In the bottom left corner, change the python interpreter to the one in your environment.
I am trying to run a script using an interface created with tkinter. I have a button that executes a script which code is:
subprocess.call("python3 " + PATH_TO_SCRIPTS + "main.py 1 &", shell=True)
However, when this button is pressed I am getting the following error.
Traceback (most recent call last):
File "/home/m//PycharmProjects/ROSAutonomousFlight/catkin_ws/src/ardrone_numeric_method_controller/scripts/main.py", line 17, in <module>
from controller import *
File "/home/m/PycharmProjects/ROSAutonomousFlight/catkin_ws/src/ardrone_numeric_method_controller/scripts/controller.py", line 5, in <module>
import rospy
It says that the module rospy does not exist, but when I run
import rospy
using python or python3 it is imported successfully. What can I do to solve this issue? I am using Ubuntu.
The comments to your question are mostly about Python, but I guess it is more of a ROS issue.
You don't have to set-up your PYTHONPATH manually to find rospy but you have to source the setup.bash of your catkin workspace (otherwise none of the ROS tools is found).
Usually this is done by adding something like
source ~/catkin_ws/devel/setup.bash
to .bashrc. This works fine for everything that is run in a terminal.
I don't know how you start your script but as it provides a graphical interface you probably just run it by double-clicking it in the file browser? If you indeed do so, the script is not run in a terminal and therefore can't find the ROS modules. Run the script from a terminal (in which the setup.bash has been sourced) and it should work.
I found a code which i need. It is from this link : How to install a package using the python-apt API
#!/usr/bin/env python
# aptinstall.py
import apt
import sys
pkg_name = "libjs-yui-doc"
cache = apt.cache.Cache()
cache.update() # error is in this line
pkg = cache[pkg_name]
if pkg.is_installed:
print "{pkg_name} already installed".format(pkg_name=pkg_name)
else:
pkg.mark_install()
try:
cache.commit()
except Exception, arg:
print >> sys.stderr, "Sorry, package installation failed [{err}]".format(err=str(arg))
However i can't make it work. I searched about the problem on the web. It is said that there should be no package manager,apt,pip etc active in order to work with this code. However, no package manager,apt,pip etc. is open in my computer. I thought that when computer starts, some package manager can be active. So i typed
ps -aux
in terminal and look at the active processes, but i didn't see any active process related to package manager(i'm not %100 sure about this, because any process i don't know can be related to package manager.But how could i know it?) To sum up,i started the computer and opened only terminal. Then i typed python aptinstall.py and hit enter. I take the following error :
Traceback (most recent call last):
File "aptinstall.py", line 7, in <module>
cache.update()
File "/usr/lib/python2.7/dist-packages/apt/cache.py", line 397, in update
raise LockFailedException("Failed to lock %s" % lockfile)
apt.cache.LockFailedException: Failed to lock /var/lib/apt/lists/lock
I delete the lock by giving the command in terminal :
sudo rm /var/lib/dpkg/lock
It didn't work too.
How can i solve this problem? Any idea will be appreciated.
Please try looking for update-manager in ps. It runs automatically on a periodic basis, so it may be locking the apt db.
There are three different reasons which cause this error.
1 - As i mentioned earlier, if any package manager is runnning(for example;pip,apt-get,synaptic,etc), it gives the error.
2 - If you are using your ubuntu in a virtual machine, this causes the same error.
3 - If you are running your program without root privileges, this causes the same error. For example ,if you are running your program with "python aptinstall.py" you get the error, running the program with "sudo python aptinstall.py" is the correct one.
I'm working on a class project (don't worry, this question is not homework) and recently moved from department machines to my own machine.
The project is to build a simple operating system. To make the task easier, we are provided with the ability to "attach" gdb to QEMU in which our program runs. Running this program without attaching gdb on my computer works fine, however it is when I start trying to use gdb that it does not run.
The main thing to note (I think) is that it runs fine on the department computers (gdb 7.4.1-debian) but not on mine (7.6.1-ubuntu).
The error I am getting pertaining to python is that gdb extensions are written in python but they do not seem to be found. I am also getting syntax error. A run of the program looks like this:
/usr/bin/qemu-system-i386
GNU gdb (GDB) 7.6.1-ubuntu
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/alfonso/course/cs167/weenix/kernel/weenix.dbg...done.
After which it hangs for a bit, then gives me this error:
inittmp.gdb:1: Error in sourced command file:
localhost:1234: Connection timed out.
Traceback (most recent call last):
File "/home/alfonso/course/cs167/weenix/kernel/mm/memcheck.py", line 5, in <module>
import weenix
ImportError: No module named 'weenix'
File "/home/alfonso/course/cs167/weenix/kernel/mm/page.py", line 15
print "pagesize: {0}".format(weenix.kmem.pagesize())
^
SyntaxError: invalid syntax
File "/home/alfonso/course/cs167/weenix/kernel/mm/slab.py", line 40
print "{1:<{0}} {3:>{2}} {5:>{4}} {7:>{6}}".format(
^
SyntaxError: invalid syntax
File "/home/alfonso/course/cs167/weenix/kernel/proc/proc.py", line 17
print weenix.proc.str_proc_tree()
^
SyntaxError: invalid syntax
Traceback (most recent call last):
File "/home/alfonso/course/cs167/weenix/kernel/util/debug.py", line 3, in <module>
import weenix
ImportError: No module named 'weenix'
Traceback (most recent call last):
File "/home/alfonso/course/cs167/weenix/kernel/util/list.py", line 3, in <module>
import weenix
ImportError: No module named 'weenix'
Breakpoint 1 at 0xc0008f04: file util/debug.c, line 190.
Breakpoint 2 at 0xc0007016: file main/kmain.c, line 298.
Breakpoint 3 at 0xc0006cf3: file main/kmain.c, line 129.
init.gdb:6: Error in sourced command file:
The program is not being run.
Of course, the import errors and invalid syntaxes made me initially think about my PYTHONPATH and/or package settings, but that is something that works fine (tested it). The only thing I can think of is that I have some configuration problems that I am overlooking.
If you would like me to, I can post the bash script, .gdb files and the rest, but since this works fine on department computers, I doubt this is the problem.
Python versions: (department: "2.7.3", me: "2.7.5+")
EDIT:
After some searching, I have realized that the newest Linux Mint(petra) uses gdb that interprets python as python3. I am currently looking for a way to configure gdb, but as I have never done it before, I would appreciate if someone could direct me in doing so.
You use Python 3 for this debug mode.
$ python3 test33.py
File "test33.py", line 1
print "hello".format()
^
SyntaxError: invalid syntax
Make sure you use Python 2 as you say.
I'm doing this homework, too. (I guess weenix is too commonly used for OS courses.)
Regarding "import weenix" problem, it's because weenix's python script isn't in gdb's data directory. When using gdb with python, this dir will be added to python's PATH automatically. Therefore, just put "weenix/python/weenix" under your data directory/python. As for me, it's /usr/shared/gdb/.
Having fun with weenix!