Python error ImportError: No module named
Based on your comments to orip's post, I guess this is what happened:
- You edited
__init__.py
on windows. - The windows editor added something non-printing, perhaps a carriage-return (end-of-line in Windows is CR/LF; in unix it is LF only), or perhaps a CTRL-Z (windows end-of-file).
- You used WinSCP to copy the file to your unix box.
- WinSCP thought: "This has something that's not basic text; I'll put a .bin extension to indicate binary data."
- The missing
__init__.py
(now called__init__.py.bin
) means python doesn't understand toolkit as a package. - You create
__init__.py
in the appropriate directory and everything works... ?
How to fix ImportError: No module named ... error in Python?
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
.
Relative imports - ModuleNotFoundError: No module named x
As was stated in the comments to the original post, this seemed to be an issue with the python interpreter I was using for whatever reason, and not something wrong with the python scripts. I switched over from the WinPython bundle to the official python 3.6 from python.org and it worked just fine. thanks for the help everyone :)
import error: 'No module named' *does* exist
My usual trick is to simply print sys.path
in the actual context where the import problem happens. In your case it'd seem that the place for the print is in /home/hughdbrown/.local/bin/pserve
. Then check dirs & files in the places that path shows..
You do that by first having:
import sys
in python 3 with the print function:
print(sys.path)
or in python 2 with print expression:
print sys.path
ImportError: No module named when trying to run Python script
This issue arises due to the ways in which the command line IPython interpreter uses your current path vs. the way a separate process does (be it an IPython notebook, external process, etc). IPython will look for modules to import that are not only found in your sys.path, but also on your current working directory. When starting an interpreter from the command line, the current directory you're operating in is the same one you started ipython in. If you run
import os
os.getcwd()
you'll see this is true.
However, let's say you're using an ipython notebook, run os.getcwd()
and your current working directory is instead the folder in which you told the notebook to operate from in your ipython_notebook_config.py file (typically using the c.NotebookManager.notebook_dir
setting).
The solution is to provide the python interpreter with the path-to-your-module. The simplest solution is to append that path to your sys.path list. In your notebook, first try:
import sys
sys.path.append('my/path/to/module/folder')
import module_of_interest
If that doesn't work, you've got a different problem on your hands unrelated to path-to-import and you should provide more info about your problem.
The better (and more permanent) way to solve this is to set your PYTHONPATH, which provides the interpreter with additional directories look in for python packages/modules. Editing or setting the PYTHONPATH as a global var is os dependent, and is discussed in detail here for Unix or Windows.
Python 3.4 ImportError: No module named 'typing' when importing requests
It looks like you are importing from the package 'typing' but you do not have it installed. Try installing the package:
pip install typing
Related Topics
Label Encoding Across Multiple Columns in Scikit-Learn
Multiprocessing: How to Share a Dict Among Multiple Processes
How to One Hot Encode in Python
What Does Asterisk * Mean in Python
Common Elements Comparison Between 2 Lists
Django Multivaluedictkeyerror Error, How to Deal with It
How to Override and Extend Basic Django Admin Templates
Differencebetween Size and Count in Pandas
How to Import a Module That Is Definitely Installed
Output to the Same Line Overwriting Previous Output
Python None Comparison: Should I Use "Is" or ==
How to Convert a String with Dot and Comma into a Float in Python
How to Switch to New Window in Selenium for Python
How to Parse Dates with -0400 Timezone String in Python
Pandas Loc VS. Iloc VS. at VS. Iat
Should Wildcard Import Be Avoided
How to Change the X Axis in Matplotlib So There Is No White Space