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
Related
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.
Pycharm says REPORT.py file doesn't exist. However the code works perfectly.
Here is the image of the issue:
Now that is not the strangest part. I know sometimes when you working within a package you have to reference the package name: import package_name.filename so when I tried that it appears to have fixed the incorrect reporting.
But then...
Traceback (most recent call last):
File "C:/Users/REDACTED/PycharmProjects/REDACTED/MAIN/MAIN.py", line 2, in <module>
import MAIN.REPORTS as PDD
File "C:\Users\REDACTED\PycharmProjects\REDACTED\MAIN\MAIN.py", line 2, in <module>
import MAIN.REPORTS as PDD
ModuleNotFoundError: No module named 'MAIN.REPORTS'; 'MAIN' is not a package
This seams like a mistake with how Pycharm is checking for my file.
For the sake of completeness I also tried to import from.
Pycharm is also not marking this as invalid but I get a new interesting error when running the code:
Traceback (most recent call last):
File "C:/Users/REDACTED/PycharmProjects/REDACTED/MAIN/MAIN.py", line 2, in <module>
from MAIN import REPORTS as PDD
File "C:\Users\REDACTED\PycharmProjects\REDACTED\MAIN\MAIN.py", line 2, in <module>
from MAIN import REPORTS as PDD
ImportError: cannot import name 'REPORTS'
As request in the comments here is my folder structure:
Per suggestion in the comments I did try to import * but I still get the same reporting issue from Pycharm.
Update:
I believe I found out why the issue existed when trying to import from my package.
Due to my package name being MAIN and my main py file being MAIN.py I believe my code was trying to import from the py file and not the package.
After renaming my package to MAIN_PACK and doing import MAIN_PACK.REPORT as PDD the code works fine without any reporting from Pycharm saying it is not valid.
That at the vary least fixes the Pycharm reporting.
However that still does not explain why Pycharm reports that import REPORTS is not a module but still the code would work.Does anyone know why this is occurring?
Set the main folder as the source root. You can do that by right clicking the MAIN folder and navigating to the bottom of the list. Mark the directory as source root. Go into Pycharm settings under console and check add source roots to python path.
Pycharm uses source root to resolve imports. More information can be found here
https://www.jetbrains.com/help/pycharm/content-root.html
Relevant text from link:
Source roots (or source folders; shown as the Source root icon ).
These roots contain the actual source files and resources. PyCharm uses the source roots as the starting point for resolving imports.
The files under the source roots are interpreted according to their type. PyCharm can parse, inspect, index, and compile the
contents of these roots.
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 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.