Iport Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about
Python Importerror Cannot Import Name
Stack Overflow the company Business Learn more about hiring developers or posting ads with import error -9912 image capture us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a
Python Importerror No Module Named Windows
community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to fix “ImportError: No module named …” error in Python? up vote 47 down django importerror: no module named vote favorite 6 What is the correct way to fix this ImportError error? I have the following directory structure: /home/bodacydo /home/bodacydo/work /home/bodacydo/work/project /home/bodacydo/work/project/programs /home/bodacydo/work/project/foo And I am in the directory /home/bodacydo/work/project Now if I type python ./programs/my_python_program.py I instantly get ImportError: No module named foo.tasks The ./programs/my_python_program.py contains the following line: from foo.tasks import my_function I can't understand why python won't find ./foo/tasks.py - it's there. If I do it importerror: no module named pycharm from the Python shell, then it works: python >>> from foo.tasks import my_function It only doesn't work if I call it via python ./programs/my_python_program.py script. python share|improve this question edited Jul 9 '15 at 20:36 neuronet 1,26511344 asked Feb 24 '10 at 12:31 bodacydo 14.5k38126228 add a comment| 5 Answers 5 active oldest votes up vote 52 down vote accepted Python does not add the current directory to sys.path, but rather the directory that the script is in. Add /home/bodacydo/work/project to either sys.path or $PYTHONPATH. share|improve this answer answered Feb 24 '10 at 12:47 Ignacio Vazquez-Abrams 446k64797954 So whats the point then of having init.py in the root folder? It seems to serve no purpose if you edit either sys.path or the pythonpath. –user1980175 Jan 4 '14 at 23:13 6 @Editor: __init__.py only indicates that the directory should be treated as a package, when its parent is either in sys.path or is itself a package. –Ignacio Vazquez-Abrams Jan 4 '14 at 23:15 In addition check the permissions on the folder. That was the problem in my case. –SidJ Aug 24 at 3:08 add a comment| up vote 18 down vote Do you have a file called __init__.py in the foo directory? If not then pyth
here for
Python Importerror No Module Named Site
a quick overview of the site Help Center importerror: no module named mac Detailed answers to any questions you might have Meta Discuss the workings
$pythonpath
and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers http://stackoverflow.com/questions/2325923/how-to-fix-importerror-no-module-named-error-in-python or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it http://stackoverflow.com/questions/23417941/python-import-error-no-module-named-does-exist only takes a minute: Sign up 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
started with python -I had a hard time figuring out how to import third-party modules & packages into my program. Here's a gist of what http://knowpapa.com/import/ I finally learnt: Know the Python Path Knowing about the PYTHONPATH is http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html key to installing and importing third-party packages. When an import command is passed, python looks for the module/package in a list of places. The default path(s) where python would search for modules can be found out by: import sys print sys.path For my computer it gives me the no module the following paths: [", ‘C:\\Python27\\Lib\\idlelib', ‘C:\\Windows\\system32\\python27.zip', ‘C:\\Python27\\DLLs', ‘C:\\Python27\\lib', ‘C:\\Python27\\lib\\plat-win', ‘C:\\Python27\\lib\\lib-tk', ‘C:\\Python27', ‘C:\\Python27\\lib\\site-packages'] Starters would do good to install or add modules in one of these paths. If you get this wrong, you will get an error like: ImportError: No module named "foo" . By convention, all third-party packages go into Pythonfolder/Lib/site-packages. Importing Module or Importing packages ? When you no module named add a third-party module to your python library, remember that simply dumping a folder with bunch of .py files will not make it a package. When you use the import command, python does not look inside folders, even if the folders are located in the PYTHONPATH. However, if a folder in the PythonPath has a file called __init__.py, Python jumps inside it and treats the complete folder as a package. Changing the Pythonpath If you want to add packages in any other directory (other than the python paths listed above) - you will have to first export the python path in your code with: PYTHONPATH=$PYTHONPATH:C/Your new path/yournewmodulefolder Virtual Environment Builder Suppose you build several applications in your Python environment where one of your application requires version 1 of PackageX, while another application of yours requires version 2 of PackageX. If you try placing both these version in the same folder (say site-package), you are in for some trouble. To avoid any such interference, you can have separate Virtual environment for each of your applications using Virtual P
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 and CPython Using the Python Kerberos Module General Linux Notes Python Conferences 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 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 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