I have a situation very much like the one at Error “ImportError: DLL load failed: %1 is not a valid Win32 application”, but the answer there isn’t working for me. My Python code says: But that line throws the error shown in the title of this question. I have OpenCV installed in C:libopencv on this 64-bit machine. I’m using 64-bit
Tag: path
A system independent way using python to get the root directory/drive on which python is installed
For Linux this would give me /, for Windows on the C drive that would give me C:\. Note that python is not necessarily installed on the C drive on windows. Answer You can get the path to the Python executable using sys.executable: Then, for Windows, the drive letter will be the first part of splitdrive:
How to know the directory where the python script is called?
Let’s say that I have a python script a.py in /A/B/a.py, and it’s in the PATH environment variable. The current working directory is /X/Y/, and it’s the directory where I call the /A/B/a.py. In a.py, how to detect /X/Y/? I mean, how to know in which directory the python call is made? Answer You can get the current working directory
Find full path of the Python interpreter?
How do I find the full path of the currently running Python interpreter from within the currently executing Python script? Answer sys.executable contains full path of the currently running Python interpreter. which is now documented here
How to use glob() to find files recursively?
This is what I have: but I want to search the subfolders of src. Something like this would work: But this is obviously limited and clunky. Answer pathlib.Path.rglob Use pathlib.Path.rglob from the pathlib module, which was introduced in Python 3.5. If you don’t want to use pathlib, use can use glob.glob(‘**/*.c’), but don’t forget to pass in the recursive keyword
Relative paths in Python [duplicate]
This question already has answers here: How do you properly determine the current script directory? (16 answers) Closed 6 months ago. I’m building a simple helper script for work that will copy a couple of template files in our code base to the current directory. I don’t, however, have the absolute path to the directory where the templates are stored.