I am working on a Python application on Windows10 in which I want to use Webkit module from Python. I am getting an error as no module named webkit. I have installed pygtk and python, but I cannot find anything for webkit. Any ideas?
Code :
import os
import urlparse
import webkit
import gtk
view = webkit.WebView()
sw = gtk.ScrolledWindow()
sw.add(view)
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.add(sw)
win.resize(1080,1920)
win.show_all()
uri = 'resources/football.html'
uri = os.path.realpath(uri)
uri = urlparse.ParseResult('file', '', uri, '', '', '')
uri = urlparse.urlunparse(uri)
view.load_uri(uri)
gtk.main()
Thank you.
Firstly pygtk is a dead project and you shouldn't use it; PyGObject is the maintained bindings.
Secondly only a very old version of WebKitGtk supports Windows that is terribly insecure and unmaintained so you shouldn't use it.
So sadly WebKitGtk does not support Windows.
Related
I am using python 2.7 but am not able to get anything how to read url which are active in tab of browsers.
So far i tried this
import win32gui
import win32process
import psutil
#w=win32gui
#value=w.GetWindowText(w.GetForegroundWindow())
#print(value)
appwindow = win32gui.GetForegroundWindow()
ProcessID = win32process.GetWindowThreadProcessId(appwindow)
#procname = psutil.Process(ProcessID)
#applicname = procname.name()
print("hello")
Check out pybrinf package, is Windows supported and allows you to get some info about a browser.
I just installed caldav 0.5.0 using pip on Windows. I tried to use this code from the documentation:
from datetime import datetime
import caldav
from caldav.elements import dav, cdav
# Caldav url
url = "https://user:pass#hostname/caldav.php/"
client = caldav.DAVClient(url)
But I get this error:
AttributeError: module 'caldav' has no attribute 'DAVClient'
Does someone know what causes this issue?
It is because your file is named calendar.py, which causes some kind of collision somewhere. Renaming your file to something else will do the trick (it did for me).
I am porting a Python2 script that uses Pango for drawing text to a Cairo surface. It works fine using the old PyGtk API with the pangocairo package. My system (Debian Jesse) doesn't have Python3 packages for PyGtk and instead uses the newer Gtk+ libraries with the PyGObject API.
I want to create a pangocairo.CairoContext object but it seems to be missing in the new API. The PangoCairo package has a create_context() function but it generates a PangoContext object that doesn't have the methods I need.
So far I have this:
import cairo
from gi.repository import Pango
from gi.repository import PangoCairo
surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 8, 8)
ctx = cairo.Context(surf)
pctx = PangoCairo.create_context(ctx) # Creates a PangoContext
pctx.set_antialias(cairo.ANTIALIAS_SUBPIXEL) # This fails
The old Python2 code that works:
import cairo
import pango
import pangocairo
surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 8, 8)
ctx = cairo.Context(surf)
pctx = pangocairo.CairoContext(ctx)
pctx.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
Does anyone have a solution for this? Is there any good documentation on how PangoCairo should be used with the new API?
It looks like the library has been rearranged a bit. The Pango context (now Pango.Context) is retrieved from the Pango.Layout object now. Here is a working solution:
import cairo
from gi.repository import Pango
from gi.repository import PangoCairo
surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 8, 8)
ctx = cairo.Context(surf)
layout = PangoCairo.create_layout(ctx)
pctx = layout.get_context()
fo = cairo.FontOptions()
fo.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
PangoCairo.context_set_font_options(pctx, fo)
I am using xampp and I am able to run simple python script on it so xampp is setup fine for python. I am trying to use pillow.
I have installed anaconda and did following in terminal
conda install pillow
If I run test.py below in terminal, it works fine. It prints format, size, mode.
But if I try it from web browser I'm getting blank page.
Here is test.py
#!/Library/Frameworks/anaconda/bin/python
print("Content-Type: text/html")
print()
print("<html><head><title>Python</title></head><body>")
from PIL import Image, ImageFilter
original = Image.open("Lenna.png")
print("<h5>The size of the Image is: </h5>")
print("<h2>size " + original.format, original.size, original.mode + "</h2>")
if I use cgitb.enable() I get following error
A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
/Applications/XAMPP/xamppfiles/cgi-bin/test7.py in ()
8 print("<html><head><title>Python</title></head><body>");
9 print("<h5>The size of the Image is: </h5>");
=> 10 from PIL import Image
11 original = Image.open("Lenna.png");
12 width, height = original.size;
PIL undefined, Image undefined
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PIL/Image.py in ()
61 # Also note that Image.core is not a publicly documented interface,
62 # and should be considered private and subject to change.
=> 63 from PIL import _imaging as core
64 if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
65 raise ImportError("The _imaging extension was built for another "
PIL undefined, _imaging undefined, core = <PIL.Image._imaging_not_installed object>
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PIL/_imaging.so, 2): Library not loaded: #loader_path/.dylibs/libtiff.5.dylib Referenced from: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PIL/_imaging.so Reason: Incompatible library version: _imaging.so requires version 8.0.0 or later, but libtiff.5.dylib provides version 6.0.0
args = ('dlopen(/Library/Frameworks/Python.framework/Vers...later, but libtiff.5.dylib provides version 6.0.0',)
msg = 'dlopen(/Library/Frameworks/Python.framework/Vers...later, but libtiff.5.dylib provides version 6.0.0'
name = '_imaging'
path = '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PIL/_imaging.so'
with_traceback = <built-in method with_traceback of ImportError object>
Kind of an anti-answer, but unless you are doing it this way for academic reasons, you should try one of the more standard frameworks:
Flask
bottle.py
The two frameworks I listed above are examples of minimalist frameworks that do not get in your way. They take care of running your app and setting up routes. The minimum to use Flask is this:
from flask import Flask
from PIL import Image, ImageFilter
app = Flask(__name__)
#app.route("/")
def myview():
original = Image.open("Lenna.png")
return """
<html><head><title>Python</title></head>
<body>
<h5>The size of the Image is: </h5>
<h2>size {format}, {size}, {mode}</h2>
</body></html>""".format(
format=original.format,
size=original.size,
mode=original.mode)
app.run()
Next, if you want to make your app available, you only need to setup a reverse proxy in XAMPP (easy-peasy). I highly suggest using Flask; it comes with an awesome in-page debugger, courtesy of its sister project Werkzeug (lit. "toolbox").
Werkzeug debugger:
I use django, python 2.7, virtualenv
I try in the admin to open a file with a dialogbox
def import_csv(self, request, queryset):
import csv
from Tkinter import *
from tkFileDialog import *
fileName = askopenfilename()
I have the error :
Can't find a usable init.tcl in the following directories:
C:/Python27/lib/tcl8.5 C:/mat4/env/lib/tcl8.5 C:/mat4/lib/tcl8.5 C:/mat4/env/library C:/mat4/library C:/mat4/tcl8.5.2/library C:/tcl8.5.2/library
This probably means that Tcl wasn't installed properly.
I tried to use easygui but it is the same
How to fix this error ?
This can't possibly work. Django is a web framework. You can't run a desktop GUI like Tkinter in a website.
You need to create a web form with a file field and a view to process the upload.