problems with monkeyrunner - monkeyrunner

I am working on making some changes to the android framework layer and building my own version. I am working based on froyo and trying to use monkeyrunner for some testing. I have pulled the source and can build and run in the emulator but when I try to use a monkeyrunner script I can't seem to get anyhting to work. I built the code using lunch full-eng and it runs fine on the device. I am just trying to get a simple script running based on the example at http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html shown below with a print statement added just to see if I could get anything to run.
/# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
/# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
print "Hello World!"
When the following line is in the script I get an error as follows.
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
Traceback (most recent call last):
File "../../MRTesting/MyTest.py, line 4, in
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
ImportError: cannot import name MonkeyDevice
So if I remove MonkeyDevice from the import as shown below I get a different error on the call to waitForConnection()
from com.android.monkeyrunner import MonkeyRunner
Traceback (most recent call last):
File "../../MRTesting/MyTest.py, line 6, in
device = MonkeyRunner.waitForConnection()
AttributeError: type object 'com.android.monkeyrunner.MonkeyRunner' has no attribute 'waitForConnection'
I tried modifying the call to have some arguments as indicated in the documentation as follows but I still get the same error. The second argument matches the value returned by a call to adb devices.
device = MonkeyRunner.waitForConnection(5, 'emulator-5554')
I have done some digging around and one person said that the shebang needs to be at the beginning of the file as follows with the path modified to avoid putting information in I would rather not share.
/#! /home/<path>/monkeyrunner
I could not see how this would be any different than me invoking monkeyrunner directly from the command line but I tried it and no luck. I did not install the sdk anywhere on my system as it is included in the build tree but it seems to me that the monkeyrunner tool might not be able to locate it as needed but I can't find any indication of how to fix this. I am running the following commands when I build my system from within my build directory at the root.
. build/envsetup.sh
setpaths
lunch full-eng
make -j16
Anyone have any thoughts on this?

Related

Cannot download tensorflow model of cahya/bert-base-indonesian-522M

I was going to download this model, and then I was going to save it later to be used with bert-serving. Since bert-serving only supports tensorflow model, I need to download the tensorflow one and not the PyTorch. The PyTorch model downloads just fine, but the I cannot download the tensorflow model. I used this code to download:
from transformers import BertTokenizer, TFBertModel
model_name='cahya/bert-base-indonesian-522M'
model = TFBertModel.from_pretrained(model_name)
Here's what I got when running the code on Ubuntu 16.04, python3.5, transformers==2.5.1,
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/username/.local/lib/python3.5/site-packages/transformers/modeling_tf_utils.py", line 346, in from_pretrained
assert os.path.isfile(resolved_archive_file), "Error retrieving file {}".format(resolved_archive_file)
File "/usr/lib/python3.5/genericpath.py", line 30, in isfile
st = os.stat(path)
TypeError: stat: can't specify None for path argument
And here's what I got when running it on Windows 10, python 3.6.5, transformers 3.1.0:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\transformers\modeling_tf_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
579 if resolved_archive_file is None:
--> 580 raise EnvironmentError
581 except EnvironmentError:
OSError:
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
<ipython-input-3-c2f14f761f05> in <module>()
3 model_name='cahya/bert-base-indonesian-522M'
4 tokenizer = BertTokenizer.from_pretrained(model_name)
----> 5 model = TFBertModel.from_pretrained(model_name)
C:\ProgramData\Anaconda3\lib\site-packages\transformers\modeling_tf_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
585 f"- or '{pretrained_model_name_or_path}' is the correct path to a directory containing a file named one of {TF2_WEIGHTS_NAME}, {WEIGHTS_NAME}.\n\n"
586 )
--> 587 raise EnvironmentError(msg)
588 if resolved_archive_file == archive_file:
589 logger.info("loading weights file {}".format(archive_file))
OSError: Can't load weights for 'cahya/bert-base-indonesian-522M'. Make sure that:
- 'cahya/bert-base-indonesian-522M' is a correct model identifier listed on 'https://huggingface.co/models'
- or 'cahya/bert-base-indonesian-522M' is the correct path to a directory containing a file named one of tf_model.h5, pytorch_model.bin.
This also happens with other cahya/ models. This page says that you can use the tensorflow model. However, based on the error, it seems like the file does not exist over there?
I tried downloading other pretrained model like bert-base-uncased etc. and they download just fine. This issue only happens with cahya/ models.
Am I missing something? or should I report this issue to forum or the github issue?
This seems to be purely an issue of your environment.
Running the first code sample worked fine for me under Ubuntu 18.04 (I think using at least Ubuntu 16.04 should work as well, Windows 10 I cannot guarantee). I further use transformers 3.1.0, and tensorflow 2.3.0.
The first environment to me seems to be purely the fault of outdated versions for both Python (recommendation in general is at least 3.6+ currently, not even tied to transformers specifically), as well as the latest transformers release for full compatibility with models from the ModelHub.
For the second enviornment, I cannot full confirm this, but I supsect that it is due to path handling under Windows 10, as transformers needs to interpret paths as either an OS path, or ModelHub id.

pyinstaller ImportError: C extension: No module named np_datetime not built

I am running a virtual environment with Python 2.7 for my program.
There seems to be a problem after creating the executable file on windows.
I ran venv/Scripts/pyinstaller.exe -F main.py
everything seems fine. But when i click on the created executable main.exe.
There is an error.
Tried and tested
I have re-installed of pandas and pyinstaller
Implemented the hook-pandas.py to the hooks folder in the environment.
hook-pandas
Ensured the environment is activated.
Checked that the program is running fine before building executable.
Re-created the environment.
Yet after all that, I am prompted with this issue [see Importerror] when I run the executable file.
It is an extreme pain to debug this because the command prompt displaying the error will not pause but close almost immediately.
Similar issues
Looking for Suggestions
I am hoping for suggestions to troubleshoot Pyinstaller. Any resources to read up on would be nice.
Usually, I have no trouble with python as Pycharm has several handy debugging tools that will help me identify the problem
I ran into the same problem and found this thread, but I managed to solve it borrowing from the reference you posted (about pandas._libs.tslibs.timedeltas), so thank you for that!
In that article, the module that resulted in the ImportError was, in fact pandas._libs.tslibs.timedeltas, if you look at the poster's logs. But the error you and I ran into refers to np_datetime instead. So, from the traceback logs, I finally figured out that the code we have to write in hook-pandas.py should be the following:
hiddenimports = ['pandas._libs.tslibs.np_datetime']
Maybe that alone will solve your problem, HOWEVER, in my case, once I solved the np_datetime issue, other very similar ImportError problems arose (also related to hiddenimports regarding pandas), so, in case you run into the same issues, just define hiddenimports as follows:
hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']
TL;DR:
You can first try to write
hiddenimports = ['pandas._libs.tslibs.np_datetime']
into hook-pandas.py. However, if for some reason you run into the exact same issues I did afterwards, try
hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']
If you wish to dive deeper (or run into a different pandas ImportError than the ones I did), this is the code in pandas's __init__.py referenced in your traceback log (lines 23 to 35):
from pandas.compat.numpy import *
try:
from pandas._libs import (hashtable as _hashtable,
lib as _lib,
tslib as _tslib)
except ImportError as e: # pragma: no cover
# hack but overkill to use re
module = str(e).replace('cannot import name ', '')
raise ImportError("C extension: {0} not built. If you want to import "
"pandas from the source directory, you may need to run "
"'python setup.py build_ext --inplace --force' to build "
"the C extensions first.".format(module))
From that I went into the
C:\Python27\Lib\site-packages\pandas_libs
and
C:\Python27\Lib\site-packages\pandas_libs\tslibs
folders and found the exact names of the modules that resulted the errors.
I hope that solves your problem as it did mine.
Cheers!

flask installation error in running _init_.py

I have this error while installing Flask in command prompt:
(flask) C:\myproject\app>python_init_.py
Traceback (most recent call last):
File "_init_.py", line 3, in <module>
app = Flask<_name_>
NameError: name '_name_' is not defined
What does this mean, and how can I fix it?
The dunder name variable is __name__ with two underscores (for init.py by the way) on both side. Also your should have parenthesis not <>:
app = Flask(__name__)
You can read more about dunder variable and methods in the official documentation.
Sidenote:
A common convention in python is to name your main package by the name of your project in lowercase. From that I tend to use __package__ instead of __name__. Flask example are simple enough to work in a one file structure but in real world you probably gonna have more. Therefore __name__ will be __init__ from the module name while __package__ will be equal to project/app name

Why the imported PowerFactory module in python can only execute single time?

The script is be able to run a software called PoiwerFctory externally by Python as follows:
#add powerfactory.pyd path to python path
import sys
sys.path.append("C:\\Program Files\\DIgSILENT\\PowerFactory 2017
SP2\\Python\\3.6")
#import powerfactory module
import powerfactory
#start powerfactory module in unattended mode (engine mode)
app=powerfactory.GetApplication()
#get the user
user=app.GetCurrentUser()
#active project
project=app.ActivateProject('Python Test') #active project "Python Test"
prj=app.GetActiveProject #returns the actived project
#run python code below
ldf=app.GetFromStudyCase('ComLdf') #caling loadflow command object
ldf.Execute() #executing the load flow command
#get the list of lines contained in the project
Lines=app.GetCalcRelevantObjects('*.ElmLne') #returns all relevant objects,
i.e. all lines
for line in Lines: #get each element out of list
name=line.loc_name #get name of the line
value=line.GetAttribute('c:loading') # return the value of elements
#Print the results
print('Loading of the line: %s = %.2f'%(name,value))
When the above code first time executed in Spyder, it will show proper resutls. However, if re-executing the script again, the following error is appeared:
Reloaded modules: powerfactory
Traceback (most recent call last):
File "<ipython-input-9-ae989570f05f>", line 1, in <module>
runfile('C:/Users/zd1n14/Desktop/Python Test/Call Digsilent in
Python.py', wdir='C:/Users/zd1n14/Desktop/Python Test')
File "C:\ProgramData\Anaconda3\lib\site-
packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-
packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/zd1n14/Desktop/Python Test/Call Digsilent in Python.py",
line 12, in <module>
user=app.GetCurrentUser()
RuntimeError: 'powerfactory.Application' already deleted
Referred to How can I exit powerfactory using Python in Unattended mode?, this may because of PowerFactory in still running. And the only way which has been found so far is to re-start the Spyder and execute the script again, this is so inefficiency that if I want to re-write the code and debugging it.
It would be so much appropriated that if anyone could give me some advice for such problem.
I ran into the same Problem. Python is still connected to powerfactory and gives the Error if you try to connect again. What basicly worked for me was to kill the instance on the end of your skript with
del app
another idea during debugging could be:
try:
# Do something in your skript
finally:
del app
So the killing of the instance happens in any case.
The way to solve this is to reload the powerfacotry module by adding:
if __name__ == "__main__":
before import powerfacory.
The reason behind may referred to: What does if __name__ == "__main__": do?.

Beginners Module error

Hey guys just playing around with Xively at the moment with a PI.
I am having troubles getting my pi to run the python script tho.
https://xively.com/dev/tutorials/pi/#code
Was the tutorial i used but i keep getting this error.
(venv)pi#raspberrypi /home/xively_tutorial $ python xively_tutorial.py
Traceback (most recent call last):
File "xively_tutorial.py", line 4, in
import xively
ImportError: No module named xively
Any help on fixing this would be much appreciated.
Cheers
My hunch is you have closed down the SSH session after the first install. If you didn't re-source the "activate" command for the Python virtual environment, it wouldn't find the module.
Don't forget the "source .envs/.venv/bin/activate" command before running in a new SSH.

Resources