Python Debug Import Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta import error python no module named Discuss the workings and policies of this site About Us Learn
Python Importerror Cannot Import Name
more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack python importerror no module named site 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, sys.path python helping each other. Join them; it only takes a minute: Sign up Trace Python imports up vote 14 down vote favorite 2 My Python library just changed it's main module name from foo.bar to foobar. For backward compat, foo.bar still exists, but importing it raises a few warnings. Now, it seems some example program still imports from
Python Importerror No Module Named Windows
the old module, but not directly. I'd like to find the erroneous import statement. Is there any tool that allows me to trace imports and find the culprit without wading through all of the code? python debugging import trace share|improve this question asked Sep 7 '11 at 10:23 Fred Foo 229k34436610 add a comment| 2 Answers 2 active oldest votes up vote 22 down vote accepted Start the python interpreter with -v: $ python -v -m /usr/lib/python2.6/timeit.py # installing zipimport hook import zipimport # builtin # installed zipimport hook # /usr/lib/python2.6/site.pyc matches /usr/lib/python2.6/site.py import site # precompiled from /usr/lib/python2.6/site.pyc # /usr/lib/python2.6/os.pyc matches /usr/lib/python2.6/os.py import os # precompiled from /usr/lib/python2.6/os.pyc import errno # builtin import posix # builtin # /usr/lib/python2.6/posixpath.pyc matches /usr/lib/python2.6/posixpath.py import posixpath # precompiled from /usr/lib/python2.6/posixpath.pyc # /usr/lib/python2.6/stat.pyc matches /usr/lib/python2.6/stat.py import stat # precompiled from /usr/lib/python2.6/stat.pyc # /usr/lib/python2.6/genericpath.pyc matches /usr/lib/python2.6/genericpath.py import genericpath # precompiled from /usr/lib/python2.6/genericpath.pyc # /usr/lib/python2.6/warnings.pyc matches /usr/lib/python2.6/warnings.py import warnings # precompiled from /usr/lib/python2.6/warnings.pyc # /usr/lib/python2.6/linecache.pyc matches /usr/lib/python2.6/linecache.py import linecache # precompiled from /usr/lib/python2.6/linecache.pyc # /usr/lib/python2.6/types.pyc
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 in .py and contains valid Python python importerror no module named requests (syntax errors, for example, will stop you from being able to import a file) or a __init__.py example folder which contains Python files. for a folder to become a module, it must contain a special file called __init__.py When a module is actually
Add To Pythonpath
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 inside the __init__.py of the folder Finally, where does Python look for http://stackoverflow.com/questions/7332299/trace-python-imports 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 <-- contains a variable called "baz" Or . `-- foo/ |-- __init__.py `-- bar/ |-- __init__.py `-- baz.py Or: https://help.pythonanywhere.com/pages/DebuggingImportError/ . `-- 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 import baz import foo print(foo) # this should show the path to the module. Is it what you expect? import sys print('\n'.join(sys.path)) # does this show the files and folders you need? Django-specific issues In Django, we s
First, I ran pip show --files sendwithus from the terminal This was the output: http://preview.tinyurl.com/p2l99mq Then, I took that "Location" info and manually appended it to the path http://forum.komodoide.com/t/im-unable-to-import-a-python-package-i-keep-getting-the-error-message-importerror-no-module-named-name-of-module/384 in the beginning of my code: import sys print sys.path sys.path.append('Users/MacBookAir/anaconda/lib/python2.7/site-packages') import sendwithus #the rest of my code Finally worked! My original explanation of what I did: What I've done so far: I http://gis.stackexchange.com/questions/85408/debugging-importerror-no-module-named-arcpy used PIP to install a module, sendwithus When I tried using the package: import sendwithus #my_code I got this error: ImportError: No module named sendwithus I manually added the path in Komodo (Komodo no module >> Preferences >> Python >> +) Komodo >> Preferences Python 4.Now, Komodo recognizes the package and finds it on the drop-down 5.And yet, I'm still getting the same error. 6.So, I went and tried to append the path using sys.path, thinking maybe it was an issue there. My code: import sysprint sys.pathsys.path.append('/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages') 8.No dice. The problem remains. ImportError: No module named name_of_module toddw 2014-06-11 19:15:22 no module named UTC #2 Could it be that Komodo and your terminal were using different Python's? I.e. one was using ActivePython, one was using the Mac system Python. adam 2014-06-11 23:28:16 UTC #3 Not sure! How do I check? toddw 2014-06-11 23:57:24 UTC #4 In the terminal, type: which python and in Komodo, check in the Python preferences page and click on the Use this interpreter menulist - the first Python interpreter is what Komodo uses when it's set to Find on Path. adam 2014-06-12 00:15:11 UTC #5 Here's the output: and Should I change from "Find on Path" to "user/bin/python" ? Will that break (or fix) my ability to use PIP? Sorry if these are noob questions. adam 2014-06-12 00:16:05 UTC #6 Re-reading your answer. Nevermind, looks like it's defaulting to "user/bin/python" already since that's the first one on the list. toddw 2014-06-12 16:02:05 UTC #7 It's best to use the same interpreter (i.e. /Users/Macbook/Air/anaconda/bin/python) in both terminal and Komodo - as that way any python libraries installed by pip on the command line (assuming pip is setup for anaconda/bin/python) should be available to Komodo automatically (for code intelligence and debugging) without having to manually adj
Badges sign up log in tour help Tour Start 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 Stack Overflow the company Business Learn more about hiring developers or posting ads with us Geographic Information Systems Questions Tags Users Badges Unanswered Ask Question _ Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Debugging ImportError: No module named arcpy? up vote 3 down vote favorite 1 I have written a script and am trying to run it in Python IDLE 2.7.6. I first try to import arcpy, but I get an error message saying "ImportError: No module named arcpy". Why doesn't it work? I'm working off ArcGIS 10.2 for Desktop. arcpy arcgis-10.2 idle share|improve this question edited Jul 29 '15 at 9:55 PolyGeo♦ 39.3k1358149 asked Feb 4 '14 at 23:47 model_help 63116 2 You have to ensure that the arcpy module is within your path/pythonpath environment variables - I believe this should be taken care of if it is installed correctly. –dklassen Feb 4 '14 at 23:58 add a comment| 3 Answers 3 active oldest votes up vote 5 down vote accepted This error is discussed near the bottom of the Importing ArcPy documentation page where there are some additional notes about ArcGIS 10.2.1 (if that is the precise version that you are using). share|improve this answer edited Jul 29 '15 at 9:51 answered Feb 5 '14 at 0:43 PolyGeo♦ 39.3k1358149 Wow - thank you so much I had this exact problem, note that your file location may not match exactly the three locations as shown at the bottom ESRI documentation. I am on 10.2.2 but the directory where my files really were was "Program Files (x86) / 10.2" lame difference that I did not catch. Does anyone know why these paths aren't fixed automatically when you d/l the python package from ESRI and re-install, or during a Repair from the ArcGIS for Desktop installer? My desktop10.2.pth file was actually empty after I re-installe