This question already has answers here:
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed 5 years ago.
When I import urllib.request in python 3, I get the following error:
Traceback (most recent call last):
File "urllibExample.py", line 1, in <module>
import urllib.request
File "/home/andrew/Python/urllib.py", line 1, in <module>
import urllib.request, urllib.parse, urllib.error
ModuleNotFoundError: No module named 'urllib.request'; 'urllib' is not
a package
I'm not sure why I'm getting this error message since urllib.request is in the standard library. Does anyone know how to fix this?
You appear to have a file of your own named urllib.py. The import is being attempted from this file instead of the system installed one.
Rename your file.
Related
This question already has answers here:
ImportError: No module named 'resource_rc'
(5 answers)
Closed 7 months ago.
I converted QT .ui file into .py file and when I run it I get this error?
Traceback (most recent call last):
File ~\Desktop\Project\main2.py:14 in <module>
from ui3 import Ui_Form
File ~\Desktop\Project\ui3.py:39 in <module>
import rec_rc
ModuleNotFoundError: No module named 'rec_rc'
The following solution if provided by eyllanesc in this question, and it seems to be the same error as yours.
You should have a file called rec.qrc, this must be converted to
.py, this or you can do it by executing:
pyrcc5 rec.qrc -o rec_rc.py
This question already has answers here:
Why can't I import from a module alias?
(4 answers)
Closed 2 years ago.
Let's suppose I import the pathlib module with an alias :
import pathlib as plib
Then plib is now pointing to the pathlib module :
>>> plib
<module 'pathlib' from '/usr/lib/python3.8/pathlib.py'>
Now can someone tell me why importing something from this aliased module doesn't work?
>>> from plib import Path
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'plib'
The loading process of The module is not based on the alias, it searches the python installation or project directory by the given name after import statement.
This question already has an answer here:
Python ImportError: cannot import name itemgetter
(1 answer)
Closed 2 years ago.
When I tried in Mac os with python 3.8.3
this code:
from turtle import *
shape("turtle")
I get this error:
Traceback (most recent call last):
File "C:\Users\jeeva\Desktop\Tanmay_new\python\pi\Draw_pi\draw_pi.pyw", line 2, in <module>
shape("turtle")
NameError: name 'shape' is not defined
It looks like python doesn't reconize shape.
Please help me.
See if you have a file named turtle.py other than the module. Rename it and try again
This question already has answers here:
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed 6 years ago.
I have a Python script that uses requests. It worked fine for a long time. Now out of the blue I get the following error. I tried reinstalling requests but that didn't fix it. The only thing I can think of that caused the error is I have been running a Django development server, so maybe I got hacked? Please help.
code:
import requests
...
error:
Traceback (most recent call last):
File "myfile.py", line 1, in <module>
import requests
File "/Users/myuser/.virtualenvs/mysite/lib/python2.7/site-packages/requests/__init__.py", line 58, in <module>
from . import utils
File "/Users/myuser/.virtualenvs/mysite/lib/python2.7/site-packages/requests/utils.py", line 12, in <module>
import cgi
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/cgi.py", line 50, in <module>
import mimetools
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
import tempfile
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 35, in <module>
from random import Random as _Random
ImportError: cannot import name Random
You have masked the built-in library module with a local file named random.py. Rename that file.
Python looks up modules to import along a path, and if you put a module in a location that's looked at before the standard library, you can end up masking a built-in like you did here.
This question already has answers here:
ImportError: No module named _ssl
(9 answers)
Closed 9 years ago.
I'm getting an error because the ssl module isn't available
If I run help('modules') from the python interpreter it is listed there
When I try to import it from the interpreter, I get
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
Ensure that you have openssl package installed.