I installed CircuitPython on my Raspberry Pi Zero W and tried to import usb_hid in Python and it threw the error: ModuleNotFoundError: No module named 'usb_hid'. I've spend all day trying to solve this issue to no avail.
I'm running the default Raspberry Pi OS and I used this tutorial to install the CircuitPython libraries.
My end goal is to use my Raspberry Pi as a mouse that controls another device. I modified the code from this tutorial to come up with this code:
import time
import usb_hid
from adafruit_hid.mouse import Mouse
mouse = Mouse(usb_hid.devices)
time.sleep(5)
while True:
mouse.move(x=100)
time.sleep(0.5)
mouse.move(x=-100)
time.sleep(0.5)
I'm very new to Raspberry Pi's / Python, so maybe I'm just missing something obvious.
I built a code to generate and play random musical notes. It is working great within python, but I would like to make it into an .exe stand alone program, so people without python can use it. I show an image below of the output. It creates a matplotlib figure with a 'TkAgg' backend. There are 5 buttons and an user entry box that all work.
I used cx_freeze to try to package it, and I worked through all of the errors. I also got some of the examples to work. I can see the the build folder is getting the 4 Images and many .wav files I need to draw the musical staff and play the notes. One error showed that the .exe tried to run my code, because it couldn't find the .wav files). I changed how I specified where they were for the .exe. But now when I run the .exe nothing happens.
Unfortunately my code is a monstrosity. It's messy, and somewhat long (750 lines if you count white space). The .py file I am trying to write to the .exe is Interval_Trainer_v1_1.py. It can be found here.
Because it works in python, but not in the .exe, I thought it might have to do with my ignorance of how to use classes in conjunction with plotting well. Basically I call the class, and then initialize a bunch of things so I can refer to them later. That allows me to delete notes I've plotted before, old answers, etc.
How can I practice building up 'TkAgg' backended figures that will execute properly after cf_freeze? I feel like I need to start with some basic ideas and build up to my application, which is fairly complex.
One note, I do use pygame for the sounds.
Here is my setup file:
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY']=r'C:\Users\Bart\Anaconda3\tcl\tcl8.6'
os.environ['TK_LIBRARY']=r'C:\Users\Bart\Anaconda3\tcl\tk8.6'
import sys
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
additional_mods = ['numpy.core._methods', 'numpy.lib.format',"matplotlib.backends.backend_tkagg", 'matplotlib.pyplot', 'matplotlib.image', 'matplotlib.widgets']
setup(
name = "Interval Trainer",
version = "1.0.0",
author = "Bart",
author_email = "bcubrich#gmail.com",
options = {"build_exe": {'includes': additional_mods,"packages":["pygame","tkinter",'random'],
"include_files": [
'Images/F cleff 8vb.png', 'Images/F cleff.png',
'Images/G cleff 8vb.png', 'Images/G cleff.png',
'Pitches/A#1.wav', 'Pitches/A#2.wav', 'Pitches/A#3.wav',
'Pitches/A#4.wav', 'Pitches/A#5.wav', 'Pitches/A1.wav',
'Pitches/A2.wav', 'Pitches/A3.wav', 'Pitches/A4.wav',
'Pitches/A5.wav', 'Pitches/Ab1.wav', 'Pitches/Ab2.wav',
'Pitches/Ab3.wav', 'Pitches/Ab4.wav', 'Pitches/B#2.wav',
'Pitches/B#3.wav', 'Pitches/B#4.wav', 'Pitches/B1.wav',
'Pitches/B2.wav', 'Pitches/B3.wav', 'Pitches/B4.wav',
'Pitches/B5.wav', 'Pitches/Bb1.wav', 'Pitches/Bb2.wav',
'Pitches/Bb3.wav', 'Pitches/Bb4.wav', 'Pitches/C#2.wav',
'Pitches/C#3.wav', 'Pitches/C#4.wav', 'Pitches/C#5.wav',
'Pitches/C2.wav', 'Pitches/C3.wav', 'Pitches/C4.wav',
'Pitches/C5.wav', 'Pitches/C6.wav', 'Pitches/D#2.wav',
'Pitches/D#3.wav', 'Pitches/D#4.wav', 'Pitches/D#5.wav',
'Pitches/D2.wav', 'Pitches/D3.wav', 'Pitches/D4.wav',
'Pitches/D5.wav', 'Pitches/Db1.wav', 'Pitches/Db2.wav',
'Pitches/Db3.wav', 'Pitches/Db4.wav', 'Pitches/E#2.wav',
'Pitches/E#3.wav', 'Pitches/E#4.wav', 'Pitches/E1.wav',
'Pitches/E2.wav', 'Pitches/E3.wav', 'Pitches/E4.wav',
'Pitches/E5.wav', 'Pitches/Eb2.wav', 'Pitches/Eb3.wav',
'Pitches/Eb4.wav', 'Pitches/F#1.wav', 'Pitches/F#2.wav',
'Pitches/F#3.wav', 'Pitches/F#4.wav', 'Pitches/F#5.wav',
'Pitches/F1.wav', 'Pitches/F2.wav', 'Pitches/F3.wav',
'Pitches/F4.wav', 'Pitches/F5.wav', 'Pitches/G#1.wav',
'Pitches/G#2.wav', 'Pitches/G#3.wav', 'Pitches/G#4.wav',
'Pitches/G#5.wav', 'Pitches/G1.wav', 'Pitches/G2.wav',
'Pitches/G3.wav', 'Pitches/G4.wav', 'Pitches/G5.wav',
'Pitches/Gb1.wav', 'Pitches/Gb2.wav', 'Pitches/Gb3.wav',
'Pitches/Gb4.wav']}},
executables = [Executable("Interval_trainer_v1_1.py", base=base)],
)
Output Image
Any help is appreciate.
See the matplotlib user interfaces examples embedding_in_tk and embedding_in_tk2 to practice building up TkAgg backended figures.
I have a npy file, (largeFIle.npy) saved in the same "colab notebooks" folder on my google drive that I have my google colab notebook saved in. I'm trying to load the data into my notebook with the code below but I'm getting the error below. This code works fine when I run it locally on my laptop with the notebook in the same folder as the file. Is there something different I need to do when loading data with notebooks in google colab? I'm very new to colab.
code:
dataset_name = 'largeFIle.npy'
dataset = np.load(dataset_name, encoding='bytes')
Error:
FileNotFoundError Traceback (most recent call last)
<ipython-input-6-db02a0bfcf1d> in <module>()
----> 1 dataset = np.load(dataset_name, encoding='bytes')
/usr/local/lib/python3.6/dist-packages/numpy/lib/npyio.py in load(file, mmap_mode, allow_pickle, fix_imports, encoding)
370 own_fid = False
371 if isinstance(file, basestring):
--> 372 fid = open(file, "rb")
373 own_fid = True
374 elif is_pathlib_path(file):
FileNotFoundError: [Errno 2] No such file or directory: 'largeFIle.npy'
When you launch a new notebook on colab, it connects you with a remote machine for 12 hours and all you have there is the notebook and preloaded functions. To access your folders on drive, you need to connect the remote instance to your drive and authenticate it.
This thing bugged me for sometime when I was beginning too, so I'm creating a gist and I'll update it as I learn more. For your case, check out section 2 (Connecting with Drive). You don't have to edit or understand anything, just copy the cell and run it. It will run a bunch of functions and then give you an authentication link. You need to go to that link and sign-in with Google, you'll get an access token there. Put it back in the input box and press Enter. If it doesn't work or if there's some error, run the cell again.
In the next part I mount my drive to the folder '/drive'. So now, everything that's on your drive exists in this folder, including your notebook. Next, you can change your working directory. For me, I'm keeping all my notebooks in '/Colab' folder, edit it accordingly.
Hope it helps you. Feel free to suggest me edits to the gist as you learn more. :)
Have you set up your google drive with google colab with this method. After mounting Google drive use below command for your problem (Assuming you have stored largeFIle.npy in Colab Notebook folder.)
dataset = np.load('drive/Colab Notebooks/largeFIle.npy, encoding='bytes')
I am working with project, connected with ROS Kinetic. I wrote my nodes, using Python3 and tried to transfer some information with ros-service from 1 node to another. This information represents a huge object that couldn't be easilly formatted to normal ROS types, so I used pickle.dumps(object, 0).decode() and send it like a string.In the server side I couldn't use pickle and met an exception about: No module named search.
The code of the server side:
#!/usr/bin/env python3
from visualization.srv import *
import rospy
import pickle
megafoo = []
def handle_nodes(req):
global megafoo
print(type(req.nodes))
megafoo.extend(pickle.loads(req.nodes.encode()))
print(len(megafoo))
a=1
print("A request type: {0}".format(type(req)))
return ListNodesResponse(a)
def nodes_creater_server():
rospy.init_node('nodes_server')
s = rospy.Service('draw_some_nodes', ListNodes, handle_nodes)
print('ready to draw nodes')
rospy.spin()
if __name__ == "__main__":
nodes_creater_server()
I tried to make this without calling pickle and problem was resolved so I think that I can't call pickle from server somehow
Quite late to the party, but "No module named search" sounds like your pickle string contains a custom class "search" that isn't available at the receiving side. Would this be correct?
To verify you can try to transfer some simple native Python value like (123, "abc") using pickle in ROS (which should work).
Another option is to write two separate programs, one that writes the pickle to disk, and another one that reads the pickle from that file. Then you can experiment with loading, and eg decide which modules you need to import.
I am new to Python (version 2.7). I have been using for a long time some excel workbooks that uses DDE function to capture "real-time market data" - that is served by one Market Data Provider ("Matriks", if matters).
In a bit to simplify my overall process flow, I decided to bypass this excel workbook thing for data capture, and instead, I decided to use python codes to perform the same task.
The problem is that,
1) I get "error: The server could not be created" when I run the code (provided below) using Pythonwin.
2) and I get "ImportError: This must be an MFC application - try 'import win32ui' first" when I run this very simple code using IDLE.
(and of course, I downloaded and run win32ui.)
Any help is appreciated.
# DDE code
# excel equivalent of this code is: =MTX|DATA!EURUSD.SON
import win32ui
import dde
s=dde.CreateServer()
s.Create("MTX")
c=dde.CreateConversation(s)
c.ConnectTo("DATA","SON")
c.Connected()
c.Request("EURUSD")
# returns
# Traceback (most recent call last):
# File "C:\IQTrader\_script\_obj\DDEClient.py", line 12, in <module>
# import dde
# ImportError: This must be an MFC application - try 'import win32ui' first
The issue is resolved. The very basic reason for the error is the pywin module.
For those facing with the same problem:
1.Delete pythonwin and pywin32_system32 folderes entirely (presumably under C:\Python27\Lib\site-packages)
2.Check your pywin32 version; it should be 214 (not 218) for those using v2.7
3.Download pywin32-214.win32-py2.7 from appropriate resources (one is this: http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/ )
4.Everything should be fine.
I had a similar problem. I had to:
uninstall Python 2.7 64-bit
install Python 2.7 32-bit
use the pywin32 version 214
Run cmd.exe as administrator so that the c.ConnectTo() connects successfully
However, I am still having the weird problem that I must have Excel open at the same time with a cell holding the value =MTX|DATA!EURUSD.SON for the python script to return a valid quote. Otherwise, I just get "N/A" as the return value.
#Aykut did you run into this issue as well?