Now it's been like 3 days and I still don't manage. Maybe someone can help.
I want to send a control command to a midi device, via python, on a mac. Everywhere I see, the happy answer is to use pygame, but truth is that the pygame version on the mac lacks that functionality.
When I try run this two lines :
from pygame import midi
midi.init()
I get the following error:
Traceback (most recent call last):
File "midi_send.py", line 9, in <module>
midi.init()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site- packages/pygame/midi.py", line 71, in init
import pygame.pypm
ImportError: No module named pypm
I've looked and looked and all I find is dead ends.
Has anyone actually tried using pygame to write to a midiport, on a mac? is there an alternative that doesn't include getting stuck in some gcc compile error something replace line N of somemidi.o file somewhere in /etc/whatever/whatever?
Sorry for being frustrated...
You could try using the rtmidi-python library (or older and slightly different pyrtmidi) - both based on rtmidi which provides for straightforward sending of MIDI Control and Notes:
import rtmidi_python as rtmidi
midi_out = rtmidi.MidiOut()
midi_out.open_port(0)
midi_out.send_message([0x90, 48, 100]) # Note on
midi_out.send_message([0x80, 48, 100]) # Note off
Related
First time Python user, so apologies if I am misunderstanding something basic like how libraries are accessed (I am an R user).
Using a colleague's code (which works on his end) and trying to load the the following:
from reportlab.lib import colors
results in the following error:
Traceback (most recent call last):
File "Box\Py\Python3\Py3_StaticMain.py", line 32, in <module>
from reportlab.lib import colors
File "C:\Program Files\Python310\lib\site-packages\reportlab\lib\colors.py", line 44, in <module>
from reportlab.lib.utils import asNative, isStr, rl_safe_eval
File "C:\Program Files\Python310\lib\site-packages\reportlab\lib\utils.py", line 389, in <module>
haveImages = Image is not None
NameError: name 'Image' is not defined
Pillow and reportlab are installed. After searching online I found similar error reports and the solution was to add this line prior to the previous library call (again, my colleague does need this on his end):
from PIL import Image
However, this did not fix the problem, the error persists. Also of note both these lines get greyed out by PyCharm which apparently means that these libraries are already loaded so these lines are unnecessary? It is counter intuitive that an unnecessary command would cause an error. The other libraries imported are os.path, sys, datetime, and tkinter. Also, even if I just put these two lines in a new py file I get the same behavior: greyed out and error.
Not a very satisfying answer but after uninstalling and reinstalling both Python and the IDE everything worked.
The form builder wxFormBuilder imports wx and wx.xrc. However the second of these causes an error as follows:
Traceback (most recent call last):
File "/home/peter/python/wxpython/wxFormBuilder/Demo/demo.py", line 4, in
import demogui
File "/home/peter/python/wxpython/wxFormBuilder/Demo/demogui.py", line 11, in
import wx.xrc
File "/usr/local/lib/python3.6/dist-packages/wx/xrc.py", line 10, in
from ._xrc import *
ImportError: libwx_gtk3u_html-3.0.so.0: cannot open shared object file: No such file or directory
The obvious answer would be that the file was missing, but it isn't:
peter#peter-HP-Pavilion-15-Notebook-PC:~$ locate libwx_gtk3u_html-3.0.so.0
/usr/local/lib/python3.6/dist-packages/wx/libwx_gtk3u_html-3.0.so.0
So, to my inexperienced eyes it seems to be present and in the right place. Can anyone make any suggestions on this?
I'm using wxPython for Python 3, by the way.
Many thanks
This issue was fixed in wxPython release 4.0.1, see the discussion at https://groups.google.com/forum/#!topic/wxpython-users/UBjdeTgOmD4.
The build scripts were setting LD_RUN_PATH only for the wxPython libraries, not for the embedded wxWidgets build. I can confirm that the fixes mentioned in https://github.com/wxWidgets/Phoenix/issues/723 solve the issue.
I've been working on a basic Django project and I deployed it to AWS Elastic Beanstalk. I'm not sure if that's causing this, but I'm just telling you this so that you know what I might have been done with my project. Then, my python project interpreter got kinda messy and when I try to run the application it started to give me some errors about missing packages. After that, I checked my project interpreter, and it was like this:
Then, I tried to install the required packages using PyCharm, however, it kept giving me the error below. I also tried to build some of those packages manually, like Django, on my own terminal but the error was same. Further, I was able to install packages on other python versions on my mac, which sorta tells I might have messed my default python interpreter somehow.
40:357: execution error: Traceback (most recent call last): File
"/var/folders/f1/k7c234sx5fn9j84yt130_znr0000gn/T/tmp2zDEZTpycharm-management/pip-9.0.1/setup.py",
line 6, in
from setuptools import setup, find_packages File "/Users/bkaankuguoglu/Library/Python/2.7/lib/python/site-packages/setuptools/init.py",
line 12, in
import setuptools.version File "/Users/bkaankuguoglu/Library/Python/2.7/lib/python/site-packages/setuptools/version.py",
line 1, in
import pkg_resources File "/Users/bkaankuguoglu/Library/Python/2.7/lib/python/site-packages/pkg_resources/init.py",
line 72, in
import packaging.requirements File "/Users/bkaankuguoglu/Library/Python/2.7/lib/python/site-packages/packaging/requirements.py",
line 59, in
MARKER_EXPR = originalTextFor(MARKER_EXPR())("marker") TypeError: call() takes exactly 2 arguments (1 given) (1)
I'd really appreciate any help here and please ask me if any extra detail is needed to answer this question before downvoting.
pip install setuptools==33.1.1
I am trying to import the spherical harmonic toolbox (SHTOOLS) in python. I have the files downloaded and unzipped and am using RedHat.
I added the package's path to my python system path and when I go to import the package, I get this error:
>>import pyshtools
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pyshtools/__init__.py", line 49, in <module>
load_documentation()
File "pyshtools/__init__.py", line 27, in load_documentation
from . import _SHTOOLS
ImportError: cannot import name _SHTOOLS
I can not seem to figure out what the issue is. I checked that the path to this folder was actually added to the system path and it was.
Is this an issue on my end? Or is it possible that I have something downloaded incorrectly? If so, how would I go about fixing this issue?
The SHTOOLS package needs to be built with make first to compile the Fortran libraries. The wiki on Github gives directions on which libraries are required - libblas-dev, liblapack-dev, g++, gfortran, and libfftw3-dev (these are the Ubuntu packages, they may have slightly different names on Redhat). Once these are installed, you need to run make, then sudo make all to install the Fortran and Python components. The Makefile has a lot of good comments in it, I'd recommend reading through it before running make.
I have Python 2.6 running on Fedora 13. I installed PIL 1.1.7, and I get the successful installed message in the Python prompt. I am able to import PIL.PhotoImage,but when I try to run the following, I get an error.
mgobj = PhotoImage(file=imgpath)
Stacktrace:
Traceback (most recent call last):
File "viewer-tk.py", line 25, in <module>
imgobj = PhotoImage(file=imgpath) # now JPEGs work!
File "/home/Toshiba/vinpython/venv/lib/python2.6/site-packages/PIL/ImageTk.py", line 116, in __init__
self.paste(image)
File "/home/Toshiba/vinpython/venv/lib/python2.6/site-packages/PIL/ImageTk.py", line 181, in paste
import _imagingtk
ImportError: No module named _imagingtk
In the module ImageTk.py , I see _imagingtk being imported,but i am not sure how do it get that module.Help is greatly appreciated!!!
You need to install Tkinter python module as stated at this trac. But since it's an integral part of python distributions. Since you are using fedora take a look at this page where you can install Tkinter when it doesn't come along, even being for Fedora 3 I think it might help.