GZIP python3 AttributeError: 'module' object has no attribute 'compress' - python-3.x

pipe.setnx(prefix+item[0], gzip.compress(bytes(item[1], 'utf-8')))
I'm trying to compress a file using the gzip python lib on an EC2 instance. I assume that gzip is part of the standard library. However, I get the following error
AttributeError: 'module' object has no attribute 'compress'

I figured out that someone else had added a library called gzip. So, it was defaulting to that one and the not standard library. I ended up using zlib instead.

Related

Using .stem with full path to file in Python 3

How can I get the full path to a file without the file extension using .stem?
I have tried:
from pathlib import Path
for i,file in enumerate(os.listdir(os.environ['onedrive'])):
if file.endswith(".txt"):
print("Full file path without extension using stem:", os.path.realpath(file).stem)
Error:
AttributeError: 'str' object has no attribute 'stem'
perhaps I am calling the path to the file incorrectly, but I am not sure how else.

Create empty directory using Scons

I am trying to add new empty folder into existing project. In SConscript.3dn file I use:
Import('env_rcp')
e = env_rcp.Clone()
# another code ...
e.Execute(e.Mkdir('$RUNTIMEDIR/resources'))
and while building locally I get AttributeError: 'SConsEnvironment' object has no attribute 'Mkdir'
I did try also os.Mkdir('$RUNTIMEDIR/resources'), then I get AttributeError: 'module' object has no attribute 'Mkdir'.
Some import is missing, or should I define Mkdir somehow? In Scons manual I did not find much help
solution is: e.Execute(Mkdir('$RUNTIMEDIR/resources'))

OpenCV2 createBackgroundSubtractorMOG Attribute not found

I am using cv2 version 4.0.0 and python version 3.7.2.
I am trying to subtract Background using this method cv2.createBackgroundSubtractorMOG2() and its working well.
But when I use cv2.createBackgroundSubtractorMOG() its not working its showing me
AttributeError: module 'cv2.cv2' has no attribute
'createBackgroundSubtractorMOG '.
I also tried cv2.BackgroundSubtractorMOG() but i got same error
AttributeError: module 'cv2.cv2' has no attribute
'BackgroundSubtractorMOG'.
and another subtraction method cv2.createBackgroundSubtractorGMG() also not working.
I also refer other stackoverflow answers but I didn't get solution.
MOG2 containts in main opencv repository. MOG and GMG are from opencv_contrib: https://github.com/opencv/opencv_contrib/tree/master/modules/bgsegm
there are two subtraction packages in opencv. BackgroundSubtractorMOG() it's at cv2.bgsegm.BackgroundSubtractorMOG(),to use you must install opencv-contrib-python

AttributeError: 'module' object has no attribute 'mkdirs'

While creating a nested directory in Python 3.6 received following error:
AttributeError: 'module' object has no attribute 'mkdirs'
Sample code:
def create_sample_data():
os.mkdirs("/tmp/lambdadir/ProjectTemp/mynewtest")
f=open("/tmp/lambdadir/ProjectTemp/mynewtest/my_copy.txt","w+")
f.write("This is inside a directory")
f.close()
Please help.
There is no os.mkdirs. Perhaps you meant os.mkdir or os.makedirs instead?
After googling a bit, found that, its a Python version issue.
I changed code from os.mkdirs() to os.makedirs() and it worked.
Details: os module documentation
Credits:
buttscicles - Reddit
In 3.10 when I tried it I faced the same. seems it's not available,
so I used below code.
# The folder should not exist or else will throw FileExistsError
os.mkdir('Parent-folder')
# The parent folder is should be created before , or else throws FileNotFoundError:
os.mkdir('Parent-folder/SubFolder')

AttributeError: 'module' object has no attribute 'sift'

I want to use sift() in python &openCV
here is my environment:
python:2.7.6
os:ubuntu 14.04
opencv:2.4.9
After several hours hard-work, now i seem to successfully install opencv,because i can do as below:
import cv2
print cv2.version ---- 2.4.9
now my problem is that when i want to call cv2.sift(),it says AttributeError: 'module' object has no attribute 'sift'
If i download opencv_contrib from github and use cmake -DOPENCV_EXTRA_MODULES_PATH=/modules , the compiling will fail , it says:
Module opencv_xfeatures2d disabled because opencv_shape dependency can't be resolved!
someone else even says the opencv_contrib can only work with opencv3
then how can i solve this problem? I need your help~

Resources