AttributeError: 'module' object has no attribute 'mkdirs' - python-3.x

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')

Related

Python AttributeError: module 'os' has no attribute 'exit'

I'm using Python 3.9.12 and I get error in the following line
os.exit()
the Error message is: AttributeError: module 'os' has no attribute 'exit'
os.exit() is not and was not a method of the os module.
You may confuse it with os._exit() or sys.exit()
make sure variable os not been overwrited, like filename or varable name ...
As from comment, exit is a built-in. So os.exit() becomes exit()

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'))

'SalesforceBulk' object has no attribute 'post_bulk_batch'

I'm trying to run a bulk job in salesforce. After creating job and prepared csv_iterator through my data, when i ran this
batch = bulk.post_bulk_batch(job, csv_iterator)
I'm getting the error stating
AttributeError: 'SalesforceBulk' object has no attribute 'post_bulk_batch'
I've installed salesforce_bulk in python2 and 3 as well. Tried in both versions, but same error.
Why is this happens. How to rectify this issue? Thanks in advance.
UPDATE:
I have installed the version salesforce-bulk==1.1.0
Now it is working in python2 but in python3 this is what happening
from salesforce_bulk import SalesforceBulk
ImportError: cannot import name 'SalesforceBulk'
Is there no support for python 3 to do salesforce bulk job process?
Found it! In python3 install version salesforce-bulk == 2.1.0 and change the method name post_bulk_batch to post_batch
That's it do the trick!

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 '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