Building (./setup.py build) seems to go fine, installing (sudo ./setup.py install) gives a few errors:
byte-compiling build/bdist.linux-x86_64/egg/weasyprint/tests/testing_utils.py to testing_utils.pyc
File "build/bdist.linux-x86_64/egg/weasyprint/tests/testing_utils.py", line 81
print('%i errors logged:' % len(logs), file=sys.stderr)
^
SyntaxError: invalid syntax
And later here:
Extracting WeasyPrint-0.42-py2.7.egg to /usr/local/lib/python2.7/dist-packages
File "/usr/local/lib/python2.7/dist-packages/WeasyPrint-0.42-py2.7.egg/weasyprint/tests/testing_utils.py", line 81
print('%i errors logged:' % len(logs), file=sys.stderr)
^
SyntaxError: invalid syntax
In the end it gives: Finished processing dependencies for WeasyPrint==0.42
On running weasyprint the traceback is:
Traceback (most recent call last):
File "/usr/local/bin/weasyprint", line 11, in <module>
load_entry_point('WeasyPrint==0.42', 'console_scripts', 'weasyprint')()
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 570, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2751, in load_entry_point
return ep.load()
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2405, in load
return self.resolve()
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2411, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python2.7/dist-packages/WeasyPrint-0.42-py2.7.egg/weasyprint/__init__.py", line 32, in <module>
from .urls import (fetch, default_url_fetcher, path2url, ensure_url,
File "/usr/local/lib/python2.7/dist-packages/WeasyPrint-0.42-py2.7.egg/weasyprint/urls.py", line 22, in <module>
from base64 import decodebytes
ImportError: cannot import name decodebytes
What am I doing wrong?
According to the traceback, you're trying to install the current master branch. But the current master branch (and thus the next version) need Python 3.4+, you can use the 0.x branch if you want to keep Python 2 support.
(It's time to use Python 3 :wink:.)
We should probably have a better error message or this bug will not be the last one.
Thanks. Yes, I have python 3.5, but I also have 2.7 because of some other software that requires that.
Is there a way to use WeasyPrint with python3? I mean in my situation. Perhaps a special way when installing or building? I tried putting #!/usr/bin/python3 as the first line of weasyprint but then I get The 'WeasyPrint==0.42' distribution was not found and is required by the application.
(I have been running WeasyPrint for close to 2 years with both python2 and python3 installed, and only since the last release does it not work anymore.)
Is there a way to use WeasyPrint with python3?
Yes! Use it in a virtual environment as proposed by the documentation, but instead of launching virtualenv ./venv, launch virtualenv -p python3.5 ./venv.
So the recommendation is: don't use the repo.
If the version supplied through pip is mostly up-to-date, then that is sufficient.
I reopen the issue as having a nice error message would be much better than this ugly stacktrace :wink:.
OK, sorry.
It would also be nice if people could use the repo and don't need to use pip. Isn't there a fancy way to get it to work on systems where both python2 and python3 are installed..?
Isn't there a fancy way to get it to work on systems where both python2 and python3 are installed..?
You can also use python3 -m weasyprint instead of weasyprint, for example python3 -m weasyprint http://wikipedia.org wikipedia.pdf
Not sure how these modules get registered... python3 -m weasyprint works in the terminal where I have just build & installed. In all other terminal windows (also newly opened ones) I get: /usr/bin/python3: No module named weasyprint. Everywhere weasyprint in the path and gives the stacktrace when called bare.
Is there a way to force the recognition of weasyprint as a module in python3?
Is there a way to force the recognition of weasyprint as a module in python3?
Using python3 -m weasyprint will work if WeasyPrint is installed or in the current folder. If you REALLY don't want to install it, you can launch python3 /path/to/weasyprint/weasyprint.py.
I also noticed that after doing ./setup.py build; sudo ./setup.py install in the clone of this repo, that everything gets installed in /usr/local/lib/python2.7/dist-packages/WeasyPrint-0.42-py2.7.egg. Is there no way in the install procedure to force an install into /usr/local/lib/python3.5/dist-packages?
When I move /usr/local/lib/python2.7/dist-packages/WeasyPrint-0.42-py2.7.egg/weasyprint into /usr/local/lib/python3.5/dist-packages everything seems to work, even without python3 -m.
I also noticed that after doing ./setup.py build; sudo ./setup.py install in the clone of this repo, that everything gets installed in /usr/local/lib/python2.7/dist-packages/WeasyPrint-0.42-py2.7.egg. Is there no way in the install procedure to force an install into /usr/local/lib/python3.5/dist-packages?
Yes, just use sudo python3 setup.py install.
This one is worth making part of the official setup/install instructions!
I removed all trace of weasyprint, did ./setup.py build; sudo python3 setup.py install and it works everywhere, as is..!
Most helpful comment
Yes, just use
sudo python3 setup.py install.