Getting 'ImportError: No module named appium' - python-appium

I am using following piece of code in python:
from appium import webdriver
from os import path
CUR_DIR = path.dirname(path.abspath(__file__))
APP = path.join(CUR_DIR, 'TheApp.app.zip')
APPIUM = 'http://localhost:4723'
CAPS = {
'platformName': 'iOS',
'platformVersion': '14.0',
'deviceName': 'iPhone 12 mini',
'automationName': 'XCUITest',
'app': APP,
}
driver = webdriver.Remote(APPIUM, CAPS)
driver.quit()
I was able to start a session directly from the Appium desktop app using this same desired capabilities, but when I try to run this script to start the session from there, I get this error:
from appium import webdriver
ImportError: No module named appium
Advice please, it's my first time dealing with these technologies. Thank you!

The problem I had was I was trying to run the file using python session_ios.py; I solved it when I changed to python3 session_ios.py because it is the version of Appium that I have installed.

Related

ModuleNotFoundError: No module named 'gspread' on python anywhere

What I am trying to achieve.
Run a python script saved On pythonanywhere host from google sheets on a button press.
Check the answer by Dustin Michels
Task of Each File?
app.py: contains code of REST API made using Flask.
runMe.py: contains code for that get values from(google sheet cell A1:A2). And sum both values send sum back to A3.
main.py: contains code for a GET request with an argument as name(runMe.py).filename may change if the user wants to run another file.
I Made an API by using Flask.it works online and offline perfectly but still, if you want to recommend anything related to the app.py.Code Review App.py
from flask import Flask, jsonify
from flask_restful import Api, Resource
import os
app = Flask(__name__)
api = Api(app)
class callApi(Resource):
def get(self, file_name):
my_dir = os.path.dirname(__file__)
file_path = os.path.join(my_dir, file_name)
file = open(file_path)
getvalues = {}
exec(file.read(), getvalues)
return jsonify({'data': getvalues['total']})
api.add_resource(callApi, "/callApi/<string:file_name>")
if __name__ == '__main__':
app.run()
Here is the Code of runMe2.py
import gspread
from oauth2client.service_account import ServiceAccountCredentials
# use creds to create a client to interact with the Google Drive API
scopes =['https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name('service_account.json', scopes)
client = gspread.authorize(creds)
# Find a workbook by name and open the first sheet
# Make sure you use the right name here.
sheet = client.open("Demosheet").sheet1
# Extract and print all of the values
list_of_hashes = sheet.get_all_records()
print(list_of_hashes)
below is the main.py code
import requests
BASE = 'https://username.pythonanywhere.com/callApi/test.py'
response = requests.get(BASE)
print(response.json())
main.py output
{'data': 54}
Test.py code
a = 20
b = 34
total = a+b
print(total)
PROBLEM IS
if I request runMe2.py at that time I am got this error.
check runMe2.py code above
app.py is hosted on https://www.pythonanywhere.com/
ModuleNotFoundError: No module named 'gspread'
However, I installed gspread on pythonanywhere why using the command. but it's not working.
You either haven't installed the gspread package on your current python environment or it is installed somewhere (e.g. in a diff. virtual env) and your script cant find it.
Try installing the package inside the environment your running your script in using pip3:
pip3 install gspread
You can try something like this on Windows
pip install gspread
or on Mac
pip3 install gspread
If you're running on Docker, or building with a requirements.txt you can try adding this line you your requirements.txt file
gspread==3.7.0
Any other instructions for this package can be found here => https://github.com/burnash/gspread
Download gspread here
Download the tar file: gspread-3.7.0.tar.gz from the above link
Extract file and convert folder in zip then upload it back on server
Open bash console and use command as
$ unzip gspread-3.7.0
$ cd gspread-3.7.0
$ python3.7 setup.py install --user

How to take screenshots in AWS Device farm for a run using appium python?

Even after a successful execution of my tests in DeviceFarm, I get an empty screenshots report. I have kept my code as simple as below -
from appium import webdriver
import time
import unittest
import os
class MyAndroidTest(unittest.TestCase):
def setUp(self):
caps = {}
self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
def test1(self):
self.driver.get('http://docs.aws.amazon.com/devicefarm/latest/developerguide/welcome.html')
time.sleep(5)
screenshot_folder = os.getenv('SCREENSHOT_PATH', '/tmp')
self.driver.save_screenshot(screenshot_folder + 'screen1.png')
time.sleep(5)
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(MyAndroidTest)
unittest.TextTestRunner(verbosity=2).run(suite)
I tested on a single device pool -
How can I make this work ?
TIA.
Missing a slash (/) before the filename (i.e., screen1.png). Line 15 should be as below -
self.driver.save_screenshot(screenshot_folder + '/screen1.png')
Though I'm not sure exactly how to write this to a file in Device Farm here are the appium docs for the screenshot endpoint and a python example.
https://github.com/appium/appium/blob/master/docs/en/commands/session/screenshot.md
It gets a base 64 encoded string which then we would just need to save it somewhere like the appium screenshot dir the other answers mentioned. Otherwise we could also save it in the /tmp dir and then export it using the custom artifacts feature.
Let me know if that link helps.
James

MATLAB Engine for Python: Desktop not supported, Swing is not currently available

I need to start MATLAB in Python using MATLAB Engine API for Python as www-data with GUI/as desktop app. And the following code results in the error:
import matlab.engine
eng = matlab.engine.start_matlab()
eng.desktop(nargout=0)
When I try to run this code, the -desktop argument is just ignored and Matlab runs like -nodesktop.
import matlab.engine
eng = matlab.engine.start_matlab('-desktop')
Error: desktop is not supported because: Swing is not currently available.
How to make it run?

IPython Failing to Run Code

I was trying out this Python code from a training website in IPython:
from bs4 import BeautifulSoup
import requests
url = raw_input("www.google.com")
r = requests.get("http://" +url)
data = r.text
soup = BeautifulSoup(data)
for link in soup.find_all('a'):
print(link.get('href'))
and found that it ran fine on the first try. I've now tried simply restarting the kernel, opening a new notebook, and generally returning the settings to how they were when I first ran the program with no luck. Why might IPython be failing to run the code and giving no response at all (as though I haven't clicked anything)?
Seems like raw_input is not supported by IPython. So it's probably just hanging there. If you change:
url = raw_input("www.google.com")
to
url = "www.google.com"
it should work.

import error: Django Running in terminal works but not in eclipse IDE

from django.http import HttpResponse
import urllib2
import simplejson
import memcache
def epghome(request):
mc=memcache.Client(['localhost:11211'])
if mc.get("jsondata"):
myval=mc.get("jsondata")
return HttpResponse("<h1>This Data is coming from Cache :</h1><br> " + str(myval))
else:
responseFromIDubba = ""
responseFromIDubba = urllib2.urlopen("http://www.idubba.com/apps/guide.aspx?key=4e2b0ca2328e03acce0014101d302ac7&type=1&f1=1&f2=0&channel=&gener=&page=0&summary=1").read()
parseResponseString = simplejson.loads(responseFromIDubba)
print(parseResponseString)
body=""
for data in parseResponseString["data"]:
#for keys in data:
#body=body+str(data .items())+".."+str(data[str(keys)])+"<br>"
body=body+str(data.items())+"<br><br>"
#body=body+"<br><br>"
mc.set("epgdata3",body)
mc.set("jsondata",responseFromIDubba)
returndata=str(mc.get("jsondata"))
return HttpResponse("<h1>No Cache Set</h1>" + responseFromIDubba)
Hi, This code is working if I run it in the terminal Python, without any error.
But in ECLIPSE IDE it always gives Import Error.
Even if I downloaded and install those modules. Also, and I restarted both Eclipse and my system, but it won't help.
Can you please suggest me a site where I get all libraries at once ?