OData example not working (Python) - python

I'm running this code that I got from here
https://tuomur-python-odata.readthedocs.io/en/latest/#what-is-this
from odata import ODataService
url = 'http://services.odata.org/V4/Northwind/Northwind.svc/'
Service = ODataService(url, reflect_entities=True)
Order = Service.entities['Order']
query = Service.query(Order)
query = query.filter(Order.Name.startswith('Demo'))
query = query.order_by(Order.ShippedDate.desc())
for order in query:
print(order.Name)
When I run the code, it says ImportError: No module named odata. I tried using pip install odata, nothing was found. How do I install this library? I can't find any documentation on how to install it either.

Download the project from GitHub, run python setup.py install, sudo if necessary.

Related

Can't import deepspeech on kivy for android

I am using kivy to create an android app. I need to install the deepspeech framework, however, in order for deepspeech to be installed it is necessary to create a recipe.
I created a recipe and built the apk, there were no errors in the build, it created the apk and also, as far as I could see in the folders, the deepspeech was built. However after I install the app in the phone and try to run the app, it crashes and says there is no module named deepspeech.
Does anyone know what i am doing wrong? I've been stuck on this for a while now, and can't seem to find the end of this :/.
from pythonforandroid.recipe import PythonRecipe
from pythonforandroid.toolchain import current_directory, shprint
import sh
class deepspeechRecipe(PythonRecipe):
version = 'v0.9.2'
url = 'https://github.com/mozilla/DeepSpeech/archive/{version}.tar.gz'
depends = ['numpy', 'setuptools']
call_hostpython_via_targetpython = False
site_packages_name = 'deepspeech'
def build_arch(self, arch):
env = self.get_recipe_env(arch)
with current_directory(self.get_build_dir(arch.arch)):
# Build python bindings
hostpython = sh.Command(self.hostpython_location)
shprint(hostpython,
'setup.py',
'build_ext', _env=env)
# Install python bindings
super().build_arch(arch)
def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
numpy_recipe = self.get_recipe('numpy', self.ctx)
env['CFLAGS'] += ' -I' + numpy_recipe.get_build_dir(arch.arch)
#env['LDFLAGS'] += ' -L' + sqlite_recipe.get_lib_dir(arch)
env['LIBS'] = env.get('LIBS', '') + ' -lnumpy'
return env
recipe = deepspeechRecipe()
Buildozer:1.4.0
requirements = python3==3.7.14, hostpython3==3.7.14, kivy, kivymd, sqlite3, numpy==1.14.5, deepspeech, apsw
If you need any extra information I can add.
I have already tried using tensorflow to run the model, however, the model gives an array as the output and I don't know the right procedures to transform that into a text form.
I have already tried other recipes (like opencv) and all work fine.
Edit:
I found out that when i use the recipe it does run, and it does build properly, but only the deepspeech_training part because the setup.py only installs that. To install other parts like the model class it is necessary to use another setup.py located in "native_client/python", but that requires the rest of the folders, so I still need to figure that out.
Edit2:I was able to build the packages that i wanted (the inference of deepspeech) however when i run it gives the following error.
python : ImportError: dlopen failed: library "libc++_shared.so" not found: needed by /data/user/0/org.test.myapp/files/app/_python_bundle/site-packages/deepspeech/_impl.so in namespace classloader-namespace
python : Python for android ended.
Add pillow in your requirements and check if it works!
requirements = python3==3.7.14, hostpython3==3.7.14, kivy, kivymd, sqlite3, numpy==1.14.5, deepspeech, apsw, pillow

openstack API python - no module named version

I'm trying to instanciate VM on openstack using the NovaClient API in python. More precisely with mq-rabbit celery tasks.
Unfortunatly I got this error :
from novaclient import client
File "/usr/local/lib/python2.7/dist-packages/novaclient/__init__.py", line 15, in <module>
import pbr.version
ImportError: No module named version
I already tested with a simple python file and it works, my VM was created but when I try to do this throught a celery tash I got the error above...
My version is the latest python-novaclient-6.0.2, but as our servers are in version 2 I use the version 2 API.
Here is my code in my celery task, who works when I test in python shell :
loader = loading.get_plugin_loader('password')
auth = loader.load_from_options(auth_url=auth_url, username=username, password=password, project_name=tenant_name)
sess = session.Session(auth=auth)
nova = client.Client('2', session=sess) #API version and session
Seems it's the same error and this one
Basically what you need is to make sure you have pbr installed.
If you had it already, reinstalling might help
pip uninstall pbr
pip install pbr

Postgresql ssl connection through python

I found below link
http://python.projects.pgfoundry.org/docs/1.0/driver.html#connection-keywords
it says...
import postgresql.driver as pg_driver
is the way to import
i used -
import postgresql.driver as pg_driver
pg_driver.connect(user = self.username, password = self.password, host = self.host, port = self.port,sslmode = 'verify-full', sslrootcert=self.ssl_cert)
but it gives 'ImportError: No module named postgresql.driver'
i tried 'pip install postgresql'
but it gives 'Could not find any downloads that satisfy the requirement postgresql
No distributions at all found for postgresql'
how can i fixed that ???
You can download latest version of py-postgresql and use 'Python34\python.exe setup.py install' to install it.
You can check Python34\Lib\site-packages\ if there is a folder called postgresql which proves it's installed correctly. Then try import postgresql.driver as pg_driver again and tell me if it works.

ImportError: No module named netifaces

I'm trying to get the IP address and MAC address of my pc's network card by python. I got some code from here
I create a proj "getip".
create "main.py". And I modify the code of "main.py" as follow
from netifaces import interfaces, ifaddresses, AF_INET
def ip4_addresses():
ip_list = []
for interface in interfaces():
for link in ifaddresses(interface)[AF_INET]:
ip_list.append(link['addr'])
return ip_list
def main():
print ip4_addresses()
if __name__ == "__main__":
main()
and I create "app.yaml"
application: getip
version: 1
runtime: python
api_version: 1
handlers:
- url: .*
script: main.py
and when I run the main.py at console as "python main.py", I got the ip addresses.
and when I run as "dev_appserver.py getip", the server is setup. When I browse the page as localhost:8080, the web page is white screen and I got the following error at console.
from netifaces import interfaces, ifaddresses, AF_INET
ImportError: No module named netifaces
How can I solve the problem?
just install netifaces
pip install netifaces if you have pip installed, or download the source, unpack it run and python setup.py install
warning: this will install it globally on your system, so use caution, or use virtualenv
If you are using ubuntu:
sudo apt install python3-netifaces
Came here for the same question but in my case pip install would say that requirement is already satisfied. However:
pip uninstall netifaces && pip install netifaces
fixed it.
Leaving this here for posterity. Use sudo if you need to.
Actually, the problem here is you must be root when installed with pip, or it will not install globally. Therefore would not be able to find the module unless in the same directory or path as the module directory
so you need this:
sudo pip install netifaces
or on windows install with an elevated command prompt!
It seems that you have installed netifaces in your local development environment. But Google App Engine does not recognize it.
If you run your script with python main.py, Python interpreter will look for your libraries in the PYTHONPATH. GAE does not follow that rule.
To install a library in GAE, usually you just need to put the library module directory in the root of your app path(whee the app.yaml is). But I don't think Google will allow you to install libraries that can get hardware information in their PaaS for security reasons.
Updates:
Becaue you just need a web server to output the result, I recommend you to choose a simple, well documented, micro Python web framework, like Flask or bottle.
Installation:
pip install Flask or easy_install Flask
code:
from flask import Flask
from netifaces import interfaces, ifaddresses, AF_INET
app = Flask(__name__)
def ip4_addresses():
ip_list = []
for interface in interfaces():
for link in ifaddresses(interface)[AF_INET]:
ip_list.append(link['addr'])
return ip_list
#app.route("/")
def main():
return str(ip4_addresses())
if __name__ == "__main__":
app.run()
Run: python main.py

Import error in twilio

I am having the same problem as this thread regarding twilio-python:
twilio.rest missing from twilio python module version 2.0.8?
However I have the same problem but I have 3.3.3 installed. I still get "No module named rest" when trying to import twilio.rest.
Loading the library from stand alone python script works. So I know that pip installing the package worked.
from twilio.rest import TwilioRestClient
def main():
account = "xxxxxxxxxxxxxxxx"
token = "xxxxxxxxxxxxxxxx"
client = TwilioRestClient(account, token)
call = client.calls.create(to="+12223344",
from_="+12223344",
url="http://ironblanket.herokuapp.com/",
method="GET")
if __name__ == "__main__":
main()
but this does not work:
from twilio.rest import TwilioRestClient
def home(request):
client = TwilioRestClient(account, token)
Do you have any idea what I can try next?
I named a python file in my project twilio.py. Since that file was loaded first, then subsequent calls to load twilio would reference that file instead of the twilio library.
TLDR: just don't name your python file twilio.py
Check which versions of pip and python you are running with this command:
which -a python
which -a pip
pip needs to install to a path that your Python executable can read from. Sometimes there will be more than one version of pip like pip-2.5, pip-2.7 etc. You can find all of them by running compgen -c | grep pip. There can also be more than one version of Python, especially if you have Macports or brew or multiple versions of Python installed.
Check which version of the twilio module is installed by running this command:
$ pip freeze | grep twilio # Or pip-2.7 freeze etc.
The output should be twilio==3.3.3.
I hope that helps - please leave a comment if you have more questions.
This Worked For me : (Windows)
Python librarys are in G:\Python\Lib
(Python is installed at G:, it might be different for you)
Download Twilio from github at paste the library at >> G:\Python\Lib <<
import problem gone :)
I had the same issue and it drove me crazy. Finally I figured it out. When you get the error:
AttributeError: module 'twilio' has no attribute 'version'
Look 2 lines above and the error is telling you where it expects to find the twilio file. So I moved it from where it was to where it was asking it to be.
Installed to:
c:\users\rhuds\appdata\local\programs\python\python37-32\lib\site-packages
Moved it to:
Traceback (most recent call last):
File "", line 1, in
import twilio
File "C:\Users\rhuds\AppData\Local\Programs\Python\Python37-32\twilio.py", line 2, in
Now I can import twilio. Besides that, the only other thing I did was uninstall old versions of Python, but I don't think that really mattered.

Categories