Create empty directory using Scons - 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'))

Related

Pyinstaller : Kivy: AttributeError: 'NoneType' object has no attribute 'clearcolor'

I am trying to package a kivy based python application for windows using auto-py-to-exe. auto-py-to-exe uses Pyinstaller for packaging. So after packaging the application and trying to run the created executable file of the application, I encounter this error:
File "desktop.py", line 356, in <module>
AttributeError: 'NoneType' object has no attribute 'clearcolor'
which in the actual code in desktop.py refers to:
from kivy.core.window import Window
....something....
if __name__ == "__main__":
.... something
Window.clearcolor = (1, 1, 0.99, 1)
....something
Here I am trying to provide close to white color background to the window.
I have checked for proper installation of kivy and availability of kivy.core.window module in site-packages of python.
I have read at severals places to use the package-name in --hidden-import as sometimes modules may not be picked due incorrect path or other issues, so I have tried passing this module as --hidden-import "kivy.core.window" and also tried --add-data flag as --add-data "C:/Python3/Lib/site-packages/kivy/core/window;window/" to forcefully include kivy.core.window.
However no luck and I still getting the same error.
If I am not mistaken the above mentioned error means the code get Nonetype when it tries to access window although the module is present at right place i.e. after packaging it is present in the package along with other kivy modules.
Also when I run the script from some IDE it works fine.
I have followed this document for debugging the Pyinstaller warnings/errors.
Config: Windows10, Python3.4, kivy 1.11.1
What am I missing or how can I specify executable to look for the file at the correct path?
So after #inclement's comment : to remove the line
After removing this line I get [CRITICAL] [App ] Unable to get a Window, abort. . I have browsed this error and found different solution referring to sdl2.dll here. So I went ahead and added path to .dll files for sdl2, glew and angle in Windows environment variable path PATH = C:\Python3\share\sdl2\bin and so on for glew and angle. So all the .dll files are imported properly and it works fine.
I use this way to solve it:
(If you don't want to find sdl2 bin path, you can use this way.)
pip install pygame
If you use custom spec, you will need to edit it to let pyinstaller rebuild exe.
I don't know how does it work, but it work for me.
(Pygame also use sdl2)
(My env: kivy 2.1.0, pyinstaller 5.1, conda env, python 3.7)
Or like answer above, but use some different way:
# In spec file, modify this line:
a = Analysis(
...
binaries=[(r"Your_env_path\share\sdl2\bin\*.dll", ".")],
...
)
You can also use --add-binary argument.
how to use bundled program after pyinstaller --add-binary?
# In Unix
pyinstaller -w --add-binary="Your_env_path\share\sdl2\bin\*.dll:." -F main.py
# In Window
pyinstaller -w --add-binary="Your_env_path\share\sdl2\bin\*.dll;." -F main.py
Or following official way:
https://kivy.org/doc/stable/guide/packaging-windows.html
"Editor and add these lines at the beginning of the spec"
# In spec file:
from kivy_deps import sdl2, glew
exe = EXE(
...
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
...
)
My english is not good, hoping this conveys the correct meaning.

Dynamically import files from another directory

My input is a list of file names (as a list of variables) and I know the path to these files. Each file has a function called "test" and I have to call the "test" function from each of these files. The path is not my working directory. I need to be able to dynamically import these files.
I tried using importlib, but I get the following errors:
import importlib
importlib.import_module("..\..\foo", package=None)
TypeError: the 'package' argument is required to perform a relative import for '..\\..\\x0coo'
importlib.import_module("C:\Users\Desktop\foo", package=None)
ModuleNotFoundError: No module named 'C:\\Users\\Desktop\\foo'
How would I go about executing the function in a file, using the filename and path (both stored in variables)?
I'm not sure this is the best way, but I solved this by first adding the path to
the module to sys.path:
>>import sys
>>sys.path.append('/path/to/module')
>>mod=importlib.import_module('my_module_name')
then you can call functions in that module like this
>>mod.myfunc(myargs)
or, if you have the function name in a python string like func='myfunctionname'
you can call it like
>>mod.__dict__[func](args)
I'd need to see more code, but my first guess is that you need to replace \ with / in your Directory string, since \ escapes out of the string.

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

GZIP python3 AttributeError: 'module' object has no attribute 'compress'

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.

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