Questions tagged [importerror]

Refers to errors that result from attempting to import a module or library into one's code

Import errors occur while attempting to import a module or library into one's code. Common causes include:

  1. attempting to import from an incorrect file/module/library name
  2. not including the required files in the project/language/system path
  3. cyclic imports (A imports B and B imports A)
2706 questions
1798
votes
31 answers

Importing files from different folder

I have the following folder structure. application ├── app │   └── folder │   └── file.py └── app2 └── some_folder └── some_file.py I want to import some functions from file.py in some_file.py. I've tried from…
Ivan
  • 21,917
  • 6
  • 22
  • 21
772
votes
20 answers

How to fix "Attempted relative import in non-package" even with __init__.py

I'm trying to follow PEP 328, with the following directory structure: pkg/ __init__.py components/ core.py __init__.py tests/ core_test.py __init__.py In core_test.py I have the following import statement from…
skytreader
  • 10,673
  • 5
  • 39
  • 57
616
votes
16 answers

ImportError: Cannot import name X

I have four different files named: main.py, vector.py, entity.py and physics.py. I will not post all the code, just the imports, because I think that's where the error is (If you want, I can post more). main.py: import time from entity import…
jsells
  • 6,169
  • 3
  • 12
  • 3
524
votes
31 answers

Python error "ImportError: No module named"

Python is installed in a local directory. My directory tree looks like this: (local directory)/site-packages/toolkit/interface.py My code is in here: (local directory)/site-packages/toolkit/examples/mountain.py To run the example, I write python…
Eduardo
  • 17,165
  • 20
  • 59
  • 71
167
votes
18 answers

"ImportError: No module named" when trying to run Python script

I'm trying to run a script that launches, amongst other things, a python script. I get a ImportError: No module named ..., however, if I launch ipython and import the same module in the same way through the interpreter, the module is accepted. …
CodeOcelot
  • 2,944
  • 3
  • 18
  • 23
153
votes
19 answers

ImportError: No Module Named bs4 (BeautifulSoup)

I'm working in Python and using Flask. When I run my main Python file on my computer, it works perfectly, but when I activate venv and run the Flask Python file in the terminal, it says that my main Python file has "No Module Named bs4." Any…
harryt
  • 1,693
  • 2
  • 12
  • 10
147
votes
16 answers

ImportError: cannot import name main when running pip --version command in windows7 32 bit

I've installed the latest python (2.7.9) bundled with pip and setuptools for windows 32-bit. I've tried reinstalling pip but the problem persists. Here's the error after running pip --version in Administrator cmd: Traceback (most recent call last): …
Woootiness
  • 1,743
  • 2
  • 13
  • 15
125
votes
9 answers

ImportError: libSM.so.6: cannot open shared object file: No such file or directory

When trying to import OpenCV, using import cv2 I get the following error: /usr/local/lib/python2.7/dist-packages/cv2/__init__.py in () 7 8 # make IDE's (PyCharm) autocompletion happy ----> 9 from .cv2 import * 10 11 #…
Dmitry Rastorguev
  • 2,995
  • 4
  • 11
  • 14
113
votes
10 answers

ImportError: No module named six

I'm trying to build OpenERP project, done with dependencies. It's giving this error now Traceback (most recent call last): File "openerp-client.py", line 105, in File "modules\__init__.pyo", line 23, in File…
asadullah07
  • 1,241
  • 2
  • 9
  • 9
93
votes
2 answers

psycopg2: AttributeError: 'module' object has no attribute 'extras'

In my code I use the DictCursor from psycopg2.extras like this dict_cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) However, all of the sudden I get the following error when I load the cursor: AttributeError: 'module' object has no…
n1000
  • 4,298
  • 3
  • 32
  • 57
87
votes
21 answers

Installing OpenCV for Python on Ubuntu, getting ImportError: No module named cv2.cv

I have an Ubuntu 14.04 system, on which I want to install OpenCV and use it with Python 2.x. I installed OpenCV using the instructions here: https://help.ubuntu.com/community/OpenCV The install seemed to run properly, no errors, the script ended…
robm
  • 1,021
  • 2
  • 8
  • 9
87
votes
7 answers

ImportError: No module named mock

So I am trying to use unittest.mock to mock some of my methods in my unit tests. I do: from unittest.mock import MagicMock f = open("data/static/mock_ffprobe_response") subprocess.check_output = MagicMock(return_value=f.read()) f.close() But I am…
Richard Knop
  • 73,317
  • 142
  • 374
  • 539
86
votes
3 answers

Attempted relative import with no known parent package

from ..box_utils import decode, nms This line is giving error ImportError: attempted relative import with no known parent package What is this error and how to resolve this error?
Puneet Shekhawat
  • 983
  • 1
  • 5
  • 13
80
votes
6 answers

How can I troubleshoot Python "Could not find platform independent libraries "

I'm trying to use Fontcustom to create an icon font using svg files and fontforge. I'm on OSX.7. However, whenever I run the program I get the error Could not find platform independent libraries Could not find platform dependent libraries…
Lars
  • 6,670
  • 9
  • 45
  • 65
64
votes
7 answers

ImportError: No module named 'bottle' - PyCharm

I installed bottle on python3.4 with pip install. In terminal, when I do: $ python3.4 >>>import bottle # shows no import error >>> but when I do it in PyCharm, it says "import bottle ImportError: No module named 'bottle'"
Tinno TL
  • 643
  • 1
  • 5
  • 7
1
2 3
99 100