I'm working on a project that involves experimenting with Arduino Mega and I'm learning about it from this book https://books.google.co.uk/books/about/Python_Programming_for_Arduino.html?id=O0PfBgAAQBAJ&printsec=frontcover&source=kp_read_button&redir_esc=y#v=onepage&q&f=false
I'm in a stage where I need to import pyfirmata library but for whatever reason it keeps throwing an import error.
I installed the library using pip3 and when that didn't help I built it from source therefore I'm quite confident that I've got it in my system. I even got a file path where it is installed. Within my Python site-packages directory.
The book is favouring Python 2.7 but I figured I can make this work in Python 3 as well. I tried import pyfirmata, from pyfirmata import Arduino and in both cases I get import error.
It shouldn't be that hard to get this to work. What should I try ?
#!/usr/bin/python
# Import required libraries
import pyfirmata
from time import sleep
I also tried replacing the first line with the exact file path of the directory but no effect.
you did everything needed with python but you also need to open Arduino IDE and press files, examples, Firmata, StandardFirmata then transfer the code to your board. Your board will now easily communicate with Python through the module Pyfirmata.
Related
Model works pretty fine on my pc using VS Code. Once I create an exe with pyinstaller and try to run the .exe nothing works. A small window appears for 1 sec and nothing else. I also tried some tk msg box and nothing happens.
Here are the imports of my main :
import csv
import os
import openpyxl
import sft_gen
from ortools.sat.python import cp_model
The imports of my 2nd file (sft_gen):
import csv
from tkinter import Tk
from tkinter.filedialog import askopenfilename
When I run the .exe in the cmd prompt I get :
Error msg in prompt
Edit.1. : After testing, found out that :
from ortools.sat.python import cp_model
is the reason why the .exe fails to execute.
What could be the solution to this? I really want to deploy my CP model to other users... In the meantime I'll try other .exe apps like py2exe and mention here if I have any success with it.
This was asked before.
From what I understand, pyinstaller does not support python module using native libraries.
My company has a large Git repository that is actively being developed (call it really-big-repo). I would like to use the reticulate package to call some of those python functions in R. Apologies in advance as I still try to get my arms around both python and git.
Single python files can be called using reticulate::source_python("flights.py") (see here). However, the python script I would like to imports modules that are from other parts of the repository. For example, the file that I would like to source great_python_functions.py looks like this:
import datetime
import json
import re
import requests
from bs4 import BeautifulSoup
from SomeRepoDirectory import utils
from SomeRepoDirectory.entity.models import Entity, EntityAlias, EntityBase, Subsidiary
import SomeRepoDirectory.entity.wikipedia
from SomeRepoDirectory.io.es import es_h
...
To further complicate it, the repo is pretty large and this file is just a small part of it. I'm not sure it is wise to load ALL of the repo's functions into my R environment.
And one more bonus question. I really would like to access the functions that are on a branch of the repo, not master. I've cloned the repository to a different directory than my R project using git clone git#github.com:my-company-name/really-big-repo.git
Here are the following steps you can try, but gotta say this is going to be complicated, might I say learning python might be easier :p
Like you said you have cloned the repository:
cd ./cloned_repo
conda activate your_vitual_env
git checkout feature/branch
python setup.py develop # this will install the pkg in virtual env, you can also use install instead of develop
Now in your R, use the virtual env in which you installed the repo, in my example I am using conda env, so you can use: reticulate::use_condaenv('your_virtual_env') and then you should be able to use those functions.
Also, in my experience intermingling python and R has caused a lot of pain for production development especially with package management. So I will advise some caution.
I've got code that loads a joblib file and works perfectly in my IDE. However when making an exe with pyinstaller it fails. This is some test code:
from joblib import load
print('imported joblib')
load('Repeat.joblib')
When running the exe it successfully imports load, but fails when reading the joblib file. The joblib file is a machine learning model build using scikit learn 0.22.1 and I have joblib 0.14.1.
I've tried everything I can think of. Pyinstaller initially failed with a recursion error but I fixed that using a spec file using
import sys
sys.setrecursionlimit(5000)
Any help?
A, I did find this post about people rolling back Joblib to v0.11 with some success. However that doesn't appear to have resolved your issue.
IT might be an issue with PyInstaller. The key might lie in your `hiddenimports'.
Bounty Source solution
I have some PyQt5 application with some tr() translations in it. I have a Python script that compiles UI forms and resources, and I want it to also update the ts file with translations, because it's a bit annoying to run pylupdate manually each time.
Alas, I haven't find any information, how to run the Python functions that provide translation file compilation in PyQt5. Haven't you ever got the same problem?
I was able to do it like this
import os
ret = os.system("E:\Anaconda3\Library\\bin\\pylupdate5.exe -verbose Main.py otherfile.py thirdfile.py -ts zh_CN.ts")
Hopefully you found it as well
I am attempting to convert a python file to an executable file. Easy enough right?
I used pyinstaller on a simple program that doesn't import anything. It worked like a charm. Then, I tried it with another dummy program with imported modules, (PyQt4, sys, matplotlib) that my actual program would have. Here I encountered problems.
This error appeared when I ran the application in the 'dist' folder pyinstaller created.
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'
I found another site with a possible solution to this problem, but his situation wasn't exactly the same: http://code.activestate.com/lists/python-dev/118463/
This lead me to trying the QT designer that I downloaded earlier. Perhaps if I could convert the .ui file it produced into a .py file, I would be fine. I could use his solution and all would be well.
That's when I got this error:
File "C:\Anaconda3\Lib\site-packages\PyQt4\uic\pyuic.py", line 26, in module
from PyQt4 import QtCore
mportError: No module named 'PyQt4'
I should also probably mention that all the modules I have are through Anaconda 3
I thought installing pyqt in a conda... project? Would fix the problem. It didn't. To be honest I don't entirely know what those are for.
Now I'm entertaining the idea of just using the c++ files that QT designer makes instead of converting them and importing python to tell the gui what to do.
What do you guys think would solve the errors above?
Short solution / workaround:
In your python file import the missing module explicitly. In your case: import encodings.
Proper solution:
By importing every module separately so you might end up imorting many modules and submodules. In this case you need tell pyinstaller where to find the modules (e. g. using compile flags).