I want to import a color module but I am getting the error:
ImportError: No module named 'scripts.UltraColor'
Import code:
from scripts.UltraColor import *
The import code is in pygameTest.py
The problem here, as far as I can see on that screenshot is UltraColor file doesn't have the .py extension, for import to work properly you'll need to rename it from UltraColor to UltraColor.py, otherwise will raise an ImportError exception.
For more information, take a look to this one. Import a python module without the .py extension
Related
Unable to import str from a module in the same directory.
Project is structured like this:
parent
└───cmds
└───chat_client.py
auth_client.py
In chat_client.py when I try to from cmds.auth_client import sesuser I get ModuleNotFoundError: No module named 'cmds'.
I tried removing the cmds. part, however instead it just gave me ImportError: cannot import name 'sesuser' from 'auth_client' (e:\parent\cmds\auth_client.py).
from auth_client import sesuser
try removing extention '.py'
The statement
from PyQt5 import QtWidgets
yields ImportError: DLL load failed: The specified module could not be found., but the statement
from PyQt5 import sdklfjsdlfkj
yields ImportError: cannot import name 'dfgdfgdfg'. This is confusing to me, because it's not like in the first snippet I'm trying to import something from QtWidgets. I mean, the QWidgets module is either there or it isn't, right? How is it possible that it's there "enough" to avoid a cannot import name, but also not there enough to be able to import it?
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've downloaded pymumble from https://github.com/Robert904/pymumble and saved it to my working directory. I import it with:
from pymumble import pymumble
However, I receive:
ImportError: No module named pymumble
I'm looking at similar code that does this successfully. What am I doing wrong when trying to import this?
As I can see there is no file called pymumble in given repository, if you are looking for this there is a file called mumble.py, try importing
from mumble import mumble
this will work.
I am facing a strange error while executing a python code. The following code is a small snippet of the python code I am executing:
#samplecode.py
import time
from datetime import datetime
import sys
import os
import inspect
sys.path.append(os.path.dirname('C:\Users\qksr\Desktop\work\kako\logging.py'))
import logging
from logging import Dynamic
While executing samplecode.py I am facing an error showing the following:
Traceback (most recent call last):
File "C:\Users\qksr\Desktop\work\Fire\samplecode6.py", line 8, in <module>
from logging import Dynamic
ImportError: cannot import name Dynamic
My logging.py which contains the code that needs to be imported while execution. The following is the code:
class Dynamic(object):
pfile3=open('C:\Users\qksr\Desktop\work\sample3.txt','w')
we can see that the class Dynamic is created yet the import error is thrown.
The strangest thing is I did few examples of importing files and it worked well. I have tried hard but still cannot figure it out. I would like to know why this error was thrown and why suddenly for this and not in previous samples?
Python already has a built-in logging module, which is being located before yours (you're appending your folder to the end of the path).
Rename your logging.py file to something else.