Why is this happening?
python --version = 2.7.1
import urllib
def main():
urllib.urlretrieve('http://media2.apnonline.com.au/img/media/images/2011/02/28/apple-logo_fct825x508x16_t460.jpg', 'image.jpg')
if __name__ == '__main__':
main()
Trace:
Traceback (most recent call last):
File "robot.py", line 7, in <module>
main()
File "robot.py", line 4, in main
urllib.urlretrieve('http://media2.apnonline.com.au/img/media/images/2011/02/28/apple-logo_fct825x508x16_t460.jpg', 'image.jpg')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 91, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 237, in retrieve
fp = self.open(url, data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 205, in open
return getattr(self, name)(url)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 289, in open_http
import httplib
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 79, in <module>
import mimetools
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
import tempfile
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 34, in <module>
from random import Random as _Random
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 45, in <module>
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
ImportError: cannot import name log
Is it possible that you have a file named math.py in the same directory as the program you are running? If so python tries to import it before the math module.
Solution: Just rename it to something else.
Tip: In the future try to name your modules in a non-conflicting way.
Related
I want to use a numpy function in an Anki addon that I am forking, but it returns an error when I run Anki (error below). I guess it is because I am using import numpy. So how I can use a numpy function when the package is not in the original code in the addon. Should I install the package first? If yes, how? Because pip install doesn't work in the code and I should probably install package in an environment.
Caught exception:
Traceback (most recent call last):
File "aqt\progress.py", line 54, in handler
File "aqt\main.py", line 149, in on_window_init
File "aqt\main.py", line 197, in setupProfileAfterWebviewsLoaded
File "aqt\main.py", line 244, in setupProfile
File "aqt\main.py", line 425, in loadProfile
File "aqt\hooks_gen.py", line 2985, in __call__
File "anki\hooks.py", line 34, in runHook
File "C:\Users\saeed\AppData\Roaming\Anki2\addons21\1807206748\__init__.py", line 37, in start_here
from . import common as fastwq
File "C:\Users\saeed\AppData\Roaming\Anki2\addons21\1807206748\common.py", line 29, in <module>
from .gui import show_about_dialog, show_options # , check_updates
File "C:\Users\saeed\AppData\Roaming\Anki2\addons21\1807206748\gui\__init__.py", line 3, in <module>
from .common import *
File "C:\Users\saeed\AppData\Roaming\Anki2\addons21\1807206748\gui\common.py", line 28, in <module>
from ..service import service_manager, service_pool
File "C:\Users\saeed\AppData\Roaming\Anki2\addons21\1807206748\service\__init__.py", line 24, in <module>
service_manager = ServiceManager() # Service Manager
File "C:\Users\saeed\AppData\Roaming\Anki2\addons21\1807206748\service\manager.py", line 35, in __init__
self.update_services()
File "C:\Users\saeed\AppData\Roaming\Anki2\addons21\1807206748\service\manager.py", line 43, in update_services
self.web_services, self.local_custom_services = self._get_services_from_files()
File "C:\Users\saeed\AppData\Roaming\Anki2\addons21\1807206748\service\manager.py", line 78, in _get_services_from_files
module = importlib.import_module(
File "C:\Users\saeed\AppData\Roaming\Anki2\addons21\1807206748\utils\importlib.py", line 43, in import_module
__import__(name)
File "C:\Users\saeed\AppData\Roaming\Anki2\addons21\1807206748\service\dict\frdic.py", line 8, in <module>
import numpy
ModuleNotFoundError: No module named 'numpy'
I'm new to APIs and am following the exact instructions of every website explaining how one is supposed to get help of the APIs in Python using the requests module. However, no matter what API link I define (of course I went for many free API samples just to test if they work), I get this error: ImportError: cannot import name 'b64encode' from 'base64'
I have no idea what the problem is, or what I'm not getting right.
Here's my snippet, just as a sample:
import requests
words = 30
paragraphs = 1
formats = 'text'
response = requests.get(f"https://v2.jokeapi.dev/")
print(response.text)
The complete error I get is like so:
Traceback (most recent call last):
File "/home/liana/Desktop/testing.py", line 1, in <module>
import requests
File "/usr/lib/python3/dist-packages/requests/__init__.py", line 43, in <module>
import urllib3
File "/usr/lib/python3/dist-packages/urllib3/__init__.py", line 11, in <module>
from . import exceptions
File "/usr/lib/python3/dist-packages/urllib3/exceptions.py", line 3, in <module>
from six.moves.http_client import IncompleteRead as httplib_IncompleteRead
File "/usr/lib/python3/dist-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/lib/python3/dist-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/lib/python3/dist-packages/six.py", line 82, in _import_module
__import__(name)
File "/usr/lib/python3.9/http/client.py", line 71, in <module>
import email.parser
File "/usr/lib/python3.9/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/usr/lib/python3.9/email/feedparser.py", line 27, in <module>
from email._policybase import compat32
File "/usr/lib/python3.9/email/_policybase.py", line 7, in <module>
from email import header
File "/usr/lib/python3.9/email/header.py", line 17, in <module>
import email.base64mime
File "/usr/lib/python3.9/email/base64mime.py", line 37, in <module>
from base64 import b64encode
ImportError: cannot import name 'b64encode' from 'base64' (/home/liana/Desktop/base64.py)
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 72, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 21, in <module>
from urllib.request import urlopen
File "/usr/lib/python3.9/urllib/request.py", line 88, in <module>
import http.client
File "/usr/lib/python3.9/http/client.py", line 71, in <module>
import email.parser
File "/usr/lib/python3.9/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/usr/lib/python3.9/email/feedparser.py", line 27, in <module>
from email._policybase import compat32
File "/usr/lib/python3.9/email/_policybase.py", line 7, in <module>
from email import header
File "/usr/lib/python3.9/email/header.py", line 17, in <module>
import email.base64mime
File "/usr/lib/python3.9/email/base64mime.py", line 37, in <module>
from base64 import b64encode
ImportError: cannot import name 'b64encode' from 'base64' (/home/liana/Desktop/base64.py)
Original exception was:
Traceback (most recent call last):
File "/home/liana/Desktop/testing.py", line 1, in <module>
import requests
File "/usr/lib/python3/dist-packages/requests/__init__.py", line 43, in <module>
import urllib3
File "/usr/lib/python3/dist-packages/urllib3/__init__.py", line 11, in <module>
from . import exceptions
File "/usr/lib/python3/dist-packages/urllib3/exceptions.py", line 3, in <module>
from six.moves.http_client import IncompleteRead as httplib_IncompleteRead
File "/usr/lib/python3/dist-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/lib/python3/dist-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/lib/python3/dist-packages/six.py", line 82, in _import_module
__import__(name)
File "/usr/lib/python3.9/http/client.py", line 71, in <module>
import email.parser
File "/usr/lib/python3.9/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/usr/lib/python3.9/email/feedparser.py", line 27, in <module>
from email._policybase import compat32
File "/usr/lib/python3.9/email/_policybase.py", line 7, in <module>
from email import header
File "/usr/lib/python3.9/email/header.py", line 17, in <module>
import email.base64mime
File "/usr/lib/python3.9/email/base64mime.py", line 37, in <module>
from base64 import b64encode
ImportError: cannot import name 'b64encode' from 'base64' (/home/liana/Desktop/base64.py)
Any help is appreciated.
If you look carefully at the traceback, you will see that it starts with your script, "/home/liana/Desktop/testing.py", goes through a chain of imports, and ends up crashing trying to import b64encode from base64.py.
The file /home/liana/Desktop/base64.py is something you either created or downloaded. Since it's in the current directory, it supersedes the real base64.py that "/usr/lib/python3.9/email/base64mime.py" is looking for. The file in your current directory clearly does not define the name b64encode, which is the immediate cause of the error.
To fix the problem, make sure the names of the files in your current directory don't conflict with the names of other top level modules. So either rename it delete /home/liana/Desktop/base64.py.
I'm trying to run Python behave tests but get the following error:
[moadmin#modevvm12 e2e-tests]$ behave -i features/tests/connmgr_2_scan_management_container.feature
Exception ImportError: No module named request
Traceback (most recent call last):
File "/usr/bin/behave", line 11, in <module>
sys.exit(main())
File "/usr/lib/python2.7/site-packages/behave/__main__.py", line 183, in main
return run_behave(config)
File "/usr/lib/python2.7/site-packages/behave/__main__.py", line 127, in run_behave
failed = runner.run()
File "/usr/lib/python2.7/site-packages/behave/runner.py", line 804, in run
return self.run_with_paths()
File "/usr/lib/python2.7/site-packages/behave/runner.py", line 808, in run_with_paths
self.load_hooks()
File "/usr/lib/python2.7/site-packages/behave/runner.py", line 784, in load_hooks
exec_file(hooks_path, self.hooks)
File "/usr/lib/python2.7/site-packages/behave/runner_util.py", line 386, in exec_file
exec(code, globals_, locals_)
File "features/environment.py", line 20, in <module>
from framework.sd.api.auth_rbac import AuthRBAC
File "/tmp/e2e-tests/framework/sd/api/auth_rbac.py", line 10, in <module>
from framework.sd.api.sd_endpoint import SDEndpoint
File "/tmp/e2e-tests/framework/sd/api/sd_endpoint.py", line 12, in <module>
import urllib.request, urllib.parse, urllib.error
ImportError: No module named request
urllib is installed so I can't understand why I get this error.
I am still getting this error: An error occurred while starting the kernel
Things I tried:
setuptools command
updating spyder
Uninstalled everything that had word python in it from Uninstall or change progam panel
Uninstalling and reinstalling anaconda
Reading people's response on how they tried to fix it
Tried not to get frustrated.
This started occurring after I updated the spyder which I shouldn't have, but now I am stuck with the issue. I will share the complete message that's coming up on my IPhython Console screen.
Traceback (most recent call last):
File "C:\Users\afsan\Anaconda3\lib\site‑packages\spyder\utils\ipython\start_kernel.py", line 245, in
main()
File "C:\Users\afsan\Anaconda3\lib\site‑packages\spyder\utils\ipython\start_kernel.py", line 213, in main
from ipykernel.kernelapp import IPKernelApp
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\ipykernel\__init__.py", line 2, in
from .connect import *
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\ipykernel\connect.py", line 18, in
import jupyter_client
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\jupyter_client\__init__.py", line 4, in
from .connect import *
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\jupyter_client\connect.py", line 22, in
import zmq
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\__init__.py", line 34, in
from zmq import backend
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\__init__.py", line 40, in
reraise(*exc_info)
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\utils\sixcerpt.py", line 34, in reraise
raise value
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\__init__.py", line 27, in
_ns = select_backend(first)
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\select.py", line 26, in select_backend
mod = __import__(name, fromlist=public_api)
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\cython\__init__.py", line 6, in
from . import (constants, error, message, context,
ImportError: cannot import name 'constants'
Traceback (most recent call last):
File "C:\Users\afsan\Anaconda3\lib\site‑packages\spyder\utils\ipython\start_kernel.py", line 245, in
main()
File "C:\Users\afsan\Anaconda3\lib\site‑packages\spyder\utils\ipython\start_kernel.py", line 213, in main
from ipykernel.kernelapp import IPKernelApp
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\ipykernel\__init__.py", line 2, in
from .connect import *
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\ipykernel\connect.py", line 18, in
import jupyter_client
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\jupyter_client\__init__.py", line 4, in
from .connect import *
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\jupyter_client\connect.py", line 22, in
import zmq
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\__init__.py", line 34, in
from zmq import backend
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\__init__.py", line 40, in
reraise(*exc_info)
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\utils\sixcerpt.py", line 34, in reraise
raise value
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\__init__.py", line 27, in
_ns = select_backend(first)
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\select.py", line 26, in select_backend
mod = __import__(name, fromlist=public_api)
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\cython\__init__.py", line 6, in
from . import (constants, error, message, context,
ImportError: cannot import name 'constants'
Traceback (most recent call last):
File "C:\Users\afsan\Anaconda3\lib\site‑packages\spyder\utils\ipython\start_kernel.py", line 245, in
main()
File "C:\Users\afsan\Anaconda3\lib\site‑packages\spyder\utils\ipython\start_kernel.py", line 213, in main
from ipykernel.kernelapp import IPKernelApp
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\ipykernel\__init__.py", line 2, in
from .connect import *
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\ipykernel\connect.py", line 18, in
import jupyter_client
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\jupyter_client\__init__.py", line 4, in
from .connect import *
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\jupyter_client\connect.py", line 22, in
import zmq
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\__init__.py", line 34, in
from zmq import backend
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\__init__.py", line 40, in
reraise(*exc_info)
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\utils\sixcerpt.py", line 34, in reraise
raise value
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\__init__.py", line 27, in
_ns = select_backend(first)
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\select.py", line 26, in select_backend
mod = __import__(name, fromlist=public_api)
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\cython\__init__.py", line 6, in
from . import (constants, error, message, context,
ImportError: cannot import name 'constants'
Traceback (most recent call last):
File "C:\Users\afsan\Anaconda3\lib\site‑packages\spyder\utils\ipython\start_kernel.py", line 245, in
main()
File "C:\Users\afsan\Anaconda3\lib\site‑packages\spyder\utils\ipython\start_kernel.py", line 213, in main
from ipykernel.kernelapp import IPKernelApp
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\ipykernel\__init__.py", line 2, in
from .connect import *
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\ipykernel\connect.py", line 18, in
import jupyter_client
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\jupyter_client\__init__.py", line 4, in
from .connect import *
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\jupyter_client\connect.py", line 22, in
import zmq
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\__init__.py", line 34, in
from zmq import backend
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\__init__.py", line 40, in
reraise(*exc_info)
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\utils\sixcerpt.py", line 34, in reraise
raise value
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\__init__.py", line 27, in
_ns = select_backend(first)
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\select.py", line 26, in select_backend
mod = __import__(name, fromlist=public_api)
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\cython\__init__.py", line 6, in
from . import (constants, error, message, context,
ImportError: cannot import name 'constants'
Traceback (most recent call last):
File "C:\Users\afsan\Anaconda3\lib\site‑packages\spyder\utils\ipython\start_kernel.py", line 245, in
main()
File "C:\Users\afsan\Anaconda3\lib\site‑packages\spyder\utils\ipython\start_kernel.py", line 213, in main
from ipykernel.kernelapp import IPKernelApp
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\ipykernel\__init__.py", line 2, in
from .connect import *
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\ipykernel\connect.py", line 18, in
import jupyter_client
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\jupyter_client\__init__.py", line 4, in
from .connect import *
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\jupyter_client\connect.py", line 22, in
import zmq
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\__init__.py", line 34, in
from zmq import backend
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\__init__.py", line 40, in
reraise(*exc_info)
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\utils\sixcerpt.py", line 34, in reraise
raise value
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\__init__.py", line 27, in
_ns = select_backend(first)
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\select.py", line 26, in select_backend
mod = __import__(name, fromlist=public_api)
File "C:\Users\afsan\AppData\Local\Programs\Python\Python36\Lib\site‑packages\zmq\backend\cython\__init__.py", line 6, in
from . import (constants, error, message, context,
ImportError: cannot import name 'constants'
The problem is that you have two Python versions installed:
C:\Users\afsan\Anaconda3\
C:\Users\afsan\AppData\Local\Programs\Python\Python36
Given that it seems you want to use Spyder with Anaconda, please remove your second Python version (manually, if necessary). That should fix your problem.
I am calling a python script from another python script,irrespective of the output the python script I am calling I get the following error in stderr,I googled but couldn't find anything concrete,am clueless as to why am getting this error?does anyone have any idea on how to fix it?
Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 151, in _run_module_as_main
mod_name, loader, code, fname = _get_module_details(mod_name)
File "C:\Python27\lib\runpy.py", line 109, in _get_module_details
return _get_module_details(pkg_main_name)
File "C:\Python27\lib\runpy.py", line 101, in _get_module_details
loader = get_loader(mod_name)
File "C:\Python27\lib\pkgutil.py", line 464, in get_loader
return find_loader(fullname)
File "C:\Python27\lib\pkgutil.py", line 474, in find_loader
for importer in iter_importers(fullname):
File "C:\Python27\lib\pkgutil.py", line 430, in iter_importers
__import__(pkg)
File "C:\Python27\lib\site-packages\pip\__init__.py", line 14, in <module>
from pip.utils import get_installed_distributions, get_prog
File "C:\Python27\lib\site-packages\pip\utils\__init__.py", line 27, in <module>
from pip._vendor import pkg_resources
File "C:\Python27\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 35,
import email.parser
File "C:\Python27\lib\email\parser.py", line 12, in <module>
from email.feedparser import FeedParser
File "C:\Python27\lib\email\feedparser.py", line 27, in <module>
from email import message
File "C:\Python27\lib\email\message.py", line 16, in <module>
import email.charset
File "C:\Python27\lib\email\charset.py", line 13, in <module>
import email.base64mime
File "C:\Python27\lib\email\base64mime.py", line 40, in <module>
from email.utils import fix_eols
File "C:\Python27\lib\email\utils.py", line 27, in <module>
import random
File "C:\Python27\lib\random.py", line 49, in <module>
import hashlib as _hashlib
File "C:\Python27\lib\hashlib.py", line 138, in <module>
_hashlib.openssl_md_meth_names)
AttributeError: 'module' object has no attribute 'openssl_md_meth_names'
Try to run brew cleanup and after that brew postinstall python.
For more info see this thread