I am currently using the following versions
Python - 2.7.10 ( 32 bit , win)
AndroidViewClient - androidviewclient-10.7.1-py2.7.egg
I have a simple program as below
import sys
import os
try:
sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
from com.dtmilano.android.viewclient import ViewClient
device, serialno = ViewClient.connectToDeviceOrExit()
vc = ViewClient(device=device, serialno=serialno)
device.takeSnapshot().save('Menu.png','PNG')
This is giving me the following error
*Traceback (most recent call last):
File "dump.py", line 14, in <module>
device.takeSnapshot().save('Menu.png','PNG')
File "C:\Python27\lib\site-packages\androidviewclient-10.7.1-py2.7.egg\com\dtmilano\android\adb\adbclient.py", line 678, in takeSnapshot
image = Image.open(stream)
File "C:\Python27\lib\site-packages\PIL\Image.py", line 2126, in open
% (filename if filename else fp))
IOError: cannot identify image file <cStringIO.StringI object at 0x023462A8>*
The Same snippet code - works for some devices and for some it doesnt
How can i figure out what is wrong with the devices where it doesnt work
Also please help me idetify any configuration issues as i am new to this
Related
I am a beginner at python and trying to use a very simple shutil module (shutil.copy) to copy databases from multiple folders into a backup folder. I am getting the error below. Any help is appreciated.
# importing os module
import os
#import time module
import time
import datetime
# importing shutil module
import shutil
now = datetime.datetime.now()
timestamp = str(now.strftime("%Y%m%d_%H%M%S"))
source5 = "F:/SHARED/SOP/PRE GO LIVE/TEST CASES & SCENARIOS/MASTER/PRE_GO_LIVE_MASTER.accdb"
dest5 = "F:/SHARED/SOP/SB/Python/Destination/PRE_GO_LIVE_MASTER.accdb_"+timestamp+".accdb"
print("Before copying ")
DB5 = shutil.copy(source5,dest5)
print("After DATABASE has been copied")
Error:
Traceback (most recent call last):
File "C:\Users\sbasava1\Desktop\Python\Final_Attempt.py", line 101, in <module>
DB5 = shutil.copy(source5,dest5)
File "C:\Python27\lib\shutil.py", line 119, in copy
copyfile(src, dst)
File "C:\Python27\lib\shutil.py", line 82, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 22] invalid mode ('rb') or filename:
Check your file path, use double backslashes \\ or a single forward slash / or make your string a raw string r"...".
# Original path - wouldn't work
path = "c:\location\directory"
# Raw string - would work
path = r"c:\location\directory"
# Double slashes - would work
path = "c:\\location\\directory"
# Forward slashes - would work
path = "c:/location/directory"
Consider learning about string literals
If this didn't help leave me a comment, it would also help to see the/part of the code you are working with!
Edit: Running your script didn't give me an issue:
Check if the directory you are trying to create a file in actually exists
I am writing a script that will save the complete contents of a web page. If I try using urllib2 and bs4 it only writes the contents of the logon page and none of the content after navigating to a search within the page. However, if I do a ctrl + s on the search results page, an html file is saved to disk that when opened in a text editor has all of the contents from the search results.
I've read several posts here on the subject and am trying to use the steps in this one:
How to save "complete webpage" not just basic html using Python
However, after installing geckodriver and setting the sys path variable I continue to get errors. Here is my limited code:
from selenium import webdriver
>>> from selenium.webdriver.common.action_chains import ActionChains
>>> from selenium.webdriver.common.keys import Keys
>>> br = webdriver.Firefox()
Here is the error:
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 142, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
And here is where I set the sys path variable:
I've restarted after setting sys path variable.
UPDATE:
I am now trying to use the chromdriver as this seemed more straight forward. I downloaded hromedriver_win32.zip II'm on a windows laptop) from chromedriver's download page, set the environmetal variable path to:
C:\Python27\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe
but am getting the similar following error:
>>> br = webdriver.Chrome()
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
You have also to add the path of Firefox to the system variables manually,
you maybe have installed firefox some other location while Selenium is trying to find firefox and launch from default location but it couldn't find. You need to provide explicitly firefox installed binary location:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('path/to/installed firefox binary')
browser = webdriver.Firefox(firefox_binary=binary)
browser = webdriver.Firefox()
I want to convert speech to text in real time using the module SpeechRecognition 3.4.6 I've installed everything and now I am trying a simple code from example, here's the code:
import speech_recognition as sr
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
# recognize speech using Sphinx
try:
print("Sphinx thinks you said " + r.recognize_sphinx(audio))
except sr.UnknownValueError:
print("Sphinx could not understand audio")
except sr.RequestError as e:
print("Sphinx error; {0}".format(e))
I am getting error at line audio = r.listen(source), the error traceback is:
Traceback (most recent call last):
File "sr.py", line 4, in <module>
audio = r.listen(source) # listen for the first phrase and extract it into audio data
File "/usr/local/lib/python2.7/dist- packages/speech_recognition/__init__.py", line 493, in listen
buffer = source.stream.read(source.CHUNK)
File "/usr/local/lib/python2.7/dist-packages/speech_recognition/__init__.py", line 139, in read
return self.pyaudio_stream.read(size, exception_on_overflow = False)
File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 608, in read
return pa.read_stream(self._stream, num_frames, exception_on_overflow)
TypeError: function takes exactly 2 arguments (3 given)
You need to install pyaudio 0.2.9, it seems you have older version
it seems that the version of python is too old.
I m Running Win 7 32 bit and i using python 27, i try to connect ms-access database in my QGIS plugin using pyodbc, but when i launch it i have a following error :
Traceback (most recent call last):
File "C:/PROGRA~1/QGISDU~1/apps/qgis/./python\qgis\utils.py", line 204, in startPlugin
plugins[packageName] = package.classFactory(iface)
File "C:\Users\Mr.Pakde/.qgis2/python/plugins\TestDbase\__init__.py", line 26, in classFactory
from testdbase import TestDbase
File "C:/PROGRA~1/QGISDU~1/apps/qgis/./python\qgis\utils.py", line 453, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "C:\Users\Mr.Pakde/.qgis2/python/plugins\TestDbase\testdbase.py", line 29, in
from testdbasedialog import TestDbaseDialog
File "C:/PROGRA~1/QGISDU~1/apps/qgis/./python\qgis\utils.py", line 453, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "C:\Users\Mr.Pakde/.qgis2/python/plugins\TestDbase\testdbasedialog.py", line 28, in
r'DBQ=C:\__tmp\test1.accdb')
Error: ('HY024', "[HY024] [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides. (-1023) (SQLDriverConnect); [HY024] [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides. (-1023)")
And i place it like this in my code :
from PyQt4 import QtCore, QtGui
from ui_testdbase import Ui_TestDbase
import pyodbc
db = pyodbc.connect(
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};' +
r'DBQ=C:\__tmp\test1.accdb')
class TestDbaseDialog(QtGui.QDialog):
def __init__(self):
QtGui.QDialog.__init__(self)
# Set up the user interface from Designer.
self.ui = Ui_TestDbase()
self.ui.setupUi(self)
Rec_1 = self.ui.btnOke
QtCore.QObject.connect(Rec_1, QtCore.SIGNAL('clicked()'),self.Compskala)
def Compskala(self):
skal1 = self.ui.lineSkal1.text()
skal2 = self.ui.lineSkal2.text()
bandskal = ''
if skal1 == skal2:
bandskal = 'Kedua Peta dapat dipadukan'
I really a newb in this, so can someone give me a help?
Substituting backslashes for forward slashes in the filename seems to work:
Fails
>>> db = pyodbc.connect("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};" +
"DBQ=C:\__tmp\test.accdb")
Traceback (most recent call last): File "", line 1, in
pyodbc.Error: ('HY000', '[HY000] [Microsoft][ODBC Microsoft
Access Driver] Not a valid file name. (-1044) (SQLDriverConnect)')
Succeeds
>>> db = pyodbc.connect("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};" +
"DBQ=C:/__tmp/test.accdb")
>>> connection.getinfo(pyodbc.SQL_SERVER_NAME)
'ACCESS'
I created my very first Python program for work and I have it running in PyCharm.
The program has a GUI, it basically pops up a window, has a directory tree so the user can select a jpg file, it then binarizes the image then lets the user select the binary threshold with a slider. It also displays two other images that I perform image transformations on.
SO, my problem is that I cannot build it to an .exe at all. I've tried Py2Exe, PyInstaller, and CX_freeze. I've tried building my own .spec files in Pyinstaller, but all have no success.
I'm running 2.7.6. I initially had 64 bit Python installed so I uninstalled everything Python related and installed 32 bit Python.
Initially when I was using pyinstaller I would just get ImportError: %1 is not a valid Win32 application, however since building a .spec file now I get actual errors. I've tried using hooks (hiddenimports=["wx", "scipy", "skimage", "matplotlib", "numpy"]) to make sure all the right files are included, but still no luck.
The main error that I'm receiving right now is: File "_ufuncs.pyx", line 1, in init scipy.special._ufuncs(scipy\special_ufuncs.c:19992) ImportError: No module named _ufuncs_cxx
I also created a smaller code below that just pops up a Wx window with a plot inside, but I receive the same error there.
Like I mentioned, I'm new to Python, and I've done a lot of reading and haven't been able to figure this out. I've spent probably 10-20 hours just trying to get it to compile correctly.
Below isn't my actual program, but a small snippet using wxPython and MatPlotLib that produces the same error.
This is the sample code:
import wx
from PIL import Image
import matplotlib
matplotlib.use("WXAgg")
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas#,NavigationToolbar2WxAgg as NavigationToolbar
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy
from scipy import interpolate
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from skimage.filter.rank import entropy
from skimage.morphology import disk
from skimage.util import img_as_ubyte
from skimage import color
from skimage import io
import skimage
from numpy import arange, sin, pi
class CanvasPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.canvas = FigCanvas(self, -1, self.figure)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.SetSizer(self.sizer)
self.Fit()
def draw(self):
t = arange(0.0, 3.0, 0.01)
s = sin(2 * pi * t)
self.axes.plot(t, s)
if __name__ == "__main__":
app = wx.PySimpleApp()
fr = wx.Frame(None, title='test')
panel = CanvasPanel(fr)
panel.draw()
fr.Show()
This is the error I receive:
Traceback (most recent call last):
File "<string>", line 11, in <module>
File "c:\python27_32bit\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstalle\loader\pyi_importers.py", line 270, in
load_module
exec(bytecode, module.__dict__)
File "C:\users\iolvera\PycharmProjects\EL and Grayscale Analyzer\build\compilertest\out00-PYZ.pyz\scipy.interpolate",line 156, in <module>
File "c:\python27_32bit\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\users\iolvera\PycharmProjects\EL and Grayscale Analyzer\build\compilertest\out00-PYZ.pyz\scipy.interpolate.interpolate", line 12, in <module>
File "c:\python27_32bit\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\users\iolvera\PycharmProjects\EL and Grayscale Analyzer\build\compilertest\out00-PYZ.pyz\scipy.special", line 531, in <module>
File "c:\python27_32bit\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 409, in load_module
module = imp.load_module(fullname, fp, filename, self._c_ext_tuple)
File "_ufuncs.pyx", line 1, in init scipy.special._ufuncs (scipy\special\_ufuncs.c:19992)
ImportError: No module named _ufuncs_cxx
My Python Path is correct C:\Python27_32bit\ and I also have \lib\site-packages\ and \DLL included correctly.
Like I mentioned, both programs run correctly in PyCharm.
Any help would be greatly appreciated.
Thank you!
I had this problem, and I fixed it in py2exe by specifically telling it to include the offending module. So, in setup.py:
includes = ['scipy.special._ufuncs_cxx']
setup(...,
options={"py2exe":{"includes":includes}}
)
I had this happen with a couple of other SciPy modules, too, so my includes list has about six things in it.