I have a Python 2.7 script using NLTK that runs fine on command prompt. When I ran it in a local Apache server on the same machine, it crashes and the error log shows "NotImplementedError: cannot determine number of cpus" while loading scipy. More detailed messages are shown below. Anyone else have the same problem?
.....
[Thu Aug 09 18:07:50 2018] [error] [client ::1] File "interpnd.pyx", line 1, in init scipy.interpolate.interpnd\r, referer: http://localhost/index.html
[Thu Aug 09 18:07:50 2018] [error] [client ::1] File "C:\Anaconda2\lib\site-packages\scipy\spatial\__init__.py", line 95, in \r, referer: http://localhost/index.html
[Thu Aug 09 18:07:50 2018] [error] [client ::1] from .ckdtree import *\r, referer: http://localhost/index.html
[Thu Aug 09 18:07:50 2018] [error] [client ::1] File "ckdtree.pyx", line 31, in init scipy.spatial.ckdtree\r, referer: http://localhost/index.html
[Thu Aug 09 18:07:50 2018] [error] [client ::1] File "C:\Anaconda2\lib\multiprocessing\__init__.py", line 136, in cpu_count\r, referer: http://localhost/index.html
[Thu Aug 09 18:07:50 2018] [error] [client ::1] raise NotImplementedError('cannot determine number of cpus')\r, referer: http://localhost/index.html
[Thu Aug 09 18:07:50 2018] [error] [client ::1] NotImplementedError: cannot determine number of cpus\r, referer: http://localhost/index.html
Related
I'm trying to deploy a Flask app on Apache using mod_wsgi. Im using a virtual environment. But the below line is failing.
from flask import Flask
Error:
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] mod_wsgi (pid=6937): Target WSGI script '/var/www/sample_rest/sample_rest.wsgi' cannot be loaded as Python module.
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] mod_wsgi (pid=6937): Exception occurred processing WSGI script '/var/www/sample_rest/sample_rest.wsgi'.
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] Traceback (most recent call last):
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] File "/var/www/sample_rest/sample_rest.wsgi", line 5, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] from sample_rest import sample_rest as application
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] File "/var/www/sample_rest/sample_rest.py", line 2, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] from flask import Flask, request, jsonify, make_response
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] File "/var/www/sample_rest/lib/python3.6/site-packages/flask/__init__.py", line 16, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] from werkzeug.exceptions import abort
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] File "/var/www/sample_rest/lib/python3.6/site-packages/werkzeug/__init__.py", line 15, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] from .serving import run_simple
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] File "/var/www/sample_rest/lib/python3.6/site-packages/werkzeug/serving.py", line 51, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] from .exceptions import InternalServerError
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] File "/var/www/sample_rest/lib/python3.6/site-packages/werkzeug/exceptions.py", line 68, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] from .utils import escape
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] File "/var/www/sample_rest/lib/python3.6/site-packages/werkzeug/utils.py", line 189
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] "area",
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] ^
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] SyntaxError: invalid syntax
As you can see the error is within the code of flask itself. I'm using Python-3.6.2 which is supported by flask. The source code of flask in which it's showing error is also correct. What could be the issue ?
Sorry for posting this rather then commenting:
Try to install Flask 1.1.1 which worked for me:
pip install Flask==1.1.1
Here's /home/blakeh/test.py, which doesn't really do anything but illustrate the problem with minimal code:
#!/usr/local/bin/python3
import xmlrpc.client
if __name__ == "__main__":
client = xmlrpc.client.ServerProxy('http://localhost:8010')
client.foo()
If I run this directly as the apache user, there's no permission problem with making the RPC "foo" call. It only occurs if I run it through apache. I'm using python 3.5.2.
In an apache .conf file I have this:
ScriptAlias /test "/home/blakeh/test.py"
If I run this curl command:
curl -gix "" http://localhost/test
... I get an internal server error, with this appended to /var/log/httpd/error_log:
[Wed Jan 04 21:23:09 2017] [error] [client ::1] Traceback (most recent call last):
[Wed Jan 04 21:23:09 2017] [error] [client ::1] File "/home/blakeh/test.py", line 7, in <module>
[Wed Jan 04 21:23:09 2017] [error] [client ::1] client.foo()
[Wed Jan 04 21:23:09 2017] [error] [client ::1] File "/usr/local/lib/python3.5/xmlrpc/client.py", line 1092, in __call__
[Wed Jan 04 21:23:09 2017] [error] [client ::1] return self.__send(self.__name, args)
[Wed Jan 04 21:23:09 2017] [error] [client ::1] File "/usr/local/lib/python3.5/xmlrpc/client.py", line 1432, in __request
[Wed Jan 04 21:23:09 2017] [error] [client ::1] verbose=self.__verbose
[Wed Jan 04 21:23:09 2017] [error] [client ::1] File "/usr/local/lib/python3.5/xmlrpc/client.py", line 1134, in request
[Wed Jan 04 21:23:09 2017] [error] [client ::1] return self.single_request(host, handler, request_body, verbose)
[Wed Jan 04 21:23:09 2017] [error] [client ::1] File "/usr/local/lib/python3.5/xmlrpc/client.py", line 1146, in single_request
[Wed Jan 04 21:23:09 2017] [error] [client ::1] http_conn = self.send_request(host, handler, request_body, verbose)
[Wed Jan 04 21:23:09 2017] [error] [client ::1] File "/usr/local/lib/python3.5/xmlrpc/client.py", line 1259, in send_request
[Wed Jan 04 21:23:09 2017] [error] [client ::1] self.send_content(connection, request_body)
[Wed Jan 04 21:23:09 2017] [error] [client ::1] File "/usr/local/lib/python3.5/xmlrpc/client.py", line 1289, in send_content
[Wed Jan 04 21:23:09 2017] [error] [client ::1] connection.endheaders(request_body)
[Wed Jan 04 21:23:09 2017] [error] [client ::1] File "/usr/local/lib/python3.5/http/client.py", line 1102, in endheaders
[Wed Jan 04 21:23:09 2017] [error] [client ::1] self._send_output(message_body)
[Wed Jan 04 21:23:09 2017] [error] [client ::1] File "/usr/local/lib/python3.5/http/client.py", line 934, in _send_output
[Wed Jan 04 21:23:09 2017] [error] [client ::1] self.send(msg)
[Wed Jan 04 21:23:09 2017] [error] [client ::1] File "/usr/local/lib/python3.5/http/client.py", line 877, in send
[Wed Jan 04 21:23:09 2017] [error] [client ::1] self.connect()
[Wed Jan 04 21:23:09 2017] [error] [client ::1] File "/usr/local/lib/python3.5/http/client.py", line 849, in connect
[Wed Jan 04 21:23:09 2017] [error] [client ::1] (self.host,self.port), self.timeout, self.source_address)
[Wed Jan 04 21:23:09 2017] [error] [client ::1] File "/usr/local/lib/python3.5/socket.py", line 711, in create_connection
[Wed Jan 04 21:23:09 2017] [error] [client ::1] raise err
[Wed Jan 04 21:23:09 2017] [error] [client ::1] File "/usr/local/lib/python3.5/socket.py", line 702, in create_connection
[Wed Jan 04 21:23:09 2017] [error] [client ::1] sock.connect(sa)
[Wed Jan 04 21:23:09 2017] [error] [client ::1] PermissionError: [Errno 13] Permission denied
What could explain the difference in behavior? Thanks!
Velkan's suggestion to check selinux worked. I could get this working by putting it in permissive mode with "setenforce 0". Adding this as an "answer" so I can mark it as solved.
I try to configure mod_wsgi to access odoo thanks my domain name.
I followed this tutorial.
But when I go to my site I get this error :
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] mod_wsgi (pid=30445): Target WSGI script '/opt/odoo-v9-prod/openerp-wsgi.py' cannot be loaded as Python module.
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] mod_wsgi (pid=30445): Exception occurred processing WSGI script '/opt/odoo-v9-prod/openerp-wsgi.py'.
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] Traceback (most recent call last):
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] File "/opt/odoo-v9-prod/openerp-wsgi.py", line 15, in <module>
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] import openerp
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] File "/opt/odoo-v9-prod/openerp/__init__.py", line 58, in <module>
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] import modules
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] File "/opt/odoo-v9-prod/openerp/modules/__init__.py", line 8, in <module>
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] from . import db, graph, loading, migration, module, registry
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] File "/opt/odoo-v9-prod/openerp/modules/graph.py", line 13, in <module>
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] import openerp.osv as osv
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] File "/opt/odoo-v9-prod/openerp/osv/__init__.py", line 4, in <module>
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] import osv
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] File "/opt/odoo-v9-prod/openerp/osv/osv.py", line 4, in <module>
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] from ..exceptions import except_orm
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] File "/opt/odoo-v9-prod/openerp/exceptions.py", line 15, in <module>
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] from lxml import etree
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] ImportError: /usr/local/lib/python2.7.9/lib/python2.7/site-packages/lxml/etree.so: undefined symbol: PyUnicodeUCS2_DecodeLatin1
I test my python encodage and it is UCS2.
I reinstalled lxml.
Your mod_wsgi is compiled for a different Python installation than the Python virtual environment you are trying to force it to use, or the Python shared library it is finding. Worse is that what ever it is using was compiled with different width for Unicode character support. You need to uninstall mod_wsgi and reinstall mod_wsgi from source code and compile it against the specific Python version you do want to use, forcing it to use the correct shared library if necessary. You may also want to consider reinstalling your custom Python version to use a configuration which aligns with what is generally regarded as best practice for the platform. Linux system usually use 4 byte Unicode, not 2.
Some stuff for you to read:
http://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html#python-shared-library
http://blog.dscpl.com.au/2015/06/installing-custom-python-version-into.html
Ignore the fact that the latter talks about Docker, all still relevant to normal Python install as well.
So I have created a flask application in OS from the OS quickstart on github. The app works great on my local system. when i push the app to OS it builds but I get an error 500 in the browser.
Any ideas or assistance would be appreciated.
Here is the source code from the application file:
#!/usr/bin/python import os
virtenv = os.environ['APPDIR'] + '/virtenv/'
os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python2.6/site-packages')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
pass
from run import app as application
Here is the source from the run.py file
from app import app
app.run(debug = True)
Here are the errors from the logs (Stripped the HASH ID for my site):
[Sun Aug 05 15:46:08 2012] [error] * Running on http://127.0.0.1:5000/
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] mod_wsgi (pid=28484): Target WSGI script '/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application' cannot be loaded as Python module.
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] mod_wsgi (pid=28484): Exception occurred processing WSGI script '/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application'.
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] Traceback (most recent call last):
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application", line 13, in <module>
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] from run import app as application
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/run.py", line 2, in <module>
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] app.run(debug = True)
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/ws/virtenv/lib/python2.6/site-packages/Flask-0.9-py2.6.egg/flask/app.py", line 739, in run
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] run_simple(host, port, self, **options)
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/ws/virtenv/lib/python2.6/site-packages/Werkzeug-0.8.3-py2.6.egg/werkzeug/serving.py", line 613, in run_simple
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] test_socket.bind((hostname, port))
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] File "<string>", line 1, in bind
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] error: [Errno 13] Permission denied
[Sun Aug 05 15:46:09 2012] [error] * Running on http://127.0.0.1:5000/
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] mod_wsgi (pid=31302): Target WSGI script '/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application' cannot be loaded as Python module.
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] mod_wsgi (pid=31302): Exception occurred processing WSGI script '/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application'.
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] Traceback (most recent call last):
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application", line 13, in <module>
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] from run import app as application
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/run.py", line 2, in <module>
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] app.run(debug = True)
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/ws/virtenv/lib/python2.6/site-packages/Flask-0.9-py2.6.egg/flask/app.py", line 739, in run
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] run_simple(host, port, self, **options)
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/ws/virtenv/lib/python2.6/site-packages/Werkzeug-0.8.3-py2.6.egg/werkzeug/serving.py", line 613, in run_simple
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] test_socket.bind((hostname, port))
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] File "<string>", line 1, in bind
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] error: [Errno 13] Permission denied
You should not be trying to run the Flask built in development server when hosting under mod_wsgi. Go back and check the mod_wsgi documentation in Flask as to what you are meant to be doing.
http://flask.pocoo.org/docs/deploying/mod_wsgi/
So I have finally figured out what was wrong with my code. I was missing a line in my run.py file so the incorrect file looked like this:
Incorrect file:
from app import app
app.run()
This is the corrected working file:
from app import app
if __name__ == "__main__": #Need this line for Openshift
app.run()
The if statement is apparently needed when deployed to production servers like Apache
Have you checked the following description from flask website at:
http://flask.pocoo.org/docs/deploying/mod_wsgi/#working-with-virtual-environments
Problem: application gives permission errors
Probably caused by your application running as the wrong user. Make sure the folders the application needs access to have the proper
privileges set and the application runs as the correct user (user and
group parameter to the WSGIDaemonProcess directive)
Dear Python/Django expert,
Due to recent server migration, my python-powered django app throws a 500 page. The log file is listed below. Can you please give me some help in diagnosing this problem?
==========================
[haiyang#web aihaiyang]$ tail ~/logs/user/error_django_aihaiyang_log
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] return callback(request, **param_dict), referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] File "/home/haiyang/webapps/django_aihaiyang/lib/python2.5/django/utils/decorators.py", line 93, in _wrapped_view, referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] response = view_func(request, *args, **kwargs), referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] File "/home/haiyang/webapps/django_aihaiyang/lib/python2.5/django/views/defaults.py", line 30, in server_error, referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] t = loader.get_template(template_name) # You need to create a 500.html template., referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] File "/home/haiyang/webapps/django_aihaiyang/lib/python2.5/django/template/loader.py", line 157, in get_template, referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] template, origin = find_template(template_name), referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] File "/home/haiyang/webapps/django_aihaiyang/lib/python2.5/django/template/loader.py", line 138, in find_template, referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] raise TemplateDoesNotExist(name), referer: http://aihaiyang.com/synlex/syntactic/
[Fri Jun 29 17:25:57 2012] [error] [client 127.0.0.1] TemplateDoesNotExist: 500.html, referer: http://aihaiyang.com/synlex/syntactic/
=========================
Thanks,
Haiyang
You need to create a 500.html template and put it in your template_dir
Template does not exist: 500.html