I tried to use djangos i18n and therefor had to install gettext. Now I'm getting this awkward error any time I try to start my application:
Traceback (most recent call last):
File "/var/www/mydjangoproject/manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/core/management/__init__.py", line 4, in <module>
from optparse import OptionParser, NO_DEFAULT
File "/usr/lib/python2.7/optparse.py", line 418, in <module>
_builtin_cvt = { "int" : (_parse_int, _("integer")),
File "/usr/lib/python2.7/gettext.py", line 581, in gettext
return dgettext(_current_domain, message)
File "/usr/lib/python2.7/gettext.py", line 545, in dgettext
codeset=_localecodesets.get(domain))
File "/usr/lib/python2.7/gettext.py", line 480, in translation
mofiles = find(domain, localedir, languages, all=1)
File "/usr/lib/python2.7/gettext.py", line 437, in find
for nelang in _expand_lang(lang):
File "/usr/lib/python2.7/gettext.py", line 131, in _expand_lang
from locale import normalize
ImportError: cannot import name normalize
The library locale.py is present and I can import it. Django 1.4 is running under Python 2.7.2+. Any Ideas?
I guess you have somewhere inside your project a folder locale with an __init__.py file in it.
Delete this file (you don't need it for translation to work) and you should be good to go.
Related
When I execute the following statement in my code on my Mac OS X
import json, nltk, requests, time, smtplib, uuid
I have the followiong error:
18/01/22 22:03:15 INFO TaskSetManager: Lost task 235.0 in stage 4.0 (TID 16) on executor localhost: org.apache.spark.api.python.PythonException (Traceback (most recent call last):
File "/usr/local/spark/python/lib/pyspark.zip/pyspark/worker.py", line 98, in main
command = pickleSer._read_with_length(infile)
File "/usr/local/spark/python/lib/pyspark.zip/pyspark/serializers.py", line 164, in _read_with_length
return self.loads(obj)
File "/usr/local/spark/python/lib/pyspark.zip/pyspark/serializers.py", line 422, in loads
return pickle.loads(obj)
File "utils.py", line 6, in <module>
import json, nltk, requests, time, smtplib, uuid
File "/Library/Python/2.7/site-packages/nltk/__init__.py", line 114, in <module>
from nltk.collocations import *
File "/Library/Python/2.7/site-packages/nltk/collocations.py", line 39, in <module>
from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures
File "/Library/Python/2.7/site-packages/nltk/metrics/__init__.py", line 16, in <module>
from nltk.metrics.scores import (accuracy, precision, recall, f_measure,
File "/Library/Python/2.7/site-packages/nltk/metrics/scores.py", line 16, in <module>
from scipy.stats.stats import betai
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/stats/__init__.py", line 324, in <module>
from .stats import *
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/stats/stats.py", line 242, in <module>
import scipy.special as special
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/special/__init__.py", line 531, in <module>
from ._ufuncs import *
File "numpy.pxd", line 155, in init scipy.special._ufuncs (scipy/special/_ufuncs.c:19983)
ValueError: numpy.dtype has the wrong size, try recompiling
As you can see from log, I'm using python 2,7 and pyspark (spark 1.6).
Maybe the problem is related to the fact that the software tries to use OSX system Python that use a specific version of numpy and I'm not able to understand how can avoid this.
Anyone can help me?
At this link: ValueError: numpy.dtype has the wrong size, try recompiling
the problem is related to the binary distribution of packages that are compiled against a recent version of numpy.
In my case it seems that spark refer the OSX system python ("/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/stats/stats.py") instead of the "/Library/Python/2.7" i'm using in my virtual env.
I have a small python (2.7) script that works with several threads. One of the threads will read a global list and post an https post request for each one of the entries of this list.
For doing that I saw that the best way is to use python requests module. I have installed it with pip (no problem with that, it is placed in ...Python/2.7/site-packages/requests/...), but, when I import this module in my script, I get an error.
I have created another script with just one line (import requests) to reproduce the error, and I get this:
Traceback (most recent call last):
File "req.py", line 1, in <module>
import requests
File "/Library/Python/2.7/site-packages/requests/__init__.py", line 43, in <module>
import urllib3
File "/Library/Python/2.7/site-packages/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/Library/Python/2.7/site-packages/urllib3/connectionpool.py", line 11, in <module>
from .exceptions import (
File "/Library/Python/2.7/site-packages/urllib3/exceptions.py", line 2, in <module>
from .packages.six.moves.http_client import (
File "/Library/Python/2.7/site-packages/urllib3/packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/Library/Python/2.7/site-packages/urllib3/packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/Library/Python/2.7/site-packages/urllib3/packages/six.py", line 82, in _import_module
__import__(name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 69, in <module>
from array import array
File "/Users/carlestalenssebastia/Documents/mychip/raspberry pi/array.py", line 3, in <module>
IndexError: list index out of range
Python 2.7.10
MacBook Pro with macOS Sierra (v 10.12)
Am I doing something wrong? Didn't I installed the module in the proper way?
it seems that you're having two modules with the same name array.py
rename your local array.py module to something more unique to resolve this.
take a look at this answer for more info on how to handle this issue and here to learn more on how python import system works.
I have following file structure:
/usr/share/pyshared/orca/scripts/toolkits/Gecko/script.py
In this file def getExtents is function that I have to access in following file i.e:
/usr/share/pyshared/orca/scripts/default.py
so I am trying to import function from script.py to the following file:
/usr/share/pyshared/orca/scripts/default.py
following line is added in /usr/share/pyshared/orca/scripts/default.py:
from orca.scripts.toolkits.Gecko.script import getExtents
But I get following errors:
File "<string>", line 1, in <module>
File "/usr/lib/pymodules/python2.7/orca/orca.py", line 1498, in main
init(pyatspi.Registry)
File "/usr/lib/pymodules/python2.7/orca/orca.py", line 1215, in init
loadUserSettings()
File "/usr/lib/pymodules/python2.7/orca/orca.py", line 837, in loadUserSettings
_scriptManager.activate()
File "/usr/lib/pymodules/python2.7/orca/script_manager.py", line 80, in activate
self.setActiveScript(self.getScript(None), "activate")
File "/usr/lib/pymodules/python2.7/orca/script_manager.py", line 247, in getScript
appScript = self.getDefaultScript()
File "/usr/lib/pymodules/python2.7/orca/script_manager.py", line 214, in getDefaultScript
import scripts.default as default
File "/usr/lib/pymodules/python2.7/orca/scripts/default.py", line 57, in <module>
from orca.scripts.toolkits.Gecko.script import getExtents
File "/usr/lib/pymodules/python2.7/orca/scripts/toolkits/Gecko/__init__.py", line 1, in <module>
from script import Script
File "/usr/lib/pymodules/python2.7/orca/scripts/toolkits/Gecko/script.py", line 52, in <module>
import orca.scripts.default as default
AttributeError: 'module' object has no attribute 'default'
I think you probably need
from orca.scripts import default
Also, as mentioned in the comments, check you've got the relevant __init__.py
edit: re-reading the stacktrace, looks like you've got a circular import too, you're trying to import orca.scripts.default in line 52 of "/usr/lib/pymodules/python2.7/orca/scripts/toolkits/Gecko/script.py"
Has anyone else encountered the situation where they have written unit tests for their code into a file named unittest.py, and found it to conflict with NumPy's unittest.py module? In other words, if I write this to unittest.py in a local directory:
if __name__ == "__main__":
print "pre-import"
#import numpy
print "post-import"
Then (no surprises here):
% python unittest.py
pre-import
post-import
But if I do:
if __name__ == "__main__":
print "pre-import"
import numpy
print "post-import"
I get:
% python unittest.py
pre-import
Traceback (most recent call last):
File "unittest.py", line 3, in <module>
import numpy
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/core/__init__.py", line 40, in <module>
from numpy.testing import Tester
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/testing/__init__.py", line 8, in <module>
from unittest import TestCase
ImportError: cannot import name TestCase
Subsequently, iPython fails to load:
% ipython
WARNING: IPython History requires SQLite, your history will not be saved
Traceback (most recent call last):
File "/home/jbbrown/local_bin/python/bin/ipython", line 7, in <module>
launch_new_instance()
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py", line 402, in launch_new_instance
app.initialize()
File "<string>", line 2, in initialize
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/config/application.py", line 84, in catch_config_error
return method(app, *args, **kwargs)
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py", line 312, in initialize
self.init_shell()
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py", line 332, in init_shell
ipython_dir=self.ipython_dir)
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/config/configurable.py", line 318, in instance
inst = cls(*args, **kwargs)
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/frontend/terminal/interactiveshell.py", line 183, in __init__
user_module=user_module, custom_exceptions=custom_exceptions
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 478, in __init__
self.init_reload_doctest()
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 662, in init_reload_doctest
doctest_reload()
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/IPython/utils/doctestreload.py", line 72, in doctest_reload
import doctest
File "/home/jbbrown/local_bin/python/lib/python2.7/doctest.py", line 2118, in <module>
class DocTestCase(unittest.TestCase):
AttributeError: 'module' object has no attribute 'TestCase'
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev#scipy.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
c.Application.verbose_crash=True
Interestingly, if I move the import statement outside of the "if __name__" suite, e.g.,
print "pre-import"
import numpy
print "post-import"
if __name__ == "__main__":
pass
I get:
% python unittest.py
pre-import
pre-import
post-import
Traceback (most recent call last):
File "unittest.py", line 2, in <module>
import numpy
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/core/__init__.py", line 40, in <module>
from numpy.testing import Tester
File "/home/jbbrown/local_bin/python/lib/python2.7/site-packages/numpy/testing/__init__.py", line 8, in <module>
from unittest import TestCase
ImportError: cannot import name TestCase
Of course it is trivial to change the name of the file containing my unit tests and avoid this, but I wonder if anyone else encountered this and thought of an elegant workaround that doesn't include renaming their unit test file?
You can switch to absolute imports by default on Python versions newer than 2.7:
from __future__ import absolute_import
if __name__ == "__main__":
print "pre-import"
import numpy
print "post-import"
Can anyone help me get rid of these warnings in Django please?
/usr/lib/python2.6/site-packages/simplejson-2.1.5-py2.6-linux-x86_64.egg/simplejson/_speedups.py:3: UserWarning: Module taggit was already imported from /var/www/html/matilah/taggit/__init__.py, but /usr/lib/python2.6/site-packages/django_taggit-0.9.3-py2.6.egg is being added to sys.path
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/lib/python2.6/site-packages/haystack/__init__.py", line 154, in <module>
handle_registrations()
File "/usr/lib/python2.6/site-packages/haystack/__init__.py", line 151, in handle_registrations
search_sites_conf = importlib.import_module(settings.HAYSTACK_SITECONF)
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/var/www/html/matilah/search_sites.py", line 2, in <module>
haystack.autodiscover()
File "/usr/lib/python2.6/site-packages/haystack/__init__.py", line 106, in autodiscover
app_path = importlib.import_module(app).__path__
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/var/www/html/matilah/disqus/__init__.py", line 5, in <module>
from django.utils import simplejson as json
File "/usr/lib/python2.6/site-packages/django/utils/simplejson/__init__.py", line 111, in <module>
import simplejson
File "/usr/lib/python2.6/site-packages/simplejson-2.1.5-py2.6-linux-x86_64.egg/simplejson/__init__.py", line 111, in <module>
File "/usr/lib/python2.6/site-packages/simplejson-2.1.5-py2.6-linux-x86_64.egg/simplejson/decoder.py", line 7, in <module>
File "/usr/lib/python2.6/site-packages/simplejson-2.1.5-py2.6-linux-x86_64.egg/simplejson/scanner.py", line 10, in <module>
File "/usr/lib/python2.6/site-packages/simplejson-2.1.5-py2.6-linux-x86_64.egg/simplejson/scanner.py", line 6, in _import_c_make_scanner
File "/usr/lib/python2.6/site-packages/simplejson-2.1.5-py2.6-linux-x86_64.egg/simplejson/_speedups.py", line 7, in <module>
File "/usr/lib/python2.6/site-packages/simplejson-2.1.5-py2.6-linux-x86_64.egg/simplejson/_speedups.py", line 4, in __bootstrap__
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 841, in resource_filename
self, resource_name
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 1310, in get_resource_filename
self._extract_resource(manager, self._eager_to_zip(name))
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 1332, in _extract_resource
self.egg_name, self._parts(zip_path)
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 921, in get_cache_path
self.extraction_error()
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 887, in extraction_error
raise err
pkg_resources.ExtractionError: Can't extract file(s) to egg cache
The following error occurred while trying to extract file(s) to the Python egg
cache:
[Errno 13] Permission denied: '/home/interworx/.python-eggs'
The Python egg cache directory is currently set to:
/home/interworx/.python-eggs
Perhaps your account does not have write access to this directory? You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.
I'm not sure if the "Module was already imported" error has to do with the "cannot extract PYTHON EGG" error.
In my WSGI I already have the following line os.environ['PYTHON_EGG_CACHE'] = rel('python-eggs') and I know for sure that works. Otherwise WSGI won't load my app. So I'm not sure what to do here.
Thanks!
When you get a message like "Perhaps your account does not have write access to this directory?" it's best to do a quick test. Try changing it to "/tmp" (which is writable by everyone) and see if things start working. If that fixes it, you can then identify a more appropriate directory and make sure that you (or the server) have write access to it.
Update: You are correct in choosing to tackle the earliest error message first. Here is a quick utility, Python Module Dump, that I wrote a few years ago for tracking down a mis-included module error. You might try inserting it at interesting points along your initialization code path and see if you can spot when the earlier import occurred.
There's a chance that your initial problem "Module was already imported" does in fact have to do with the permissions error you have going. Your best option would be to fix the permissions/ownership settings on the /home/interworx/.python-eggs directory (as stated by Peter Rowell above).
I came across this great little refresher on permissions today at the Google Code University. Wouldn't hurt to skim through this when you have some time: http://code.google.com/edu/tools101/linux/ownership_permissions.html
Just read the comments above here is my thoughts:
I think the problem is that the .wsgi file is not setting the environment variable in time. Can you please post your .wsgi file? Also, how are you grabbing the packages? Is it a script? Manually via pip?