ImportError: No module named anorm - python

I got the below shown error. Can anyone please help me with a solution?
from common import anorm, getsize
Exception:
Traceback (most recent call last): File "<pyshell#10>", line 1, in <module>
from common import anorm, getsize
ImportError: cannot import name anorm

Sorry for necroposting, but for anyone who's stuck on this:
apparently, you're trying to run the opencv example somewhat like this one. You need to copy the common.py from the same directory as well and everything would be fine (no need to install common package which has nothing to do with this partucular problem).

The common module does not contain an importable item named anorm. Simple as that.
Some possible reasons why:
The common module was not installed correctly.
Misspelling of the name of the item to be imported.
A file named common.py exists in the current directory, which takes precedence over the real common module (wherever it is).
Circular imports (which don't appear to be the case here, given the error traceback).

Related

DLL load failed, module not found?

I have a folder with a file "main.py" and a file "_test.pyd" (note .pyd). The file "main.py" looks like this:
import _test
I get the following error:
Traceback (most recent call last):
File "main.py", line 1, in <module>
import _test
ImportError: DLL load failed while importing _test: The specified module could not be found.
Why is this error coming up? Cheers.
Note: I was given this code by others, and it works for the original authors, so I'm not sure what's wrong with me/my machine.
Update: Running os.path.isfile('_test.pyd') returns True, so I don't think it's a problem with the path
You should append the path of the folder which contains the imported module before import.
Code:
import os
import sys
sys.path.append(os.path.realpath(os.path.dirname(__file__)))
import _test # noqa: E402
EDIT:
Other ideas:
Adding __init__.py file to the related director.
Checking the PyInit_foo() function in .pyd file.
If the Python finds the .pyd file, it will attempt to call PyInit_foo() to initialize it
Update Following posts from people experiencing similar issues, I tried downgrading my Python version (from 3.8.4rc1 to 3.5.4) and the import now works correctly. No clue why. I guess the .pyd file was written in that version of Python (I'm not the author of the file), but still I'm clueless as to what the exact origin of the problem is.
I've been through this error and what I found after a lot of investigation:-
issue was in Opencv==4.5.1 build from source with cuda and flag cuda_with_fast_math=on
I just rebuild OpenCV and disable
cuda_with_fast_math
and it works for me.

pybedtools: ImportError: cannot import name scripts

I am trying to import Pybedtools in Spyder.
from pybedtools import BedTool
This is the error I am getting:
Traceback (most recent call last):
File "<ipython-input-13-7a8ea5d1dea8>", line 1, in <module>
from pybedtools import BedTool
File "/Users/michaelsmith/anaconda2/lib/python2.7/site-packages/pybedtools/__init__.py", line 9, in <module>
from . import scripts
ImportError: cannot import name scripts
I just downloaded Anaconda and there doesn't seem to be a reason as to why this happens. What is the typical protocol for resolving bugs like this?
UPDATE:
So within my pybedtools folder there is a scripts folder (which is presumably the module we're trying to import). I changed both the command within __init__.py to:
from . import scripts2
and changed the name of the folder to scripts2 as well. However, I still get the error as such:
ImportError: cannot import name scripts2
So I must be doing something wrong here, which module should I be renaming exactly? Sorry if this is a silly question, I am quite new to python.
This is caused because Anaconda has a module named scripts and therefore your import is "shadowed" by that module. You can double check that when you call import scripts in a new notebook it works even if you have never defined such a module. A very good explanation of import traps can be found here:
http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html
A workaround would be to rename the script module of pybedtools to something else and also change all the imports to the new name.

Couldn't find cython libraries

I found the following problem in executing my python function:
Traceback (most recent call last):
File "/home/ppd/myfunc.py", line 2, in <module>
from cythonUtilsPy.cythonUtils import *
ImportError: No module named cythonUtils
How to add this cythonUtils module to my path?
Based on the error message, it looks like cythonUtilsPy is already on your path and was found, but the submodule cythonUtilsPy.cythonUtils was not found. Unless you are importing the wrong cythonUtilsPy, there is no path manipulation you can do to fix this.
You need to track down why cythonUtils is not showing up as a submodule of cythonUtilsPy, if cythonUtils is a directory perhaps it is missing an __init__.py.

Bizarre inconsistent python ImportError - possible circular dependency?

I'm trying to refactor some python code and I'm stuck with an import error I don't understand. I suspect there might be a circular dependency somewhere but I don't see it, and I'm not getting much in the way of hints from the error messages. The codebase is large, but there are two modules of interest here:
radian/models.py defines a class called ACount
datalayer/radian.py has the following line in it:
from radian.models import ACount
When I run the code (either interactively or from the main program) the imports fail in a way that doesn't make sense to me.
>>> from radian.models import ACount
>>> import datalayer.radian
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/leopd/dev/dbproj/datalayer/radian.py", line 10, in <module>
from radian.models import ACount
ImportError: No module named models
My best guess is that there's a circular dependency somewhere -- that radian is importing something that imports datalayer. But I don't see it. And the error message doesn't make any sense to me. Any ideas what's going on?
-- UPDATE --
I'm using python 2.6.1 on Mac. The __init__.py files have some code in them, but they only import from standard python packages.
Any module in the datalayer folder (including radian.py), when it sees from radian, will assume that datalayer/radian.py is the relevant module. You might need to do
from __future__ import absolute_import
in datalayer/radian.py and other similarly affected modules, and then check all your imports to ensure that they're absolute. You may be able to get away with renaming datalayer/radian.py and the imports which reference it, depending on where that module is referenced from.

Nameclash when importing packages that has the word 'django' in the name?

I have a somewhat odd problem. I decided to rename an entire branch of my package from
foo.bar.somemodule
to
foo.django.bar.somemodule
The problem is after this is done, I get the following error:
Traceback (most recent call last):
File "/home/workspace/eclipse/foo/src/foo/manage.py", line 2, in <module>
from django.core.management import execute_manager
ImportError: No module named core.management
If I now, revert the name to
foo.djangox.bar.somemodule
IT WORKS! Notice, the 'x' I added to the word django.
It seems there are some kind of name clash when using foo.django.bar.somemodule, but What gives? They should be separate from django itself.
All the imports in my code are of the form
from foo.django.bar.somemodule import someobject
import foo.django.bar.somemodule
edit: to clarify there is an 'x' in the second to last import
You're running into a situation where you want to perform an absolute import, but your Python version doesn't do them by default. Add from __future__ import absolute_import at the top of the afflicted file to tell the Python VM to activate it.

Categories

Resources