Python Import Error
Contents |
here for a quick
Python Importerror Cannot Import Name
overview of the site Help Center Detailed answers import error -9912 image capture to any questions you might have Meta Discuss the workings and policies of python importerror no module named windows this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with
Django Importerror: No Module Named
us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up
Importerror: No Module Named Pycharm
Python import error: 'No module named' does exist up vote 13 down vote favorite 3 I am getting this stack trace when I start pyramid pserve: % python $(which pserve) ../etc/development.ini Traceback (most recent call last): File "/home/hughdbrown/.local/bin/pserve", line 9, in
and then inside that for an object named baz (which may be a regular python object, or another module) A module is defined as: either a Python file ie a file on disk that ends $pythonpath in .py and contains valid Python (syntax errors, for example, will stop you from being
Python Importerror No Module Named Site
able to import a file) or a folder which contains Python files. for a folder to become a module, it must contain a importerror: no module named mac special file called __init__.py When a module is actually a folder, the things you can import from it are: any other modules that are inside the folder (ie, more .py files and folders) any objects defined or imported http://stackoverflow.com/questions/23417941/python-import-error-no-module-named-does-exist inside the __init__.py of the folder Finally, where does Python look for modules? It looks in each directory specified in the special "sys.path" variable. Typically (but not always), sys.path contains some default folders, including the current working directory, and the standard "packages" directory for that system, usually called site-packages, which is where pip installs stuff to. So from foo.bar import baz could work in a few different ways: . `-- foo/ |-- __init__.py `-- bar.py <-- https://help.pythonanywhere.com/pages/DebuggingImportError/ contains a variable called "baz" Or . `-- foo/ |-- __init__.py `-- bar/ |-- __init__.py `-- baz.py Or: . `-- foo/ |-- __init__.py `-- bar/ `-- __init__.py <-- contains a variable called "baz" What this means is that you need to get a few things right for an import to work: The dot-notation has to work: from foo.bar import baz means foo has to be a module folder, and bar can either be a folder or a file, as long as it somehow contains a thing called baz. Spelling mistakes, including capitalization, matter The top-level "foo" must be inside a folder that's on your sys.path. If you have multiple modules called "foo" on your sys.path, that will probably lead to confusion. Python will just pick the first one. Debugging sys.path issues in web apps can you run the wsgi file itself? $ python3.4 -i /var/www/www_my_domain_com_wsgi.py Or, if you're using python 2: $ python2.7 -i /var/www/www_my_domain_com_wsgi.py Or, if you're using a virtualenv, activate it first: $ workon my-virtualenv (my-virtualenv)$ python -i /var/www/www_my_domain_com_wsgi.py If this shows any errors and won't even load python (eg syntax errors), you'll need to fix them. If it loads OK, it will drop you into a Python shell. Try doing the import manually at the command line. Then, check whether they really are coming from where you think they are: from foo.bar
The stale bytecode file trap The submodules are added to the package namespace trap More exotic traps Else Clauses on Loop Statements Various Ideas for Python http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html and CPython Using the Python Kerberos Module General Linux Notes Python Conferences https://docs.python.org/2/library/exceptions.html Nick Coghlan's Python Notes Docs » Python Concepts » Traps for the Unwary in Python's Import System Edit on Bitbucket Traps for the Unwary in Python's Import System¶ Python's import system is powerful, but also quite complicated. Until the release of Python 3.3, there was no comprehensive explanation of the no module expected import semantics, and even following the release of 3.3, the details of how sys.path is initialised are still somewhat challenging to figure out. Even though 3.3 cleaned up a lot of things, it still has to deal with various backwards compatibility issues that can cause strange behaviour, and may need to be understood in order to figure out how some no module named third party frameworks operate. Furthermore, even without invoking any of the more exotic features of the import system, there are quite a few common missteps that come up regularly on mailing lists and Q&A sites like Stack Overflow. This essay only officially covers Python versions back to Python 2.6. Much of it applies to earlier versions as well, but I won't be qualifying any of the explanations with version details before 2.6. As with all my essays on this site, suggestions for improvement or requests for clarification can be posted on BitBucket. The missing __init__.py trap¶ This particular trap applies to 2.x releases, as well as 3.x releases up to and including 3.2. Prior to Python 3.3, filesystem directories, and directories within zipfiles, had to contain an __init__.py in order to be recognised as Python package directories. Even if there is no initialisation code to run when the package is imported, an empty __init__.py file is still needed for the interpreter to find any modules or subpackages in that directory. This has changed in Python 3.3: now any directory on
This module never needs to be imported explicitly: the exceptions are provided in the built-in namespace as well as the exceptions module. For class exceptions, in a try statement with an except clause that mentions a particular class, that clause also handles any exception classes derived from that class (but not exception classes from which it is derived). Two exception classes that are not related via subclassing are never equivalent, even if they have the same name. The built-in exceptions listed below can be generated by the interpreter or built-in functions. Except where mentioned, they have an "associated value" indicating the detailed cause of the error. This may be a string or a tuple containing several items of information (e.g., an error code and a string explaining the code). The associated value is the second argument to the raise statement. If the exception class is derived from the standard root class BaseException, the associated value is present as the exception instance's args attribute. User code can raise built-in exceptions. This can be used to test an exception handler or to report an error condition "just like" the situation in which the interpreter raises the same exception; but beware that there is nothing to prevent user code from raising an inappropriate error. The built-in exception classes can be subclassed to define new exceptions; programmers are encouraged to derive new exceptions from the Exception class or one of its subclasses, and not from BaseException. More information on defining exceptions is available in the Python Tutorial under User-defined Exceptions. The following exceptions are only used as base classes for other exceptions. exception BaseException¶ The base class for all built-in exceptions. It is not meant to be directly inherited by user-defined classes (for that, use Exception). If str() or unicode() is called on an instance of this class, the representation of the argument(s) to the