I would like to capture raw data from the audio out, using Python. In the Python docs it seems that using ossaudiodev works for this purpose. However, I am using Ubuntu 11.10, which has no /dev/dsp:
>>> import ossaudiodev
>>> ossaudiodev.open('r');
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory: '/dev/dsp'
Has anybody got a clue how to capture the sound my sound card outputs using Python?
OSS is an older and deprecated audio system for Linux. The current standard is to use ALSA, and to layer on top of ALSA with either JACK or PulseAudio. Ubuntu uses PulseAudio.
The best thing you could do is to find good Python bindings for connecting to PulseAudio. I just did a quick Google search and didn't find anything for you, and I don't have time to follow up more right now.
EDIT: I just remembered that ALSA does have an OSS compatibility mode. You might be able to install the OSS compatibility stuff, then just use the Python code you already have.
https://help.ubuntu.com/community/alsa-oss
http://www.alsa-project.org/main/index.php/Main_Page
I have got programs to work which require /dev/dsp by using
aoss <PROGRAM NAME AND ARGUMENTS HERE>
If you type aoss on Ubuntu's command line, it will tell you the package to install and that should, in turn, install the needed dependencies. If it doesn't work off the bat, you can try loading a kernel module such as sudo modprobe snd_mixer_oss.
Related
There is a bunch of pre-made code I simply have to run. However, the code requires the module NumPy, which for some reason is not installed. I am using Geany for the Python code, and when I click compile, the console states:
"Traceback (most recent call last):
File "chi2Fit.py", line 1, in <module>
import numpy as np
ImportError: No module named 'numpy'
I really tried to look it up, and I found the zipped NumPy packages on SourceForge, but I cannot install them. I am using Windows 10 (Virtual Machine is buggy, unfortunately). I usually run my Python programs by compiling them directly and don't use the commands within the console (so honestly I don't know how to open the command line. Yes, I am a beginner). What is the explanation?
Geany is just an editor, with the ability to run commands and such from menus and buttons. So you should be able to run this code 'by compiling them directly'. If that works while the 'geany compile' does not, then you need to check the 'compile' command. Is it using the right Python?
'compile' really doesn't make sense with Python code. You are just executing a script.
NumPy is a large package that does include compiled components. So installing it requires more than downloading a ZIP file. On Windows it is usually best to install one of the precompiled packages. Anaconda is popular one.
But we know nothing about this pre-made code, and whether it has included the necessary modules or not. You need to find out from the source of that code what is needed to run it.
You need to figure out how to install NumPy. It depends on what OS you are using.
There are pre-compiled packages for Windows. There is plenty of information here on SO (e.g., Installing NumPy on Windows) or you can use Google.
I'm working on a writing a Python script that will interface with and pull GPSD data into an application. This obviously involves an external library.
I have set up my configuration as follows on the Raspberry Pi I am using to deploy the code:
sudo apt-get install gpsd gpsd-clients python-gps
I have a working test sample code that creates the gps listener and pulls in data. It looks something like this:
gpsd = gps(mode=WATCH_ENABLE)
while gpsp.running:
gpsd.next()
It works great if I run it by calling the following command:
python test.py
But the code breaks due to an ImportError:
Traceback (most recent call last):
File "main.py", line 1, in <module>
from gps import *
ImportError: No module named gps
If I run it using:
python3 test.py
This makes sense to me because when I set up the project, I only included the libraries for the default Python (Python 2.7), not Python 3. But python3-gps isn't a package, and the rest of my project demands Python 3, so I don't know what to do.
Would it be possible to copy the Python 2.7 build of the gps library into Python 3 without errors? What other libraries should I look at? Is there anyway around this error?
Thanks so much!
There actually is a version make for version 3 -- see GitHub here...
https://github.com/tpoche/gps-python3
It advertises itself as a simple port to python 3....
The GPS3 project found on github is Python 2.7 to 3.4 compatible interface to the gpsd, yet doesn't import ancient cruft.
It is still alpha, but I would recommend it, at least for a poke and prod.
If you have pip3 installed use
pip3 install gps
I am trying to control an Agilent 33120A Arbitrary Waveform Generator using pyvisa under Ubuntu 13.04 (Raring Ringtail). I have installed and set up everything that is necessary to communicate with the instrument using our labs NI GPIB-USB-B adapter. The adapter firmware is loaded, and so are the kernel modules from linux-gpib.
I can successfully do some dry-runs, e.g. by running # ibtest (command-line tool), I can write *IDN? to the device, and I receive the device ID: 'HEWLETT-PACKARD,33120A,0,8.0-5.0-1.0'. I also tested other commands successfully, like setting voltage and frequency, and so on. It works.
The problem is, pyvisa always throws a VisaIOError... I have not clue how to get it to work. I run python-2.7 as root, so that (for now) I do not have to deal with any access privileges. This is the code and output:
import visa
>>> visa.vpp43.visa_library.load_library("/usr/lib/x86_64-linux-gnu/libvisa.so.0")
>>> visa.get_instruments_list()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/pyvisa/visa.py", line 254, in get_instruments_list
vpp43.find_resources(resource_manager.session, "?*::INSTR")
File "/usr/lib/python2.7/dist-packages/pyvisa/vpp43.py", line 583, in find_resources
instrument_description)
File "/usr/lib/python2.7/dist-packages/pyvisa/vpp43.py", line 398, in check_status
raise visa_exceptions.VisaIOError, status
pyvisa.visa_exceptions.VisaIOError: VI_ERROR_RSRC_NFOUND: Insufficient location information or the requested device or resource is not present in the system.
The library loads correctly. It is not even necessary, but I load the library explicitly to be safe. Obviously, pyvisa does not find any instrument. I also tried to explicitly open my instrument board=0, pad=10, sad=0 using either of these commands:
visa.instrument("GPIB::10")
visa.instrument("GPIB0::10")
visa.instrument("GPIB::10::0")
visa.instrument("GPIB0::10::0")
But the same exception as above is thrown.
Basically, everything is set up alright, but pyvisa does not see anything.
Used versions:
pyvisa-1.4
python-2.7
linux-gpib-3.2.20
libvisa-0.0.20130812-1 (https://launchpad.net/ubuntu/trusty/amd64/libvisa0/) newest build for Ubuntu 14.04 (Trusty Tahr) as this library is not in the repositories for Ubuntu 13.04)
I am hoping for some suggestions.
pyvisa is a Python wrapper around NI-VISA. As far as I know it's not possible to use pyvisa with linux-gpib. But linux-gpib comes with its own Python wrappers. Simply import Gpib and you're good to go, for example,
>>>import Gpib
>>>device = Gpib.Gpib(pad=10)
>>>device.write('*IDN?')
>>>device.read()
'HEWLETT-PACKARD,33120A,0,8.0-5.0-1.0'
I guess you're writing some kind of measurement script. Have a look at slave it might be usefull for you (disclaimer: I'm the author of slave). It tries to simplify the device communication. Also it comes with its own wrappers for linux-gpib.
I'm trying to write a program to record information from my computers microphone an save it to a file. PyAudio seems like one of the better packages for doing this, and they even have a binary for Windows 7 (Python 2.7). I downloaded the executable file and ran it to set up PyAudio, but when I try to import PyAudio into a python script now I get an error:
Please build and install the PortAudio Python bindings first.
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pyaudio
File "C:\Python27\lib\site-packages\pyaudio.py", line 103, in <module>
sys.exit(-1)
SystemExit: -1
If I look at pyaudio.py, the code that it's failing on is:
# attempt to import PortAudio
try:
import _portaudio as pa
except ImportError:
print "Please build and install the PortAudio Python " +\
"bindings first."
sys.exit(-1)
Also, in case it's relevant, if I go to Python27\Lib\site-packages (where pyaudio.py is) there is a file called portaudio_x64.dll.
The documentation on their site only seems to have instructions for if you want to install PyAudio by building from source code. Additionally, it says that PortAudio v19 is included in the binary, so I assumed it would just work after running the setup executable.
I have no idea what's going wrong and I really need this running soon. Any ideas on what's going wrong? Or if anyone has recommendations for similar packages that work better specifically with Windows 7 (64-bit) and Python 2.7 (Enthought distribution), as well as cross-platform, I'd love to hear them.
Copying the answer from the comments in order to remove this question from the "Unanswered" filter:
Try the binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio
~ answer per cgohlke
I have just installed OpenCV on my Windows 7 machine. As a result, I get a new directory:
C:\OpenCV2.2\Python2.7\Lib\site-packages
In this directory, I have two files: cv.lib and cv.pyd.
Then I try to use the opencv from Python. I do the following:
import sys
sys.path.append('C:\OpenCV2.2\Python2.7\Lib\site-packages')
import cv
As a result I get the following error message:
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.
What am I doing wrong?
ADDED
As it was recommended here, I have copied content of C:\OpenCV2.0\Python2.6\Lib\site-packages to the C:\Python26\Lib\site-packages. It did not help.
ADDED 2
My environment variables have the following values:
Path=C:\Program Files\MiKTex\miktex\bin;C:\OpenCV2.2\bin;C:\Python26;
PYTHONPATH=C:\OpenCV2.2\Python2.7\Lib\site-packages
Do I need to change something? Do I need to add something?
ADDED 3
I think my question is general: How to use a library? Probably I need to find a *.ddl file somewhere? Then I need to use the name of the directory containing this file as a value to some environment variables? Or maybe I need to use sys.addpath? I also need to know how the way to call the library is related to the name of the file that contains the library.
ADDED 4
It is interesting that when I type import cv, I get:
ImportError: DLL load failed: The specified module could not be found.
But when I type import opencv I get:
ImportError: No module named opencv
ADDED 5
It has been suggested that I usthe e inconsistent version of python. In more details, OpenCV tries to use Python2.7 and I had Python2.6. So, I have installed Python 2.7. It makes difference. Now I do not have the old error message, but I have a new one:
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import
ADDED 6
I have managed to resolve the problem by installing numpy. It took some time because I did not realized that there are different numpy installer corresponding to different versions of Python. Some details can be found in my answer to my own question (see bellow).
The problem was resolved. The following steps has been done:
A new version of python (version 2.7) has been installed.
After that I still was unable to run OpenCV because I had some problems with the numpy library.
I tired to install numpy but the installer did not see my new version of the Python.
I deleted the old version of Python as well as links to the old version in the Path system vatriable.
After that numpy installer was not able to finish the installation.
I have realized that I need to run another numpy installer that is associated with the Python 2.7. It can be found here.
Finally everything worked. I was able to "import cv".
I suspect you have the same problem I've run into. If you have a 64-bit version of Python, it cannot load 32-bit DLLs. OpenCV currently only ships 32-bit binaries. If you want 64-bit .pyd and .dll files, you have to compile them yourself. There are some instructions on the OpenCV Wiki, but it's not for the faint of heart. Expect to have a substantial time investment.
The easiest solution is to:
Uninstall 64-bit Python
Install a 32-bit distribution.
The PythonXY distribution includes pyopencv -- a good set of OpenCV hooks. The only limitation is that it's 32-bit, so don't make plans to process gigapixel astronomy data with it! ;)
If you must have the 64-bit version, follow these instructions to get it OpenCV to compile with Visual Studio 2010. There's a discussion on stackoverflow that describes building 64-bit apps with VC Express.
EDIT: OpenCV now ships with 64-bit Python binaries. The .dll files need to go somewhere in your path (I put them in the scripts folder), and the .pyd files go in your site-packages directory.
I had trouble interfacing OpenCV with Python, and I was looking all over the place for help. Here's what worked for me. I basically followed this post: http://opencvpython.blogspot.com/2012/05/install-opencv-in-windows-for-python.html. After downloading and extracting OpenCV 2.4.6, you basically get a folder called "opencv" with a bunch of stuff in it. Navigate to build->python->2.7. Inside, there is only one file called "cv2.pyd". I copied this file and pasted it in "python-2.7.5\Lib\site-packages". I'm actually using the Spyder IDE, and it works fine. In the python interpreter, typing in "import cv" worked for me.
Maybe you should edit your environment variable
right click on the "My Computer" or something like this, click on properties.
In the properties window click on the Advanced tab.
Then, the environment variables button.
Change the path.