I am new to python and I cannot get my head around why I am facing with the error in title.
This is my project structure:
and this is what I have inside shipping.py module:
def calc_shipping():
print('Calculating shipping...')
so when I do -> from ecommerce.shipping import calc_shipping
and want to use calc_shipping()
I get error ->
Traceback (most recent call last):
File "/Users/burakhanaksoy/gitHub/Python/PythonStudy/bman/basics/modules/app.py", line 9, in <module>
from ecommerce.shipping import calc_shipping
ModuleNotFoundError: No module named 'ecommerce'
any help is appreciated.
best,
PS: I get the same error in PyCharm as well, in fact in PyCharm, it doesn't even auto-fill 'ecommerce' or 'ecommerce.shipping' as I type
from ecommerce.shipping import calc_shipping
On such scenarios always check following things:
if the module has init, in other words if its a python module
check if its accessible from parent dir, in this example basics.
Related
The importing is as below:
from settings import Settings
And it gave a traceback.
Traceback (most recent call last):
File "c:\0Data\Desktop\Alien_invasion\Aliens.py", line 5, in <module>
from settings import Settings
ModuleNotFoundError: No module named 'settings'
I checked. It's the exact same. The book is Python crash course 2nd edition page 235.
There's a file you're missing that you need, from a quick Google search:
https://github.com/ehmatthes/pcc
Pull it from there ^ depends on what chapter you're on. Make sure you put it in your working directory.
The Python Standard Library does not have any module named settings. Most likely is a module created previously in the book or something installed with Pip
I am trying to import Pybedtools in Spyder.
from pybedtools import BedTool
This is the error I am getting:
Traceback (most recent call last):
File "<ipython-input-13-7a8ea5d1dea8>", line 1, in <module>
from pybedtools import BedTool
File "/Users/michaelsmith/anaconda2/lib/python2.7/site-packages/pybedtools/__init__.py", line 9, in <module>
from . import scripts
ImportError: cannot import name scripts
I just downloaded Anaconda and there doesn't seem to be a reason as to why this happens. What is the typical protocol for resolving bugs like this?
UPDATE:
So within my pybedtools folder there is a scripts folder (which is presumably the module we're trying to import). I changed both the command within __init__.py to:
from . import scripts2
and changed the name of the folder to scripts2 as well. However, I still get the error as such:
ImportError: cannot import name scripts2
So I must be doing something wrong here, which module should I be renaming exactly? Sorry if this is a silly question, I am quite new to python.
This is caused because Anaconda has a module named scripts and therefore your import is "shadowed" by that module. You can double check that when you call import scripts in a new notebook it works even if you have never defined such a module. A very good explanation of import traps can be found here:
http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html
A workaround would be to rename the script module of pybedtools to something else and also change all the imports to the new name.
I am a beginner with Python and using Python 3.6.0 on Mac OS X 10.12. I imported a module saved in my documents folder with all of my other modules that worked fine, yet it came back with this after the module ran:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import futval.py
ModuleNotFoundError: No module named 'futval.py'; 'futval' is not a package
All of my other modules ran fine before this one and I can't figure out the issue. I've searched around the site for answers and can't seem to find anything. Any help is appreciated.
If you're trying to import a file named futval.py, you need to write just import futval; the name of the module does not include the .py.
I found the following problem in executing my python function:
Traceback (most recent call last):
File "/home/ppd/myfunc.py", line 2, in <module>
from cythonUtilsPy.cythonUtils import *
ImportError: No module named cythonUtils
How to add this cythonUtils module to my path?
Based on the error message, it looks like cythonUtilsPy is already on your path and was found, but the submodule cythonUtilsPy.cythonUtils was not found. Unless you are importing the wrong cythonUtilsPy, there is no path manipulation you can do to fix this.
You need to track down why cythonUtils is not showing up as a submodule of cythonUtilsPy, if cythonUtils is a directory perhaps it is missing an __init__.py.
I have a somewhat odd problem. I decided to rename an entire branch of my package from
foo.bar.somemodule
to
foo.django.bar.somemodule
The problem is after this is done, I get the following error:
Traceback (most recent call last):
File "/home/workspace/eclipse/foo/src/foo/manage.py", line 2, in <module>
from django.core.management import execute_manager
ImportError: No module named core.management
If I now, revert the name to
foo.djangox.bar.somemodule
IT WORKS! Notice, the 'x' I added to the word django.
It seems there are some kind of name clash when using foo.django.bar.somemodule, but What gives? They should be separate from django itself.
All the imports in my code are of the form
from foo.django.bar.somemodule import someobject
import foo.django.bar.somemodule
edit: to clarify there is an 'x' in the second to last import
You're running into a situation where you want to perform an absolute import, but your Python version doesn't do them by default. Add from __future__ import absolute_import at the top of the afflicted file to tell the Python VM to activate it.