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"
Related
I am trying to learn Python and following along some modules. I am using Anaconda Powershell Prompt and using Python 3.7 from there. I am trying to follow along via the code below.
Everything works until I get to the line
from wrf import getvar
When I do that line I receive this
>>> from wrf import getvar
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Paul\anaconda3\lib\site-packages\wrf\__init__.py", line 6, in <module>
from . import api
File "C:\Users\Paul\anaconda3\lib\site-packages\wrf\api.py", line 1, in <module>
from .config import (xarray_enabled, disable_xarray, enable_xarray,
File "C:\Users\Paul\anaconda3\lib\site-packages\wrf\config.py", line 62, in <module>
_init_local()
File "C:\Users\Paul\anaconda3\lib\site-packages\wrf\config.py", line 52, in _init_local
_try_enable_xarray()
File "C:\Users\Paul\anaconda3\lib\site-packages\wrf\config.py", line 17, in _try_enable_xarray
from xarray import DataArray
File "C:\Users\Paul\anaconda3\lib\site-packages\xarray\__init__.py", line 1, in <module>
from . import testing, tutorial
File "C:\Users\Paul\anaconda3\lib\site-packages\xarray\testing.py", line 9, in <module>
from xarray.core import duck_array_ops, formatting, utils
File "C:\Users\Paul\anaconda3\lib\site-packages\xarray\core\duck_array_ops.py", line 26, in <module>
from . import dask_array_compat, dask_array_ops, dtypes, npcompat, nputils
File "C:\Users\Paul\anaconda3\lib\site-packages\xarray\core\npcompat.py", line 72, in <module>
_SupportsDType[np.dtype],
File "C:\Users\Paul\anaconda3\lib\typing.py", line 275, in inner
return func(*args, **kwds)
File "C:\Users\Paul\anaconda3\lib\typing.py", line 999, in __class_getitem__
_check_generic(cls, params, len(cls.__parameters__))
File "C:\Users\Paul\anaconda3\lib\typing.py", line 209, in _check_generic
raise TypeError(f"{cls} is not a generic class")
TypeError: <class 'numpy.typing._dtype_like._SupportsDType'> is not a generic class
Looks like the last few lines return an error but as a beginner I have zero clue what this means.
This looks like a similar error to <class 'numpy.typing._dtype_like._SupportsDType'> is not a generic class when importing the plotly.express library - an incompatibility between wrf-python and numpy.
Try upgrading those libraries to the latest versions.
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 am getting an exception from scipy whenever I try to import the nltk package. The command and the error looks like this:
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/__init__.py", line 114, in <module>
from nltk.collocations import *
File "/usr/local/lib/python2.7/dist-packages/nltk/collocations.py", line 39, in <module>
from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures
File "/usr/local/lib/python2.7/dist-packages/nltk/metrics/__init__.py", line 16, in <module>
from nltk.metrics.scores import (accuracy, precision, recall, f_measure,
File "/usr/local/lib/python2.7/dist-packages/nltk/metrics/scores.py", line 16, in <module>
from scipy.stats.stats import betai
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/__init__.py", line 344, in <module>
from .stats import *
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/stats.py", line 176, in <module>
from . import distributions
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/distributions.py", line 10, in <module>
from ._distn_infrastructure import (entropy, rv_discrete, rv_continuous,
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/_distn_infrastructure.py", line 43, in <module>
from new import instancemethod
File "new.py", line 107
return copy.deepcopy(self)
^
IndentationError: expected an indented block
I executed this command in a terminal (ubuntu 16.04 LTS system). I did not find anything about this error and the indentation doesn't look wrong.
The SyntaxError is in your file new.py (I guess it's in your current working directory). Try to switch to a directory where no new.py file is present (or move the new.py file in another directory), then the internal scipy import should work without problems.
On the other hand you can just upgrade to scipy 0.19.x. They removed the import there and it should work without problems.
Note that it's always a bad idea to name python files like builtin-modules! That's a common source for exceptions or unexpected behaviour.
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.
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"