ImportError pyramid hello world program - pyramid

source code:
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
def hello_world(request):
return Response('<h1>Hello world!</h1>')
if __name__ == '__main__':
config = Configurator()
config.add_view(hello_world)
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 8080, app)
server.serve_forever()
When I ran the sample hello_world program using pyramid, I got the following error.
Traceback (most recent call last):
File "application.py", line 2, in <module>
from pyramid.config import Configurator
File "/usr/local/lib/python2.7/dist-packages/pyramid/config/__init__.py", line 12, in <module>
from pyramid.interfaces import (
File "/usr/local/lib/python2.7/dist-packages/pyramid/interfaces.py", line 3, in <module>
from zope.interface import (
ImportError: No module named interface

You've installed something improperly - more than likely by using python setup.py develop somewhere instead of using pip install -e .. If you mix tools you're going to have some issues. This particular one seems to be due to namespace packages not being configured correctly which almost always is a symptom of using easy_install and pip in the same environment. You need to pick one (preferably pip), and sometimes the decision about which one to use was already made by whatever tool installed python for you.

Related

the correct way to use nornir plugins

I am a beginner with nornir, I am trying to run nornir plugins but I am having these errors:
Traceback (most recent call last):
File "nornirpy/start.py", line 2, in <module>
from nornir.plugins.tasks.commands import commands
ModuleNotFoundError: No module named 'nornir.plugins.tasks.commands'
My start.py file is very basic:
from nornir import InitNornir
from nornir.plugins.tasks.commands import commands
from nornir.core.inventory import Host
from path.to import InventoryPlugin
import json
nr = InitNornir("nornirpy/config.yml")
print(json.dumps(Host.schema(), indent=4))
What is the issue? I am using poetry to organize my project, is there a step I forgot? its not clear to me how can I use plugins in my application.
Hello Somayyah Mohammed;
First, check the version of nornir you are using. If version > 2.4.0 then module nornir.plugins.tasks.commands is not there. You can remove the import command it should work.

Python can't import dns package

I wanna learn coding in python, my first project should display dns setting from domains.
I use python 3.5 on my ubuntu 16.04 server : here the code from my dns.py:
#!/usr/bin/python3
import dns.resolver
r = dns.resolver.query('padaru.de', 'a')
print (r)
the output is:
Traceback (most recent call last):
File "./dns.py", line 4, in <module>
import dns.resolver
File "/home/users/boogieman/www/bin/dns.py", line 4, in <module>
import dns.resolver
ImportError: No module named 'dns.resolver'; 'dns' is not a package
my dns modul are here:
/usr/local/lib/python3.5/dist-packages/dns
but I have an python2.7/dist-packages/-dir too, and this directory is empty.
It's possible that, my script wanna use the module from the python2.7 dir?
can't find other issues there :/ can somebody help me with this problem?

pyramid.config.Configurator() does not work with 'with' context manager

Is trying the quick start guide in pyramid website: https://trypyramid.com
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.request import Response
def hello_world(request):
return Response('Hello World')
if __name__ == "__main__":
with Configurator() as config:
config.add_route('hello','/')
config.add_view(hello_world, route_name='hello')
app = config.make_wsgi_app()
server = make_server('0.0.0.0',6543,app)
Gives the following error:
/anaconda3/bin/python /Users/user1/Desktop/play/pyramid_play/tut_1/exp1.py
Traceback (most recent call last):
File "/Users/user1/Desktop/play/pyramid_play/tut_1/exp1.py", line 12, in <module>
with Configurator() as config:
AttributeError: __enter__
Process finished with exit code 1
Thanks Steve Piercy. This was an installation problem. I let pycharm install Pyramid while creating the project. pycharm used conda to install the package, which installed v1.5.7 (latest on conda repos) instead of the 1.9.1 (current version).
I installed pip to install the latest version which fixed the issue.

Can't get opencv working with a gtk backend on my mac

I am trying to do some human pose estimation with a cool library that can be found here:
https://github.com/DeNA/Chainer_Realtime_Multi-Person_Pose_Estimation
I have it working on still images using the tkagg backend, set via the following lines:
import matplotlib
matplotlib.use('tkagg')
import matplotlib.pyplot as plt
Unfortunately, to do the live webcam tracking it seems tkagg will not work. When I run the code to do live web cam tracking i get the following error:
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp, line 583
This seems to be telling me to use the GTK backend, which makes sense as that is what the original repo said to use. The issue is when i change the matplotlib.use line to GTK like so:
import matplotlib
matplotlib.use('GTK')
import matplotlib.pyplot as plt
This gives an error with the following trace:
Traceback (most recent call last):
File "/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/backends/backend_gtk.py", line 14, in
import gobject
ImportError: No module named 'gobject'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "camera_pose_demo.py", line 4, in <module>
from pose_detector import PoseDetector, draw_person_pose
File "/Users/mark/Downloads/Chainer_Realtime_Multi-Person_Pose_Estimation-master/pose_detector.py", line 8, in <module>
import matplotlib.pyplot as plt
File "/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/pyplot.py", line 116, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/backends/__init__.py", line 60, in pylab_setup
[backend_name], 0)
File "/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/backends/backend_gtk.py", line 18, in <module>
raise ImportError("Gtk* backend requires pygtk to be installed.")
ImportError: Gtk* backend requires pygtk to be installed.
This is obviously saying my program can't find the GTK backend. I have installed it via brew, but I have read of other people having this problem too - just withouth a clear answer. It seems as though I need to find GTK on my machine and explicitly tell my python program/virtualenv where that is, although i am not sure how to do this.
You need to install PyGTK (python wrapper for GTK) which in turn require pygobject (python wrapper for GObject).
PyGTK seems to be rather old (2011 year), I am not sure it works with Python 3.

Running Python in Windows

Am new to python, i installed python 3.2 in my windows and tried the following code,
import urllib, urllister
usock = urllib.urlopen("http://diveintopython.net/")
parser = urllister.URLLister()
parser.feed(usock.read())
usock.close()
parser.close()
for url in parser.urls: print(url)
Its showing,
Traceback (most recent call last):
File "demo.py", line 1, in <module>
import urllib, urllister
ImportError: No module named urllister
How to add that module?
urllister is not part of the standard library.
You must download file urllister.py from here, and save it next to the script you're running.

Resources