When ever I try to import smtplib in the Python interpreter, I get this error:
ImportError: cannot import name fix_eols
How can I fix this?
Edit:
Here is the full stack trace:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 46, in <module>
import email.utils
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/utils.py", line 32, in <module>
from email._parseaddr import quote
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/_parseaddr.py", line 16, in <module>
import time, calendar
File "/Users/aaronblock/Documents/programming/scripts/calendar.py", line 7, in <module>
File "/usr/local/lib/python2.7/site-packages/apiclient/__init__.py", line 19, in <module>
from googleapiclient import discovery
File "/usr/local/lib/python2.7/site-packages/googleapiclient/discovery.py", line 38, in <module>
from email.generator import Generator
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/generator.py", line 15, in <module>
from email.header import Header
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/header.py", line 16, in <module>
import email.quoprimime
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/quoprimime.py", line 49, in <module>
from email.utils import fix_eols
ImportError: cannot import name fix_eols
Just to point out how to detect this kinds of errors (since it does happen from time to time):
Pay attention to the stacktrace. In this example, the problem can be seen in the line:
File "/Users/aaronblock/Documents/programming/scripts/calendar.py", line 7, in <module>
which certainly indicates wrong file being imported when we're trying to import a system-wide library.
I had a file called "calendar.py" which messes up my Python environment because smtplib needs calendar.py in order to work. Deleting calendar.py solved my problem.
Related
I wrote imports as usual, but it is wrong. I searched and did not find a mistake like mine, please help. The file name is main.py .
Traceback (most recent call last):
File "/app/main.py", line 2, in <module>
from telethon import TelegramClient, Button, events, version
File "/usr/local/lib/python3.9/site-packages/telethon/__init__.py", line 1, in <module>
from .client.telegramclient import TelegramClient
File "/usr/local/lib/python3.9/site-packages/telethon/client/__init__.py", line 12, in <module>
from .telegrambaseclient import TelegramBaseClient
File "/usr/local/lib/python3.9/site-packages/telethon/client/telegrambaseclient.py", line 3, in <module>
import asyncio
File "/usr/local/lib/python3.9/asyncio/__init__.py", line 8, in <module>
from .base_events import *
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 18, in <module>
import concurrent.futures
File "/usr/local/lib/python3.9/concurrent/futures/__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 7, in <module>
import logging
File "/usr/local/lib/python3.9/logging/__init__.py", line 28, in <module>
from string import Template
File "/app/string.py", line 7, in <module>
from telethon import TelegramClient, events
File "/usr/local/lib/python3.9/site-packages/telethon/events/__init__.py", line 1, in <module>
from .raw import Raw
File "/usr/local/lib/python3.9/site-packages/telethon/events/raw.py", line 1, in <module>
from .common import EventBuilder
File "/usr/local/lib/python3.9/site-packages/telethon/events/common.py", line 5, in <module>
from .. import utils
File "/usr/local/lib/python3.9/site-packages/telethon/utils.py", line 22, in <module>
from .extensions import markdown, html
File "/usr/local/lib/python3.9/site-packages/telethon/extensions/markdown.py", line 9, in <module>
from ..helpers import add_surrogate, del_surrogate, within_surrogate, strip_text
File "/usr/local/lib/python3.9/site-packages/telethon/helpers.py", line 20, in <module>
_log = logging.getLogger(__name__)
AttributeError: partially initialized module 'logging' has no attribute 'getLogger' (most likely due to a circular import)
I had similar issue, my python file was called token.py. Once I renamed it into something else the problem went away.
import urllib.request
fhand = urllib.request.urlopen("http://www.python.org")
for line in fhand:
print(line.decode().strip())
This code isn't working, I'm using python3 on windows10. Every time I run this code in command prompt using atom editor, I get the following error message:
Traceback (most recent call last):
File "C:\Users\isha\Downloads\py4e\trial.py", line 1, in <module>
import urllib.request
File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 88, in <module>
import http.client
File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 71, in <module>
import email.parser
File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\email\parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\email\feedparser.py", line 27, in <module>
from email._policybase import compat32
File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\email\_policybase.py", line 9, in <module>
from email.utils import _has_surrogates
File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\email\utils.py", line 29, in <module>
import socket
File "C:\Users\isha\Downloads\py4e\socket.py", line 5, in <module>
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
**AttributeError: partially initialized module 'socket' has no attribute 'AF_INET' (most likely due to a circular import)**
Help me with this code, also I'm not able to run urllib.request and related programs
Your code works well for me. Try delete 'C:\Users\isha\Downloads\py4e\socket.py' this file and run your code again.
ASCII is installed but still getting this error. I tested by importing all the libraries in the error msg but could not solve it.
Complete Error Message here.
Traceback (most recent call last):
File "re.py", line 1, in <module>
import requests,compile, ASCII
File "C:\Program Files\Python37\lib\site-packages\requests\__init__.py", line 43, in <module>
import urllib3
File "C:\Program Files\Python37\lib\site-packages\urllib3\__init__.py", line 7, in <module>
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
File "C:\Program Files\Python37\lib\site-packages\urllib3\connectionpool.py", line 3, in <module>
import logging
File "C:\Program Files\Python37\lib\logging\__init__.py", line 26, in <module>
import sys, os, time, io, traceback, warnings, weakref, collections.abc
File "C:\Program Files\Python37\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Program Files\Python37\lib\linecache.py", line 11, in <module>
import tokenize
File "C:\Program Files\Python37\lib\tokenize.py", line 33, in <module>
import re
File "C:\Users\naeem\Desktop\re.py", line 1, in <module>
import requests,compile, ASCII
ModuleNotFoundError: No module named 'ASCII'
Python Code I am running is here:
import requests,compile, ASCII
def main():
res = requests.get("https://www.google.com/")
print(res.text)
if __name__=="__main__":
main()
Can anybody help me out please?
ModuleNotFoundError: No module named 'ASCII'
This means that don't exist a module named 'ASCII'.
Maybe it's useful curses.ascii
so:
import curses.ascii
You can find Documentation here:
https://docs.python.org/3/library/curses.ascii.html
I'm new to python, and I was creating a Bot to discord by PyCharm when suddenly there was this giant error below, I already reinstalled python, tried configuring the PATHs for python 3.7 and 3.6, changed IDE and continues giving this error, can anyone help me figure out what's causing this?
error below:
C:\Users\Pichau\AppData\Local\Programs\Python\Python36\python.exe C:/Users/Pichau/Documents/cursos/programacao/Discord/main.py
Traceback (most recent call last):
File "C:/Users/Pichau/Documents/cursos/programacao/Discord/main.py", line 1, in <module>
import discord
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\__init__.py", line 20, in <module>
from .client import Client, AppInfo, ChannelPermissions
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 28, in <module>
from .user import User
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\user.py", line 27, in <module>
from .utils import snowflake_time
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\utils.py", line 31, in <module>
import asyncio
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\asyncio\__init__.py", line 21, in <module>
from .base_events import *
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\asyncio\base_events.py", line 17, in <module>
import concurrent.futures
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\_base.py", line 7, in <module>
import logging
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\logging\__init__.py", line 26, in <module>
import sys, os, time, io, traceback, warnings, weakref, collections
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\linecache.py", line 11, in <module>
import tokenize
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\tokenize.py", line 41, in <module>
__all__ = token.__all__ + ["COMMENT", "tokenize", "detect_encoding",
AttributeError: module 'token' has no attribute '__all__'
Process finished with exit code 1
Image of error
I would check the code, unless it won’t let you, then you should probably put the code in notepad, and save it then delete the file, and try again. It probably is a computer error more then a coding error.
I am getting an exception from scipy whenever I try to import the nltk package. The command and the error looks like this:
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/__init__.py", line 114, in <module>
from nltk.collocations import *
File "/usr/local/lib/python2.7/dist-packages/nltk/collocations.py", line 39, in <module>
from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures
File "/usr/local/lib/python2.7/dist-packages/nltk/metrics/__init__.py", line 16, in <module>
from nltk.metrics.scores import (accuracy, precision, recall, f_measure,
File "/usr/local/lib/python2.7/dist-packages/nltk/metrics/scores.py", line 16, in <module>
from scipy.stats.stats import betai
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/__init__.py", line 344, in <module>
from .stats import *
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/stats.py", line 176, in <module>
from . import distributions
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/distributions.py", line 10, in <module>
from ._distn_infrastructure import (entropy, rv_discrete, rv_continuous,
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/_distn_infrastructure.py", line 43, in <module>
from new import instancemethod
File "new.py", line 107
return copy.deepcopy(self)
^
IndentationError: expected an indented block
I executed this command in a terminal (ubuntu 16.04 LTS system). I did not find anything about this error and the indentation doesn't look wrong.
The SyntaxError is in your file new.py (I guess it's in your current working directory). Try to switch to a directory where no new.py file is present (or move the new.py file in another directory), then the internal scipy import should work without problems.
On the other hand you can just upgrade to scipy 0.19.x. They removed the import there and it should work without problems.
Note that it's always a bad idea to name python files like builtin-modules! That's a common source for exceptions or unexpected behaviour.