weakref module has no attribute 'weakvaluedictionary' - python

There came up strange error from python today. Whatever i want to launch or do, i can't getting error : 'module' has no attribute 'weakvaluedictionary'.
Even tried to launch pip install/uninstall and got same error.
Nothing has been changed from last day, and yesterday everything was working perfectly.
I checked init.py and did not see anything strange with weakref:
there is import weakref and _handlers = weakref.WeakValueDictionary() #map of handler names to handlers lines.
Please help!!

I was having same issue than you. The problem was that I was naming the file I was trying to run/edit as weakref.py Then, only change the name. I changed name to "weakref_example.py"

Related

I keep getting this error for the colorgram module in Python

I keep getting this error when I am working with colorgram:
Module 'colorgram' has no 'extract' member
Here is my code so far:
import colorgram
colors = colorgram.extract("hirst/hirst.jpg", 84)
Check if you have installed colorgram module.
In PyCharm it is:
PyCharm/Preferences/Project/Python interpreter
If you cant see colorgram module there, use "+" to add it.
You might be passing the incorrect path. I was also getting the same error. I noticed that my dir in VS code terminal was 'C:\Users\user\Desktop\100DaysPythonBootcamp' so when i passed my file name 'image.jpg' it showed error as it was looking for it in the bootcamp folder
in this case you pass the location within you directory i.e
'Day18_Turtle\hriste-painting\image.jpg' (in my case) which was within it then i ran successfully

Pizzapi module for Python not running outside IDLE

So I'm bored and trying to redo old projects. I had worked with the "pizzapi" module for Node.js back around '18 and wanted to try the python version. I did a few tests in IDLE with good results but when I made a new file to run all the code from, the module isn't adding any of the functions. At first I thought it was an issue with scope but I boiled it down to it's most basic part and realized it's just not adding any of the classes. I changed it to this
from pizzapi import *
customer = Customer("First", "Last", "email#email.com", "18008675309")
and got
NameError: name 'Customer' is not defined
So I changed to
import pizzapi
customer = pizzapi.Customer("First", "Last", "email#email.com", "18008675309")
and get the error
AttributeError: module 'pizzapi' has no attribute 'Customer'
If anyone can help with this, I am using Python Version 3.6.4 and Pizzapi 0.0.6, I would greatly appreciate it.

Problems when converting from imp to importlib in python 3.4

I've made a Python application which can load plugins. These plugins are loaded based on a name and path.
I am currently using
pluginModule = imp.load_source(pluginModuleName, pluginModulePath)
and then getting a class instance in the module this way
# Load the module class and initialize it.
if hasattr(pluginModule, pluginClassName):
try:
pluginClassInst = getattr(pluginModule, pluginClassName)()
except Exception as e:
errorMsg = ('In plugin module [{}], {}'.format(os.path.basename(pluginModulePath), e))
exceptionTracePrint(self._log)
self._log.error(errorMsg)
continue
Since the imp lib is deprecated I want to use importlib. And the only similar method of getting my class instance was to use
pluginModule = importlib.machinery.SourceFileLoader(pluginModuleName, pluginModulePath).load_module()
The weird thing here is that (I am using pyCharm as IDE). when I run my code in debugging mode the above command works fine and I get my class instance. however running the code normally gives me the following error.
pluginModule = importlib.machinery.SourceFileLoader(pluginModuleName, pluginModulePath).load_module()
AttributeError: 'module' object has no attribute 'machinery'
Why is there a difference between run and debug.
Is there an alternative way of doing what I want.
Ive also tried
pluginModuleTmp = importlib.util.spec_from_file_location(pluginModuleName, pluginModulePath)
Which also gives me the correct data however I cannot load the module this way or at least I do not know how
Regards
Anders
Found the solution. Apparently in debug mode a lot more modules are imported behind my back. I fixed it by adding the import.
import importlib.machinery
Regards
Anders

An odd issue with copy module and Sublime Text2

Something strange is happening. I am getting an error when running this code in Sublime Text 2 while the code is valid elsewhere.
import copy
s = 'string'
cs = copy.copy(s)
print s == cs
I got the TypeError: 'module' object is not callable
Also, copy.deepcopy() throws an error AttributeError: 'module' object has no attribute 'deepcopy' while running inside of ST2.
I am aware this is the ST2 specific problem, but maybe some of you know whether this can be solved?
It looks like you've masked the built-in copy module my adding your own copy module somewhere in the module search path used by sublimetext2.
To fix that rename your copy.py file to something else and also delete the copy.pyc file.
The location of the file can be found using __file__ attribute of the module object.
import copy
print copy.__file__
In future please don't name your modules or packages same as python built-in modules, otherwise you'll face same issues.

python uuid weird bug

I first tried with the interpreter to produce uuid's with python's uuid module. I did the following:
>>>import uuid
>>>uuid.uuid1()
UUID('d8904cf8-48ea-11e0-ac43-109add570b60')
So far so good. I create a simple little function to produce the uuid's.
import uuid
def get_guid():
return uuid.uuid1()
if __name__ == '__main__':
print get_guid()
and I get the following error:
AttributeError: 'module' object has no attribute 'uuid1'
Ok...hmm...go back to the interpreter and now it too is broken. I get the same error running the same code I used to test this. I am baffled. What makes uuid break like this? And what is wrong with my code?
I am using python 2.6
Your test file name is most likely named uuid.py
When you went back to the interpreter, you launched the interpreter from the same directory, which by default, will first look for the module name to import in your current working directory.
Just change your test file name to something else, i.e. uuid_test_snippet.py

Categories