-
-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document installation for OSX (cannot import name constants) #29
Comments
What files does
What’s the entire output of the above? Does it fix the issue? |
Yes, it do contain constants.py. |
Ok. Add these lines to
You should now get two additional lines of output, before the traceback. What do they contain? |
|
I’m sorry, I have no idea what’s going on there… Everything looks like it should work. Does this work, when Graphite is not involved?
|
Something wrong with my environment. Yesterdays fix is not working. Let me go through it.
|
@nitinbodke Did you solve the environment problem at the end? I am facing the same problem now and have no idea where to continue fixing the problem. Any advice is highly appreciated. Thank you. |
@hanneshapke Please describe exact step to setup your environment and reproduce the bug, and copy any traceback or other output here. Also do as in #29 (comment) and copy the output here. |
Hi @SimonSapin thank you for offering your help I am trying to install Weasyprint via
I have installed the required packages via
Everything installs well and also the However, when I try to execute
The reinstall of The print out of
The test import of cairocffi brings up this error:
However
Please let me know if you need further tracebacks |
|
@hanneshapke this sounds like #28. I just pushed v0.5.3 to PyPI with a possible fix. Get it with |
Unfortunately not, problem persists.
I notice something interesting. I read through #28 and noticed the same problem that the imports don't work.
Could this maybe the issue? |
These look like two separate issues. Are you certain you’re using the same Python install and virtual environment (if any) in both cases? |
I think so. When I exit Python and run
Pretty sure these are the same environments. |
What’s the output of |
Does it mean, two different python versions are involved? |
I’m not sure. What about |
What does it tell you? |
Ok, this does look like two different Python versions (one in The first line of the file indicated by That explain away the However, that leaves the |
Hi Simon, Thank you for your detailed help!
Would it make sense to try installing all packages in a fresh virtualenv to avoid any conflicts? To your second point. Your guess was right. The first line of |
I guess one of your Pythons was shipped by Apple and the other one installed by Homebrew. But I don’t know, I don’t use OS X myself. If someone can tell me what dlopen incantation I need to reliably load dynamic libraries on OS X, I’ll be happy to fix this, but I just don’t know what to do here. |
It looks like cffi might not be able to load dylibs. Can you confirm that? I know ctypes can, it's slower but maybe a fallback to ctypes can be a solution in this case. |
Correction, cffi does support dylibs. This email seems relevant https://groups.google.com/forum/#!searchin/python-cffi/OSX$20in$20non-system$20Python/python-cffi/ZSj7xd7qAFQ/nJv33dDeFk8J |
Thanks for the link @mpaolino @hanneshapke Try to find out which directory contains the
|
Although I thought that’s what |
I installed cairocffi from pip on MacOS 10.6.8, using a python-anaconda distribution and got the same error as the original poster:
Changing
to
in the init.py of cairocffi fixed the issue for me. |
This makes no sense to me. If someone can explain the root cause of this issue I’m happy to fix it, but right now I have no idea what’s going on. |
In the version of cairocffi that I got from pip, the code in init.py never uses any of the cairo constants defined in constants.py directly, instead it uses
This can work if the module itself has been imported in the current namespace under the name constants, as is the case with:
but it cannot work if the constants contained in the module have been imported in the current namespace directly as is the case with:
|
Note that from . import constants
from .constants import * (Although the latter is at the end of the file.) The leading dot is important: it indicate explicit relative imports. The equivalent absolute imports are: from cairocffi import constants
from cairocffi.constants import *
|
Indeed, sorry, I read the code too fast. I experimented a little more and noticed something that might help resolve the issue. I only get an Import error:
when I previously got and fixed (by adding the required path to LD_LIBRARY_PATH) an OS error:
Maybe there is something in the code that is executed before the call to dlopen that isn't interrupted properly if the program fails on the dlopen call and prevents python from executing properly the imports afterwards? |
If it's helpful to anyone, I had this error (sadly, I didn't capture the entire traceback): File "/opt/graphite/lib/python2.6/site-packages/cairocffi/init.py", line 16, in The issue turned out to be Security Enhanced Linux preventing the read (by the web server) of the constants module. I'm not sure why some of the reads worked and others didn't, but in my case running the appropriate chcon command fixed the issue. |
I'm experiencing the same ImportError: cannot import name constants issue.
I initially followed the instructions from : (http://graphite.wikidot.com/installation) and built modules from source.
Subsequent requests are:
Soldiering on, I found this post and others about the issue. Starting carbon and graphite from the command line worked: when I navigate to (http://localhost:8080/dashboard/) there are no errors; everything looks to be fully functioning. Very puzzling. I then discovered something:
pip's sh-bang was I changed it to the latter. then found that starting graphite from the command line failed with missing modules. I re-added the modules and got graphite back working again. ...and. The problem persists: same same So the
and going even further: I noticed that the architecture for re-started apache and still I get both the I'm still wondering what it could be. |
OK. I've had some success.
I run:
to get the whole thing rolling. Note: I added
I think my problem was |
I don't know why, but |
I was experiencing many of the same problems in relation to installing WeasyPrint in a virtualenv on a clean vagrant box. @cdosborn suggestion worked like a charm for me as well. |
Thanks for the answer all above, I met this problem yesterday. By reading your answers, it solved by "brew install cairo"finnally lol |
We probably need a better documentation for OSX! |
Not sure if you already have an answer on this one, but I had the same issue today. As a result, when using cairocffi using plain Python, it will work. At least on my configuration. However, when using the shell of Django or start the run server, your env settings like DYLD_FALLBACK_LIBRARY_PATH are simply gone. A new shell starts and the env setting is gone. In my situation (running Django and using Weasyprint) I solved it by adding this line in my manage.py: I'm using port (not brew). Also note: after upgrading a working system to El Capitan or higher, consider recreating your virtualenv. |
I struggled with the My solution was to hack the WeasyPrint and cairocffi Python packages after they were installed, so that they would work with MacPorts. The problem resides with the Here is how I modified def dlopen(ffi, *names):
"""Try various names for the same library, for different platforms."""
for name in names:
for lib_name in [name, '/opt/local/lib/'+name]:
try:
return ffi.dlopen(lib_name)
except OSError:
pass
# Re-raise the exception.
return ffi.dlopen(names[0]) # pragma: no cover These are the changes for def dlopen(ffi, *names):
"""Try various names for the same library, for different platforms."""
for name in names:
for lib_name in [name, 'lib' + name, '/opt/local/lib/lib' + name]:
try:
path = ctypes.util.find_library(lib_name)
if path:
lib = ffi.dlopen(path)
if lib:
return lib
except OSError:
pass
raise OSError("dlopen() failed to load a library: %s" % ' / '.join(names)) Not an elegant solution, I grant you, but it gets the job done. |
I am trying to install Graphite. I am stuck upon cairo installation.
I came across "http://stackoverflow.com/questions/11491268/install-pycairo-in-virtualenv".
I have installed cairocffi in my virtual environment.
My environment is:
"OS X: 10.8.5
Python: 2.7.2
Virtual Env:
pip list
cairocffi (0.5.1)
ceres (0.10.0)
cffi (0.8.1)
Django (1.5.5)
django-tagging (0.3.1)
pip (1.5)
pycparser (2.10)
setuptools (2.0.2)
Twisted (11.1.0)
txAMQP (0.6.2)
whisper (0.9.12)
wsgiref (0.1.2)
zope.interface (4.0.5)"
Cairo:
I have installed cairo using macports.
"cairo @1.12.16_2+x11 (active)"
I started graphite with following sequence of commands:
http://0.0.0.0:8080/ is displaying Graphite home page.
But http://0.0.0.0:8080/render produces following traceback:
The text was updated successfully, but these errors were encountered: