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.
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:
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.
This question already has answers here:
How do I find the location of Python module sources?
(20 answers)
Closed 5 years ago.
I apparently have multiple versions of a module installed and I am trying to figure out where the files are because only one of them is from package management and I want to delete the other.
Is there a simple way to ask Python where it found a module after importing it?
if the module isn't built-in, you can do this:
import your_module
print(your_module.__file__)
test:
>>> import os
>>> print(os.__file__)
L:\Python34\lib\os.py
if module is built-in, you get an error:
>>> import sys
>>> print(sys.__file__)
Traceback (most recent call last):
File "<string>", line 301, in runcode
File "<interactive input>", line 1, in <module>
AttributeError: 'module' object has no attribute '__file__'
>>>
(check if module has the __file__ attribute using hasattr is also an option to avoid errors; if hasattr(module_name, '__file__'):)
also: by directly printing the module:
>>> print(os)
<module 'os' from 'L:\\Python34\\lib\\os.py'>
You can use __file__ after importing the module:
>>> import os
>>> os.__file__
'/usr/lib/python2.7/os.pyc'
This question already has answers here:
Python csv import fails
(2 answers)
Closed 1 year ago.
i don't know why i get this error even i installed correctly the libraries:
Traceback (most recent call last):
File "D:/Doc/Diagnostic-Technology/Browser.py", line 4, in <module>
import scipy.stats as stat
File "D:\Doc\Diagnostic-Technology\scipy\__init__.py", line 61, in <module>
from numpy import show_config as show_numpy_config
ImportError: cannot import name 'show_config'
packages wich i imported :
import pandas as pd
import numpy as np
import scipy.stats as stat
import math as math
help please!
I have the same problem and solved it this way
find any file named as "numpy.py" in your script directory and change it into another name.
delete any file named as "numpy.pyc" or any other file generated while compiling your code.
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.