I can't seem to get WeasyPrint to work on Windows with Python 3.4 or 3.5. Has anyone been able to do this? There aren't forums at weasyprint.org and the IRC channel is dead.
I've been able to install using both Python 3.4.3 and 3.5.1. I've followed the guideline found here [1]. I've also made note that WeasyPrint's site claims it should work with Python 2.6+ or 3.1+.
When I install for Python 3.4.3 and open the Python shell and simply 'import weasyprint' I get this:
C:\Python34>python
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import weasyprint
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\site-packages\weasyprint\__init__.py", line 337, in <module>
from .html import find_base_url, HTML5_UA_STYLESHEET, get_html_metadata # noqa
File "C:\Python34\lib\site-packages\weasyprint\html.py", line 41, in <module>
HTML5_UA_STYLESHEET = CSS(filename=os.path.join(root, 'css', 'html5_ua.css'))
File "C:\Python34\lib\site-packages\weasyprint\__init__.py", line 224, in __init__
with result as (source_type, source, base_url, protocol_encoding):
File "C:\Python34\lib\contextlib.py", line 59, in __enter__
return next(self.gen)
File "C:\Python34\lib\site-packages\weasyprint\__init__.py", line 294, in _select_source
base_url = path2url(filename)
File "C:\Python34\lib\site-packages\weasyprint\urls.py", line 87, in path2url
path = pathname2url(path)
File "C:\Python34\lib\nturl2path.py", line 46, in pathname2url
if not ':' in p:
TypeError: 'str' does not support the buffer interface
>>>
I get a similar traceback when importing in Python 3.5.1, with the exception of the final TypeError being:
TypeError: a bytes-like object is required, not 'str'
[1] https://gist.github.com/doobeh/3188318
I had looked through the issues list at weasyprint.org and didn't find anyone else complaining about Python 3.x compatibility with WeasyPrint. Then I happened upon a pull request that did complain about just that and mirrors my difficulties exactly. So off the shelf it does not work with Python 3.x, but with a small hack it does, see [1]. I'll add some comments to the pull request and hopefully this incompatibility will get looked at.
[1] https://github.com/Kozea/WeasyPrint/pull/132
Related
I am new to Python so I could perhaps learn the basics first... I'm a musician and keen to learn how to use Python with music.
I installed Python 3.8 x64 for Windows 10. I then used pip to install music21.
Opened the Python Shell, typed import music21 and got this:
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import music21
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import music21
File "D:\Python\lib\site-packages\music21\__init__.py", line 170, in <module>
from music21 import base
File "D:\Python\lib\site-packages\music21\base.py", line 94, in <module>
from music21 import common
File "D:\Python\lib\site-packages\music21\common\__init__.py", line 39, in <module>
from music21.common.parallel import *
File "D:\Python\lib\site-packages\music21\common\parallel.py", line 19, in <module>
from music21.ext.joblib import Parallel, delayed # #UnresolvedImport # type: ignore
File "D:\Python\lib\site-packages\music21\ext\joblib\__init__.py", line 119, in <module>
from .parallel import Parallel
File "D:\Python\lib\site-packages\music21\ext\joblib\parallel.py", line 32, in <module>
from .externals.cloudpickle import dumps, loads
File "D:\Python\lib\site-packages\music21\ext\joblib\externals\cloudpickle\__init__.py", line 3, in <module>
from .cloudpickle import *
File "D:\Python\lib\site-packages\music21\ext\joblib\externals\cloudpickle\cloudpickle.py", line 167, in <module>
_cell_set_template_code = _make_cell_set_template_code()
File "D:\Python\lib\site-packages\music21\ext\joblib\externals\cloudpickle\cloudpickle.py", line 148, in _make_cell_set_template_code
return types.CodeType(
TypeError: an integer is required (got type bytes)
I have found example code to run with music21 but I can't use it if I get errors.
Hope someone can help. Apologies if I'm being a complete n00b. Did look at other questions but didn't find or didn't understand the answers.
So from your output, the main piece that seems most useful is the TypeError: an integer is required (got type bytes) in the _make_cell_set_template_code function in the D:\Python\lib\site-packages\music21\ext\joblib\externals\cloudpickle\cloudpickle.py file. This issue could be an issue with music21 not being compatible with Python 3.8. I'm reading the documentation from https://web.mit.edu/music21/ and it says v.5 support Python 3.4-3.6, so I would try to get on one of those versions and restart the process you did to get to the step above. Hope this helps!
music21 v5 does not support Python 3.8 -- choose 3.7 or download the latest Git from github.
EDIT: v5.7.2 now supports 3.8
I have python 2.6 on Windows. I just installed Dropbox API and when I do:
import dropbox
It gives an error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build\bdist.win32\egg\dropbox\__init__.py", line 3, in <module>
# $Id$
File "build\bdist.win32\egg\dropbox\client.py", line 22, in <module>
File "C:\Python26\lib\site-packages\dropbox-2.2.0-py2.6.egg\dropbox\rest.py", line 415
utf8_params = {encode(k): encode(v) for k, v in params.iteritems()}
What can i do?
Reproducible also on Linux:
#> python
Python 2.6.5 (r265:79063, May 6 2011, 16:17:46)
[GCC 4.5.0 20100604 [gcc-4_5-branch revision 160292]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dropbox
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/site-packages/dropbox-2.2.0-py2.6.egg/dropbox/__init__.py", line 3, in <module>
from . import client, rest, session
File "/usr/local/lib/python2.6/site-packages/dropbox-2.2.0-py2.6.egg/dropbox/client.py", line 22, in <module>
from .rest import ErrorResponse, RESTClient, params_to_urlencoded
File "/usr/local/lib/python2.6/site-packages/dropbox-2.2.0-py2.6.egg/dropbox/rest.py", line 415
utf8_params = {encode(k): encode(v) for k, v in params.iteritems()}
^
SyntaxError: invalid syntax
I was desperate to get it working on 2.6 as I can't upgrade to latest versions of python. Finally got it working.
All you need to do is change the dictionary comprehension
From:
utf8_params = {encode(k): encode(v) for k, v in params.iteritems()}
To:
for k, v in params.iteritems():
utf8_params[encode(k)] = encode(v)
And rest of the module worked as usual so far.
I don't have the rep to add a comment so adding as an answer :)
This is definitely related to Python 2.6. The install-script of Dropbox's Python SDK is already throwing syntax errors when you run it with Python 2.6. Strangely, it keeps running and finishes regardless. Dropbox is not very specific about the required minimal version of Python, but the install-script suggests 2.6. Nevertheless, importing the Dropbox module will fail both on Windows and Linux due to a syntax error.
I just installed Python 2.7.9 in parallel to my original Python 2.6.5 environment. With 2.7, the Dropbox SDK installs and loads without any syntax error at at.
I am trying to make exe using py2exe in Python. When I import py2exe I am getting error like this:
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import py2exe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\py2exe-0.9.2.0-py2.7-win32.egg\py2exe\__init__.py", line 9, in <module>
patch_distutils()
File "C:\Python27\lib\site-packages\py2exe-0.9.2.0-py2.7-win32.egg\py2exe\patch_distutils.py", line 68, in patch_distutils
from . import distutils_buildexe
File "C:\Python27\lib\site-packages\py2exe-0.9.2.0-py2.7-win32.egg\py2exe\distutils_buildexe.py", line 91, in <module>
from . import runtime
File "C:\Python27\lib\site-packages\py2exe-0.9.2.0-py2.7-win32.egg\py2exe\runtime.py", line 3, in <module>
from .dllfinder import Scanner, pydll
File "C:\Python27\lib\site-packages\py2exe-0.9.2.0-py2.7-win32.egg\py2exe\dllfinder.py", line 7, in <module>
from importlib.machinery import EXTENSION_SUFFIXES
ImportError: No module named machinery
Can any body help me fixing this out. I am not getting machinery module any where.
I just ran into this myself. I had installed 0.9 from pypi as well. If you look at the pypi page here py2exe on pypi, you'll see that the download only supports Python 3.3 and later and you should use the 0.6 download from here. I deleted the 0.9 egg after installing 0.6 and it worked after that.
I had same issue, because i had version py2exe0.9 and it is not supported for python2.7.
I downloaded lower version from here http://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/py2exe-0.6.9.win32-py2.7.exe/download
and it works.
I am working on windows box with 8 processors. I have to run a python script that does mass data processing. When run as such, the script uses only one processor. I learnt that, to harness the power of multiple processors, I can use parallel python (pp) library.
I installed the library on my machine and followed the instructions available at http://www.parallelpython.com/content/view/15/30/#QUICKSMP
However, the code to configure pp fails on my machine:
Python 2.7.1 (r271:86832, Nov 27 2010, 17:19:03) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import pp
>>> job_server = pp.Server()
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
job_server = pp.Server()
File "C:\Python27\lib\site-packages\pp.py", line 343, in __init__
self.set_ncpus(ncpus)
File "C:\Python27\lib\site-packages\pp.py", line 503, in set_ncpus
range(ncpus - len(self.__workers))])
File "C:\Python27\lib\site-packages\pp.py", line 148, in __init__
self.start()
File "C:\Python27\lib\site-packages\pp.py", line 161, in start
self.pid = int(self.t.receive())
File "C:\Python27\lib\site-packages\pptransport.py", line 134, in receive
msg_len = struct.unpack("!Q", size_packed)[0]
error: unpack requires a string argument of length 8
>>>
Can you please tell me how do I get this resolved? I have installed pp version 1.6.0
I'm trying to build PIL 1.1.6 against cygwin or mingw whilst running against a windows install of python. When I do either the build works but I get the following failure when trying to save files.
$ python25
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL.Image import open
>>> im = open('test.gif')
>>> im.save('output1.gif')
Traceback (most recent call last):
File "", line 1, in
File "c:\Python25\Lib\site-packages\PIL\Image.py", line 1405, in save
save_handler(self, fp, filename)
File "c:\Python25\Lib\site-packages\PIL\GifImagePlugin.py", line 291, in _save
ImageFile._save(imOut, fp, [("gif", (0,0)+im.size, 0, rawmode)])
File "c:\Python25\Lib\site-packages\PIL\ImageFile.py", line 491, in _save
s = e.encode_to_file(fh, bufsize)
IOError: [Errno 0] Error
>>>
I'm not compiling with the libraries for jpeg or zip support but I don't think this should be relevant here.
The failing line seems to be a write in encode_to_file in encode.c.
I'm suspiscious that this occurs because a file descriptor is being passed from Python (which was build under visual studio 2003) to _imaging.pyd but that the file descriptors don't match because on windows file descriptors are and abstraction on top of the operating system. Does anyone know anything about this?
As far as I can tell from some cursory Google searching, you need to rebase the DLLs after building PIL in order for it to work properly on Cygwin.
References:
http://jetfar.com/cygwin-install-python-imaging-library/
http://www.cygwin.com/ml/cygwin/2003-06/msg01121.html