I have a pyenv virtualenv running 2.7.11. I run the following:
pip install newspaper
Which runs fine.
When I run the REPL I get the following:
Python 2.7.11 (default, Feb 22 2016, 10:04:27)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import newspaper
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ben/.pyenv/versions/burtonmail/lib/python2.7/site-packages/newspaper/__init__.py", line 10, in <module>
from .article import Article, ArticleException
File "/Users/ben/.pyenv/versions/burtonmail/lib/python2.7/site-packages/newspaper/article.py", line 12, in <module>
from . import images
File "/Users/ben/.pyenv/versions/burtonmail/lib/python2.7/site-packages/newspaper/images.py", line 19, in <module>
from PIL import Image, ImageFile
File "/Users/ben/.pyenv/versions/burtonmail/lib/python2.7/site-packages/PIL/Image.py", line 66, in <module>
from PIL import _imaging as core
ImportError: dlopen(/Users/ben/.pyenv/versions/burtonmail/lib/python2.7/site-packages/PIL/_imaging.so, 2): Symbol not found: _PyUnicodeUCS2_AsLatin1String
Referenced from: /Users/ben/.pyenv/versions/burtonmail/lib/python2.7/site-packages/PIL/_imaging.so
Expected in: flat namespace
in /Users/ben/.pyenv/versions/burtonmail/lib/python2.7/site-packages/PIL/_imaging.so
>>>
It looks to be a problem with linking PIL references but I'm not sure how to proceed.
That looks like the same error that we get if the extension is compiled for a different unicode standard than the python that running it. We're currently checking for _PyUnicodeUCS2_FromString in the import error, not _PyUnicodeUCS2_AsLatin1String here: https://github.com/python-pillow/Pillow/blob/master/PIL/Image.py#L85
What python are you using here, and how did you install pillow?
I have the same problem with OSX 10.11.3 El capitan
ImportError: dlopen(/Users/omm/.pyenv/versions/project/lib/python2.7/site-packages/PIL/_imaging.so, 2): Symbol not found: _PyUnicodeUCS2_AsLatin1String
Referenced from: /Users/omm/.pyenv/versions/project/lib/python2.7/site-packages/PIL/_imaging.so
Expected in: flat namespace
in /Users/omm/.pyenv/versions/project/lib/python2.7/site-packages/PIL/_imaging.so
pip install Pillow==2.5.3
Encountered the same issue after upgrading pyenv. Seems like the following change might be the reason:
python-build: Compile with --enable-unicode=ucs4 by default for CPython (#257, #542)
My current workaround is to specify ucs2 when using pyenv to install python:
PYTHON_CONFIGURE_OPTS="--enable-unicode=ucs2" pyenv install 2.7.11
Hope this would help.
To repeat, the two most important questions are:
Thank's @zhoulijoe that work for me
$pyenv deactive env
$pyenv uninstall env
$pyenv unistall 2.7.8
$PYTHON_CONFIGURE_OPTS="--enable-unicode=ucs2" pyenv install 2.7.8
$pyenv virtualenv 2.7.8 env
Cheers
Reverting the change to pyenv will get existing built extension modules working again, but won't solve the problem the pyenv change was intended to address: binary compatibility with prebuilt Mac OS X and manylinux1 wheel files published to PyPI.
On Linux, the following command will rebuild all of the modules in an environment (don't run it directly against your system Python!):
$ pip freeze | pip install --ignore-installed --no-use-wheel -r /dev/stdin
For Mac OS X, I don't believe /dev/stdin exists, so pip freeze will need to be written to a file and passed to pip install that way.
It doesn't look like this is a Pillow issue as much as a change in pyenv.
python 2.7.11 gives me that error - 2.7.6 doesn't
I upgraded because of this error
InsecurePlatformWarning
/venv/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning
but then i get this error with 2.7.11 v of python
Traceback (most recent call last):
[Sun Dec 04 12:50:04.537094 2016] [:error] [pid 11308:tid 139866024138496] [client 127.0.0.1:43087] from flask_resize import Resize
[Sun Dec 04 12:50:04.537102 2016] [:error] [pid 11308:tid 139866024138496] [client 127.0.0.1:43087] File "/venv/lib/python2.7/site-packages/flask_resize/__init__.py", line 9, in
[Sun Dec 04 12:50:04.537218 2016] [:error] [pid 11308:tid 139866024138496] [client 127.0.0.1:43087] from PIL import Image, ImageDraw, ImageFont, ImageColor
[Sun Dec 04 12:50:04.537227 2016] [:error] [pid 11308:tid 139866024138496] [client 127.0.0.1:43087] File "/venv/lib/python2.7/site-packages/PIL/Image.py", line 67, in
[Sun Dec 04 12:50:04.537644 2016] [:error] [pid 11308:tid 139866024138496] [client 127.0.0.1:43087] from PIL import _imaging as core
[Sun Dec 04 12:50:04.537663 2016] [:error] [pid 11308:tid 139866024138496] [client 127.0.0.1:43087] ImportError: /venv/lib/python2.7/site-packages/PIL/_imaging.so: undefined symbol: PyUnicodeUCS2_AsLatin1String
so I went back to 2.7.6 default version of virtualenv
@jreiher2003 Your Pillow binaries are compiled for a different python than you're trying to run with, specifically, there's a mismatch in wide/narrow unicode as mentioned above.
@jreiher2003 install
$pip install requests[security]
or directly
$pip install pyopenssl ndg-httpsclient pyasn1
and follow my steps above .
Regards,
Ed
@eduardolujan
what does this config do?
$PYTHON_CONFIGURE_OPTS="--enable-unicode=ucs2" pyenv install 2.7.8
Should I install these packages pyopenssl ndg-httpsclient pyasn1 in the virtualenv? or globally?
@eduardolujan my bad i wasn't familiar with pyenv. After doing a few test installs, everything works pretty good. no hang ups so far, thanks alot.
@jreiher2003 perfect no problem :) 馃憤
Welp, after getting to work locally I went for it on the production server and I got some more errors looks like with bcrypt... I had to go back again to 2.7.6 again. Anyone know whats going on here?
[Mon Dec 12 19:16:03.948607 2016] [:error] [pid 6703:tid 140571484960512] bcrypt is required to use Flask-Bcrypt
[Mon Dec 12 19:16:03.948722 2016] [:error] [pid 6703:tid 140571484960512] [client 127.0.0.1:46375] mod_wsgi (pid=6703): Target WSGI script '/var/www/peer_flask/peer_flask.wsgi' cannot be loaded as Python module.
[Mon Dec 12 19:16:03.948730 2016] [:error] [pid 6703:tid 140571484960512] [client 127.0.0.1:46375] mod_wsgi (pid=6703): Exception occurred processing WSGI script '/var/www/peer_flask/peer_flask.wsgi'.
[Mon Dec 12 19:16:03.948748 2016] [:error] [pid 6703:tid 140571484960512] [client 127.0.0.1:46375] Traceback (most recent call last):
[Mon Dec 12 19:16:03.948763 2016] [:error] [pid 6703:tid 140571484960512] [client 127.0.0.1:46375] File "/var/www/peer_flask/peer_flask.wsgi", line 28, in
[Mon Dec 12 19:16:03.948814 2016] [:error] [pid 6703:tid 140571484960512] [client 127.0.0.1:46375] from app import app as application
[Mon Dec 12 19:16:03.948822 2016] [:error] [pid 6703:tid 140571484960512] [client 127.0.0.1:46375] File "/var/www/peer_flask/peer_flask/app/__init__.py", line 7, in
[Mon Dec 12 19:16:03.948859 2016] [:error] [pid 6703:tid 140571484960512] [client 127.0.0.1:46375] from flask_bcrypt import Bcrypt
[Mon Dec 12 19:16:03.948866 2016] [:error] [pid 6703:tid 140571484960512] [client 127.0.0.1:46375] File "/var/www/peer_flask/peer_flask/venv/lib/python2.7/site-packages/flask_bcrypt.py", line 27, in
[Mon Dec 12 19:16:03.948928 2016] [:error] [pid 6703:tid 140571484960512] [client 127.0.0.1:46375] raise e
[Mon Dec 12 19:16:03.948943 2016] [:error] [pid 6703:tid 140571484960512] [client 127.0.0.1:46375] ImportError: /var/www/peer_flask/peer_flask/venv/lib/python2.7/site-packages/_cffi_backend.so: undefined symbol: PyUnicodeUCS2_FromUnicode
Please check the steps
env is a old environment based in specific version without ucs2 support, in my case is 2.7.8
$pyenv deactive env
$pyenv uninstall env
$pyenv unistall 2.7.8 # 2.7.8, version without ucs2 support
$PYTHON_CONFIGURE_OPTS="--enable-unicode=ucs2" pyenv install 2.7.8
$pyenv virtualenv 2.7.8 env # creating a new env with ucs2 support
$pyenv activate env
$pyenv versions | grep env # This display env as activated environment
Regards,
Ed
Most helpful comment
Reverting the change to pyenv will get existing built extension modules working again, but won't solve the problem the pyenv change was intended to address: binary compatibility with prebuilt Mac OS X and manylinux1 wheel files published to PyPI.
On Linux, the following command will rebuild all of the modules in an environment (don't run it directly against your system Python!):
For Mac OS X, I don't believe
/dev/stdinexists, sopip freezewill need to be written to a file and passed topip installthat way.