This question already has answers here:
ImportError: cannot import name namedtuple
(2 answers)
Closed 3 years ago.
I am currently working in PYCHARM and it gives me the error whenever I run the program. I tried various methods to remove this error but to no avail.
What can I do to fix this issue?
import re
File "F:\Anaconda\envs\tensorflow\lib\re.py", line 125, in <module>
import functools
File "F:\Anaconda\envs\tensorflow\lib\functools.py", line 21, in <module>
from collections import namedtuple
ImportError: cannot import name 'namedtuple'
Check the module in stdlib named types, it gets imported instead.
You can either rename your module, or switch to absolute imports.
Hope this will help you.
Related
This question already has answers here:
Pycharm and sys.argv arguments
(12 answers)
Closed 2 years ago.
I am trying to grab the 1st and 2nd argument using sys but i am unable to do so this is the code i am using :
import sys
import os
from PIL import Image
image_folder=sys.argv[1]
image_folder2=sys.argv[2]
print(image_folder)
this is the error
File "C:/Users/hp/PycharmProjects/test sys/test.py", line 4, in
image_folder=sys.argv[1]
IndexError: list index out of range
Any kind of help is appreciate[enter image description here][2]
You need to pass the command line arguments from the run configuration.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
The Code below works just fine :
import openpyxl
from openpyxl.utils import get_column_letter, column_index_from_string
import os
os.chdir('c:\\users\\shivam\\Desktop')
wb = openpyxl.load_workbook('data.xlsx')
print(wb.sheetnames)
print(get_column_letter(27))
but when I try to import it as:
from openpyxl import *
import os
os.chdir('c:\\users\\shivam\\Desktop')
wb = openpyxl.load_workbook('data.xlsx')
print(wb.sheetnames)
print(get_column_letter(27))
it gives an error:
Traceback (most recent call last):
File "D:/python projects/excel.py", line 4, in <module>
wb = openpyxl.load_workbook('data.xlsx')
NameError: name 'openpyxl' is not defined
Why everything from the module is not getting imported all at once?
If you import a module like import openpyxl, then you should use openpyxl.load_workbook.
But while importing a module like from openpyxl import *, rather than importing the whole module you're importing all the classes and functions present inside the module, so there is no need of calling openpyxl.something(), just directly call the name of class or function like load_workbook
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I was splitting some functions into a separate file. Found the functions and helper functions. Set all the paths and import in other files so everything can still be called where necessary. But after removing an unused import from the original file it gives a circular import error it seems.
So there is an unused import and while there, every test (524) succeeds, but the branch cant be pushed because of the unused import. If we remove the import, the tests goes into circular import I think and wont start at all.
The first thing i tried is to change the regarding import statements from: from /module import /object --> import module
This made the tests start but everything went wrong after that.
After that I tried to find a way through the circular import path but I just lost track of everything while I dont know if it is even a solution.
`
Traceback (most recent call last):
File "/home/user/../.py", line 2, in <module>
from x.model import x
File "/home/user/../.py", line 1, in <module>
import A
File "/home/user/../.py", line 4, in <module>
import B
File "/home/user/../.py", line 1, in <module>
import C
File "/home/user/../.py", line 9, in <module>
import D
File "/home/user/../.py", line 4, in <module>
import E
File "/home/user/../.py", line 9, in <module>
from x.model import x
ImportError: cannot import name 'x'
`
If you are using imported Ive in /home/user/projects/.../nsx/utils.py file, inside some method or function, then you should remove import statement (i.e from ive.models import Ive) from top of file import statements(if you are doing so), and import it dynamically means put import statement at the place where you are using Ive inside the method or function.
# Assume `/home/user/projects/.../nsx/utils.py` file
# Don't import Ive here
# from ive.models import Ive
def func():
# import here
from ive.models import Ive
# use Ive here
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 3 years ago.
I have a recent problem with random module
I dont understand why is that?
I showed the exact path that goes to random.py but it still didnt work.
python3.4 64bit
using pycharm 2016.2.2
First group is real error
Second group relates to help(random)
Sorry about confusion.
File "C:/Users/blueg/Google Drive/Programming/Python/PycharmProjects/LearningPython/Random Module/random.py", line 1, in <module>
import random File "C:\Users\blueg\Google Drive\Programming\Python\PycharmProjects\LearningPython\Random Module\random.py", line 4, in <module>
a = random.randint(1,6) AttributeError: 'module' object has no attribute 'randint'
Help on module random:
NAME random
FILE c:\users\blueg\google drive\programming\python\pycharmprojects\learningpython\random module\random.py
you have called your module random.py and thus you're importing your own module: rename it it will work (and also delete the random.pyc associated file or python will use that one in turn)
(I sometimes think that naming one's module in german, french or other avoids conflicts :))
I am learning to grab pictures from URL and found a Q&A here. Since it's Python 3, I changed import urllib to import urllib.request and
urllib.urlretrieve("http://www.digimouth.com/news/media/2011/09/google-logo.jpg", "local-filename.jpg")
to
urllib.request.urlretrieve("http://www.digimouth.com/news/media/2011/09/google-logo.jpg", "local-filename.jpg").
It doesn't work! It says AttributeError: 'module' object has no attribute 'urlretrieve'
I then changed urllib.urlretrieve to def request.urlretrieve and got SyntaxError: invalid syntax
I also tried def urlretrieve and it's not working either.
Could anyone tell me how to get it right? Thanks!
What if the URL contains more than one pic?
You need to use:
from urllib import request
request.urlretrieve("http://www.digimouth.com/news/media/2011/09/google-logo.jpg", "local-filename.jpg")
You can use also use:
import urllib.request
urllib.request.urlretrieve("http://www.digimouth.com/news/media/2011/09/google-logo.jpg", "local-filename.jpg")
Since you have imported urllib.request module, doesn't it seem obvious that you should call its method urlretrieve(args) as urllib.request.urlretrieve(args).
When you type import <module>, you call its method using <module>.method(args) (As specified in above code).
Alternatively, you can import the module using from <module> import * and then call its method using method(args). Eg -
from urllib.request import *
urlretrieve(args).
Another way is to only import the method you need to use in your program using
from <module> import method and then call the method using method(args). Eg -
from urllib.request import urlretrieve and then call the method using
urlretrieve(args).
The urllib.request module for Python 3 is well documented here.