Can someone help me understand this error: - python

I never know how to read these. It would be helpful if someone could help me understand this one, and maybe give advice on how to read these in general?
D:\>python captain2.py
Traceback (most recent call last):
File "captain2.py", line 2, in <module>
from twisted.internet import reactor
File "c:\Python27\lib\site-packages\twisted\internet\reactor.py", line 37, in
<module>
from twisted.internet import default
File "c:\Python27\lib\site-packages\twisted\internet\default.py", line 50, in
<module>
install = _getInstallFunction(platform)
File "c:\Python27\lib\site-packages\twisted\internet\default.py", line 46, in
_getInstallFunction
from twisted.internet.selectreactor import install
File "c:\Python27\lib\site-packages\twisted\internet\selectreactor.py", line 1
4, in <module>
from zope.interface import implements
ImportError: No module named zope.interface

In a stack traceback, Python lists the current call stack, in the order the calls happened. So, first your code in captain2.py:
from twisted.internet import reactor
Then the reactor module did:
from twisted.internet import default
and so on, until selectreactor.py did:
from zope.interface import implements
and apparently there does not exist a zope.interface module on your system.

Related

Install module cbpro throws multiple errors in several other projects (python 3.10, pycharm)

I have made a few projects which run fine. A new project required me to install pip install cbpro (a module for dealing with coinbase cryptocurrency API).
After installing it, even running the simplest code throws several errors:
Input:
import cbpro
import pandas as pd
c = cbpro.PublicClient()
data = pd.DataFrame(c.get_products())
data.tail().T
Errors:
Traceback (most recent call last):
File "/Users/me/PycharmProjects/stonks/coinbase_interface.py", line 1, in <module>
import cbpro
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cbpro/__init__.py", line 1, in <module>
from cbpro.authenticated_client import AuthenticatedClient
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cbpro/authenticated_client.py", line 10, in <module>
import requests
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/__init__.py", line 63, in <module>
from . import utils
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/utils.py", line 29, in <module>
from .cookies import RequestsCookieJar, cookiejar_from_dict
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/cookies.py", line 174, in <module>
class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'
Secondly, when I then go to other projects that were working well, I get additional errors. Of note, those projects start with:
import pandas as pd
import requests
import json
Errors:
Traceback (most recent call last):
File "/Users/me/PycharmProjects/stonks/historical_crypto_pull.py", line 2, in <module>
import requests
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/__init__.py", line 63, in <module>
from . import utils
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/utils.py", line 29, in <module>
from .cookies import RequestsCookieJar, cookiejar_from_dict
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/cookies.py", line 174, in <module>
class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'
Things I've tried:
If I uninstall cbpro, then uninstall and reinstall requests, I can undo the error and am back where I started. However, I'm interested in knowing why I am encountering these errors because I'd like to actually use cbpro and know how to solve this issue in the future.
The libraries I was using were not compatible with Python 3.10. I am still at a loss for how I would inherently know that based on the errors thrown, but since then my solution was to install Python 3.9 and see if I still get the same errors when running 3.9.
(Then I also read that it might be a better idea for my current purposes to use a slightly older version of Python, so I moved over to 3.9 completely and haven't had the same issue again.)

functools has no attribute lru_cache

I'm using Python 3.7 on my Windows
This error occurs while running every code:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import nltk
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\site-packages\nltk\__init__.py", line 99, in <module>
from nltk.internals import config_java
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\site-packages\nltk\internals.py", line 11, in <module>
import subprocess
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 50, in <module>
import signal
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\signal.py", line 3, in <module>
from functools import wraps as _wraps
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\functools.py", line 21, in <module>
from collections import namedtuple
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\collections\__init__.py", line 22, in <module>
from keyword import iskeyword as _iskeyword
File "C:\Users\HP\Desktop\tweepy\keyword.py", line 1, in <module>
import re
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\re.py", line 297, in <module>
#functools.lru_cache(_MAXCACHE)
AttributeError: module 'functools' has no attribute 'lru_cache'
How to fix it?
It looks like someone published a functools package on pypi, so if you had run:
# don't run this!
pip install functools
You may have accidentally installed that package. If you encounter this error, I would:
pip uninstall functools
To make sure that the functools you are using are the base package functools.
(I ended up here because I attempted to use functools.cache, which seems to only be present in Python 3.8, not earlier.)
I had the same error recently and it was because I had a file called functools.py in my project. Renaming it fixed the issue.

Random errors in Anaconda3

C:\Users\jesper>pip Traceback (most recent call last): File
"D:\Anaconda3\Scripts\pip-script.py", line 3, in <module>
import pip File "D:\Anaconda3\lib\site-packages\pip\__init__.py", line 14, in <module>
from pip.utils import get_installed_distributions, get_prog File "D:\Anaconda3\lib\site-packages\pip\utils\__init__.py", line 22, in
<module>
from pip.compat import console_to_str, expanduser, stdlib_pkgs File "D:\Anaconda3\lib\site-packages\pip\compat\__init__.py", line 11,
in <module>
from logging.config import dictConfig as logging_dictConfig File "D:\Anaconda3\lib\logging\config.py", line 30, in <module>
import logging.handlers File "D:\Anaconda3\lib\logging\handlers.py", line 26, in <module>
import logging, socket, os, pickle, struct, time, re File "D:\Anaconda3\lib\socket.py", line 123, in <module>
class socket(_socket.socket): TypeError: __weakref__ slot disallowed: either we already got one, or __itemsize__ != 0
I get this now, and it happened randomly and keeps recurring. I can't use Python at the moment. I tried re-installing the entire conda library and tried different locations for Anaconda. Even tried installing Anaconda for 2.7 and it still didn't work. If someone knows how to fix I'd be in there eternal debt. Thanks!

Python 2.5.4 ImportError: No module named collections

I'm fairly new to Python, and I don't understand what is going on here.
C:\Users\Mike\Desktop>storytext testGui.py
Traceback (most recent call last):
File "C:\Python25\Scripts\storytext.py", line 19, in <module>
from storytext.cmdline import main
File "C:\Python25\lib\site-packages\storytext-3.7-py2.5.egg\storytext\cmdline.py", line 3, in <module>
import scriptengine, definitions
File "C:\Python25\lib\site-packages\storytext-3.7-py2.5.egg\storytext\scriptengine.py", line 4, in
<module>
import recorder, replayer
File "C:\Python25\lib\site-packages\storytext-3.7-py2.5.egg\storytext\recorder.py", line 6, in <module>
from replayer import ReplayScript
File "C:\Python25\lib\site-packages\storytext-3.7-py2.5.egg\storytext\replayer.py", line 5, in <module>
from threading import Thread, Timer
File "C:\Python25\lib\threading.py", line 13, in <module>
from collections import deque
ImportError: No module named collections
Ok, no Module named collections. Indeed, when I search my python25 folder for collections, it's not there. I've read that it's located at Modules/_collectionsmodule.c, which I also can't find.
The kicker to the whole thing is that I can import collections from the interpreter, and I can from threading import Time, Timer in the interpreter.
I do have both python 2.5 and 2.6 on this machine, and it's running Windows 7.
Can anyone point me in the right direction?

Has Twisted changed its dependencies?

I'm currently working on a Python/Twisted project which is to be distributed and tested on Planetlab. For some reason my code was working on friday and now that I wanted to test a minor change it refuses to work at all:
Traceback (most recent call last):
File "acn_a4/src/node.py", line 6, in <module>
from twisted.internet.protocol import DatagramProtocol
File "/usr/lib/python2.5/site-packages/Twisted-10.0.0-py2.5-linux-i686.egg/twisted/__init__.py", line 18, in <module>
from twisted.python import compat
File "/usr/lib/python2.5/site-packages/Twisted-10.0.0-py2.5-linux-i686.egg/twisted/python/compat.py", line 146, in <module>
import operator
File "/home/cdecker/dev/acn/acn_a4/src/operator.py", line 7, in <module>
File "/home/cdecker/acn_a4/src/node.py", line 6, in <module>
from twisted.internet.protocol import DatagramProtocol
File "/usr/lib/python2.5/site-packages/Twisted-10.0.0-py2.5-linux-i686.egg/twisted/internet/protocol.py", line 20, in <module>
from twisted.python import log, failure, components
File "/usr/lib/python2.5/site-packages/Twisted-10.0.0-py2.5-linux-i686.egg/twisted/python/log.py", line 19, in <module>
from twisted.python import util, context, reflect
File "/usr/lib/python2.5/site-packages/Twisted-10.0.0-py2.5-linux-i686.egg/twisted/python/util.py", line 5, in <module>
import os, sys, hmac, errno, new, inspect, warnings
File "/usr/lib/python2.5/inspect.py", line 32, in <module>
from operator import attrgetter
ImportError: cannot import name attrgetter
And since I'm pretty new to python I have no idea what could have caused this problem.
All suggestions are welcome :-)
One of your own files, /home/cdecker/dev/acn/acn_a4/src/operator.py shadows Python's builtin operator module. You should rename your own operator.py to something else.
You can see the problem here:
File "/usr/lib/python2.5/site-packages/Twisted-10.0.0-py2.5-linux-i686.egg/twisted/python/compat.py", line 146, in <module>
import operator
File "/home/cdecker/dev/acn/acn_a4/src/operator.py", line 7, in <module>
Twisted tries to import operator but Python loads one of your own modules.
To prevent stuff like that in the future you should probably not add your src folder to the PYTHONPATH like that. Create a package instead, so that your own files appear as myproject.mymodule and can't shadow builtins.
ImportError is raised on import statement when a name cannot be imported, because module or package or name doesn't exists. In your case attrgetter doesn't exists in operator module.
The first idea is that you define a module called operator in the project's main directory. Modules, or packages, are searched following sys.path order, if you define a module with the same name in your main directory, you are hiding all others module with the same name in the search path.

Categories

Resources