Reportlab can't find _imaging module using production server - python

I'm trying to push a django app to the production server, but for some reason it fails and says:
ImportError: The _imaging C module is not installed
The weird part is that when I use the development server on the same machine, it works just fine. PIL is installed, and I can import the _imaging module by hand in the shell. The production server uses Apache. Any ideas?
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "C:/portal2\compliance\views.py", line 91, in show_statement
doc.build(Story, onFirstPage=firstPage, onLaterPages=otherPage)
File "C:\Python27\lib\site-packages\reportlab\platypus\doctemplate.py", line 1117, in build
BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
File "C:\Python27\lib\site-packages\reportlab\platypus\doctemplate.py", line 877, in build
self.clean_hanging()
File "C:\Python27\lib\site-packages\reportlab\platypus\doctemplate.py", line 510, in clean_hanging
self.handle_flowable(self._hanging)
File "C:\Python27\lib\site-packages\reportlab\platypus\doctemplate.py", line 757, in handle_flowable
f.apply(self)
File "C:\Python27\lib\site-packages\reportlab\platypus\doctemplate.py", line 140, in apply
getattr(doc,arn)(*args)
File "C:\Python27\lib\site-packages\reportlab\platypus\doctemplate.py", line 1093, in handle_pageBegin
self._handle_pageBegin()
File "C:\Python27\lib\site-packages\reportlab\platypus\doctemplate.py", line 535, in handle_pageBegin
self.pageTemplate.onPage(self.canv,self)
File "C:/portal2\compliance\views.py", line 55, in firstPage
canvas.drawImage(img,0,0,8.5*inch,11*inch)
File "C:\Python27\lib\site-packages\reportlab\pdfgen\canvas.py", line 857, in drawImage
imgObj = pdfdoc.PDFImageXObject(name, image, mask=mask)
File "C:\Python27\lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 2094, in init
self.loadImageFromA85(src)
File "C:\Python27\lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 2100, in loadImageFromA85
imagedata = map(string.strip,pdfutils.makeA85Image(source,IMG=IMG))
File "C:\Python27\lib\site-packages\reportlab\pdfbase\pdfutils.py", line 34, in makeA85Image
raw = img.getRGBData()
File "C:\Python27\lib\site-packages\reportlab\lib\utils.py", line 658, in getRGBData
annotateException('\nidentity=%s'%self.identity())
File "C:\Python27\lib\site-packages\reportlab\lib\utils.py", line 655, in getRGBData
self._data = im.tostring()
File "C:\Python27\lib\site-packages\PIL\Image.py", line 532, in tostring
self.load()
File "C:\Python27\lib\site-packages\PIL\ImageFile.py", line 164, in load
self.load_prepare()
File "C:\Python27\lib\site-packages\PIL\ImageFile.py", line 231, in load_prepare
self.im = Image.core.new(self.mode, self.size)
File "C:\Python27\lib\site-packages\PIL\Image.py", line 37, in getattr
raise ImportError("The _imaging C module is not installed")
ImportError: The _imaging C module is not installed
identity=[ImageReader#0x4517a30 filename='C:\portal2\pdf\Certification_fullframe.tif']
handle_pageBegin args=()

PIL should be installed before library which uses it. I got similar problem with libimaging - PIL wasn't installed before libimaging so libimaging was compiled without it. Solution was uninstall libimaging and install it again with PIL already present in system.

Found the answer!
Trouble using PIL in Django app on Windows
I had to install a version of PIL that was precompiled to work with mod-wsgi.

Related

I can't install pip packages and I get traceback error

pip install clipboard
ERROR: Exception:
Traceback (most recent call last):
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_internal\cli\base_command.py", line 167, in exc_logging_wrapper
status = run_func(*args)
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_internal\cli\req_command.py", line 205, in wrapper
return func(self, options, args)
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_internal\commands\install.py", line 287, in run
session = self.get_default_session(options)
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_internal\cli\req_command.py", line 75, in get_default_session
self._session = self.enter_context(self._build_session(options))
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_internal\cli\req_command.py", line 89, in _build_session
session = PipSession(
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_internal\network\session.py", line 282, in __init__
self.headers["User-Agent"] = user_agent()
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_internal\network\session.py", line 157, in user_agent
setuptools_dist = get_default_environment().get_distribution("setuptools")
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_internal\metadata\__init__.py", line 75, in get_default_environment
return select_backend().Environment.default()
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_internal\metadata\__init__.py", line 63, in select_backend
from . import pkg_resources
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_internal\metadata\pkg_resources.py", line 8, in <module>
from pip._vendor import pkg_resources
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3252, in <module>
def _initialize_master_working_set():
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3235, in _call_aside
f(*args, **kwargs)
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3277, in _initialize_master_working_set
tuple(
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3278, in <genexpr>
dist.activate(replace=False)
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2785, in activate
declare_namespace(pkg)
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2284, in declare_namespace
_handle_ns(packageName, path_item)
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2217, in _handle_ns
loader.load_module(packageName)
File "C:\Users\amin_\AppData\Roaming\Python\Python310\site-packages\pygoogle\google.py", line 113
print """PyGoogle %(__version__)s
^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
WARNING: There was an error checking the latest version of pip.
I suggest you can use pyperclip as it is the same a s clipboard and it is newer.
https://pypi.org/project/pyperclip/
import pyperclip
>>> pyperclip.copy('The text to be copied to the clipboard.')
>>> pyperclip.paste()
'The text to be copied to the clipboard.'
Currently only handles plaintext.
On Windows, no additional modules are needed.
On Mac, this module makes use of the pbcopy and pbpaste commands, which should come with the os.
On Linux, this module makes use of the xclip or xsel commands, which should come with the os. Otherwise run “sudo apt-get install xclip” or “sudo apt-get install xsel” (Note: xsel does not always seem to work.)
Otherwise on Linux, you will need the gtk or PyQt4 modules installed.
I hope this help. :)

PRAW induced SSL error when compiling Python script using py2exe

Python 2.7.11
Requests 2.9.1
Praw 3.4.0
I have a python script that uses PRAW (reddit API wrapper), I'm attempting to compile it into an .exe using py2exe.
Here is the current error that occurs when the .exe is run:
Traceback (most recent call last):
File "MYSCRIPTNAME.py", line 263, in <module>
File "<decorator-gen-51>", line 2, in login
File "praw\decorators.pyc", line 78, in wrap
File "praw\__init__.pyc", line 1455, in login
File "<decorator-gen-8>", line 2, in request_json
File "praw\decorators.pyc", line 116, in raise_api_exceptions
File "praw\__init__.pyc", line 620, in request_json
File "praw\__init__.pyc", line 451, in _request
File "praw\__init__.pyc", line 432, in handle_redirect
File "praw\handlers.pyc", line 146, in wrapped
File "praw\handlers.pyc", line 56, in wrapped
File "praw\handlers.pyc", line 102, in request
File "requests\sessions.pyc", line 576, in send
File "requests\adapters.pyc", line 447, in send
requests.exceptions.SSLError: [Errno 2] No such file or directory
Line 263 is r.login(user,pw) (r is r = praw.Reddit(userAgent))
Searching for other SSL issues on here and other places discussed adding cacert.pem. I tried this without resolution.

BeautifulSoup4 in Sagemath

I'm trying to perform web scraping with BS4 and then do some algebra work with the results in Sage 6.2 (in Lion 10.7.5). I assumed that /Applications/Sage-6.2.app/Contents/Resources/sage/sage -i beautifulsoup4 would work, but the result is
Attempting to download package beautifulsoup4
>>> Checking online list of optional packages.
[Traceback (most recent call last):
File "<stdin>", line 35, in <module>
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 240, in retrieve
fp = self.open(url, data)
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 208, in open
return getattr(self, name)(url)
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 359, in open_http
return self.http_error(url, fp, errcode, errmsg, headers)
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 376, in http_error
return self.http_error_default(url, fp, errcode, errmsg, headers)
File "<stdin>", line 17, in http_error_default
IOError: [Errno 404] Not Found: '//www.sagemath.org/spkg/optional/list'
Error: failed to download http://www.sagemath.org/spkg/optional/list, aborting
Next, I tried /Applications/Sage-6.2.app/Contents/Resources/sage/sage -sh <<< "easy_install --verbose pip" to get bs4 via pip. That succeeded; however /Applications/Sage-6.2.app/Contents/Resources/sage/local/bin/pip2.7 install beautifulsoup4 failed with error message
Traceback (most recent call last):
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 548, in <module>
main()
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 231, in getuserbase
USER_BASE = get_config_var('userbase')
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sysconfig.py", line 516, in get_config_var
return get_config_vars().get(name)
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sysconfig.py", line 449, in get_config_vars
import re
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/re.py", line 105, in <module>
import sre_compile
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sre_compile.py", line 14, in <module>
import sre_parse
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sre_parse.py", line 17, in <module>
from sre_constants import *
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
Next, I tried upgrading to Sage 6.6. That went smoothly, as did the installation of bs4. However, when I opened the notebook, I was unable to run code cells, because the "Shift-Enter" command only registered as "Enter" and gave me a new line instead of evaluating the code. Additionally, there was no "evaluate" button. Any recommendations to solve any of these issues would be greatly appreciated.
Unfortunately, Sage has changed how it handles optional packages like BS so that older versions may not be able to use them. You can always go to a mirror, though, like http://mirrors.mit.edu/sage/spkg/optional/ download it, and put it in your (old Sage's) optional spkg directory and try doing sage -i path/to/file.
As to the notebook issue, that should be a matter of doing a "hard cache reset" in the browser due to different jQuery versions, see e.g. here.

AWS ec2 winreg not found

I'm trying to run a python app from amazon EC2 large instance. However, Its complaining in scipy because it can't find a thing called _winreg.
I don't know how to reconfigure this so its no longer an issue.
$ python2 app.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
Traceback (most recent call last):
File "app.py", line 111, in <module> app = create_app().run(debug=True)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 772, in run run_simple(host, port, self, **options)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 622, in run_simple reloader_type)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/_reloader.py", line 265, in run_with_reloader reloader.run()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/_reloader.py", line 155, in run for filename in chain(_iter_module_files(), self.extra_files):
File "/usr/local/lib/python2.7/dist-packages/werkzeug/_reloader.py", line 70, in _iter_module_files for package_path in getattr(module, '__path__', ()):
File "/usr/lib/python2.7/dist-packages/scipy/lib/six.py", line 116, in __getattr__ _module = self._resolve()
File "/usr/lib/python2.7/dist-packages/scipy/lib/six.py", line 105, in _resolve return _import_module(self.mod)
File "/usr/lib/python2.7/dist-packages/scipy/lib/six.py", line 76, in _import_module __import__(name) ImportError: No module named _winreg """
Check out the comments on the answer of this post.
I'm guessing by using the watchdog module it doesn't import "stat" which seems to look for this _winreg package.
In other words, installing the module "watchdog" seems to do the trick.

Installing pymongo on a nitrous.io box

I'm fairly new to Python, and Nitrous.IO, and MongoDB, and command line in general so would appreciate a little guidance here if possible.
I'm trying to install pymongo on my Nitrous.IO box but can't seem to find a way to do it - this tutorial suggests 'import pymongo' but that didn't work (see below).
I can't seem to find any tutorials or help on this - a google search for "install +pymongo with nitrous.io" gave me 0 results.
action#thirdyearproject-148753:~(master*)$ import pymongo
import: unable to open X server `' # error/import.c/ImportImageCommand/366.
action#thirdyearproject-148753:~(master*)$ pip install pymongo
Traceback (most recent call last):
File "/home/action/.parts/bin/pip", line 9, in <module>
load_entry_point('pip==1.5.4', 'console_scripts', 'pip')()
File "/home/action/.parts/packages/python2/2.7.6/lib/python2.7/site-packages/pkg_resources.py", line 356, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/home/action/.parts/packages/python2/2.7.6/lib/python2.7/site-packages/pkg_resources.py", line 2431, in load_entry_point
return ep.load()
File "/home/action/.parts/packages/python2/2.7.6/lib/python2.7/site-packages/pkg_resources.py", line 2147, in load
['__name__'])
File "/home/action/.parts/packages/python2/2.7.6/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg/pip/__init__.py", line 10, in <modul
from pip.util import get_installed_distributions, get_prog
File "/home/action/.parts/packages/python2/2.7.6/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg/pip/util.py", line 15, in <module>
from pip.locations import site_packages, running_under_virtualenv, virtualenv_no_global
File "/home/action/.parts/packages/python2/2.7.6/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg/pip/locations.py", line 96, in <modu
build_prefix = _get_build_prefix()
File "/home/action/.parts/packages/python2/2.7.6/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg/pip/locations.py", line 64, in _get_
path = os.path.join(tempfile.gettempdir(), 'pip_build_%s' %
File "/home/action/.parts/packages/python2/2.7.6/lib/python2.7/tempfile.py", line 269, in gettempdir
tempdir = _get_default_tempdir()
File "/home/action/.parts/packages/python2/2.7.6/lib/python2.7/tempfile.py", line 212, in _get_default_tempdir
("No usable temporary directory found in %s" % dirlist))
IOError: [Errno 2] No usable temporary directory found in ['/tmp', '/var/tmp', '/usr/tmp', '/home/action']
action#thirdyearproject-148753:~(master*)$ easy_install pymongo
Traceback (most recent call last):
File "/home/action/.parts/bin/easy_install", line 5, in <module>
from pkg_resources import load_entry_point
File "/home/action/.parts/packages/python2/2.7.6/lib/python2.7/site-packages/pkg_resources.py", line 2829, in <module>
working_set = WorkingSet._build_master()
File "/home/action/.parts/packages/python2/2.7.6/lib/python2.7/site-packages/pkg_resources.py", line 451, in _build_master
return cls._build_from_requirements(__requires__)
File "/home/action/.parts/packages/python2/2.7.6/lib/python2.7/site-packages/pkg_resources.py", line 464, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/home/action/.parts/packages/python2/2.7.6/lib/python2.7/site-packages/pkg_resources.py", line 639, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: setuptools==2.2
action#thirdyearproject-148753:~(master*)$ parts install pymongo
parts: ERROR: Package "pymongo" not found
Aborting!
Does anyone know how I would go about installing this? It's starting to be a real pain!
You might be able to install it withpip using this advice. Once you've done that, you would use the import pymongo at the top of your code file.

Categories

Resources