Darknet attribute error on Windows. Something wrong with the DLL? - python

I am attempting to run a python file, darknet_video.py (or any python file) on Windows 10.
While running on linux I have had no problems using the .SO in exactly the same way. However, I am forced to have to port this to Windows and use the DLL.
I have compiled yolo_cpp_dll.sln with Visual Studio 17. No errors. On the command line, I can invoke darknet with, say,
./darknet.exe detector test cfg/coco.data cfg/yolov3.cfg yolov3.weights -thresh 0.25
The above works.
What does not work is the following:
python.exe darknet_video.py --data_file cfg/coco.data cfg/yolov3.cfg/yolov3.weights ..
With the above I get the following
Traceback (most recent call last):
File "darknet_video.py", line 119, in
network, class_names, class_colors = darknet.load_network(
AttributeError: module 'darknet' has no attribute 'load_network'
This type of error is the same no matter what kind of a python file I use.
I am certainly not an expert in using Windows DLLs but if I had to guess I would say that somehow the DLL was compiled in such a way that it can not understand calls such as "load_network" or any other type of call that is made.
How to proceed?
Thank You
Tom

If you compiled yolo_cpp_dll.sln correctly you
would get yolo_cpp_dll.dll then in darknet.py
change lib= CDLL('whatever') to
lib = CDLL("yolo_cpp_dll.dll", RTLD_GLOBAL).

Related

How do I avoid an ELFCLASS64 error when building Android 8 from source?

I have an old tablet I'm toying around with for the fun of it. I'm trying to build Android 8 from source just to tinker with it and see if I can install it on the tablet. I'm using Lubuntu 20.04 LTS.
So far, all I've done is set up my environment, sync to the android-8.1.0_r81 repo, and run m, all per the instructions here: https://source.android.com/setup
My tablet uses an ARMv7 processor, so when I ran lunch I chose aosp_arm-eng, which corresponds to a generic 32-bit ARMv7 processor.
However, when I run m, it eventually fails with the following error:
[ 0% 1/9730] build out/target/product/generic/obj/ETC/sepolicy_tests_intermediates/sepolicy_tests
FAILED: out/target/product/generic/obj/ETC/sepolicy_tests_intermediates/sepolicy_tests
/bin/bash -c "(python out/host/linux-x86/bin/sepolicy_tests.py -l out/host/linux-x86/lib64 -f out/target/product/generic/obj/ETC/plat_file_contexts_intermediates/plat_file_contexts -f out/target/product/generic/obj/ETC/nonplat_file_contexts_intermediates/nonplat_file_contexts -p out/target/product/generic/obj/ETC/sepolicy_intermediates/sepolicy ) && (touch out/target/product/generic/obj/ETC/sepolicy_tests_intermediates/sepolicy_tests )"
Traceback (most recent call last):
File "out/host/linux-x86/bin/sepolicy_tests.py", line 73, in <module>
pol = policy.Policy(options.policy, options.file_contexts, options.libpath)
File "/home/username/Android/Development/Oreo/out/host/linux-x86/bin/policy.py", line 255, in __init__
self.__InitLibsepolwrap(LibPath)
File "/home/username/Android/Development/Oreo/out/host/linux-x86/bin/policy.py", line 190, in __InitLibsepolwrap
lib = CDLL(LibPath + "/libsepolwrap.so")
File "/home/username/Android/Development/Oreo/prebuilts/python/linux-x86/2.7.5/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: out/host/linux-x86/lib64/libsepolwrap.so: wrong ELF class: ELFCLASS64
...
From what I understand, the out directory is the output of the make command--out isn't in the original repo. I also understand (I think) that the wrong ELF class: ELFCLASS64 error means that the libsepolwrap.so library is expecting a 32-bit OS and getting a 64-bit one. What I don't understand is why libsepolwrap.so is expecting a 32-bit OS.
According to the docs,
A 64-bit environment is required for Android 2.3.x (Gingerbread) and higher versions, including the master branch. You can compile older versions on 32-bit systems.
Given that I haven't actually modified anything yet and I'm building a pure vanilla Android 8 ROM, I'm stumped as to how to even start trying to fix this.
Side Note: I am already aware that I can find a vanilla Android 8 ROM somewhere online; I'm more interested in building it myself so I can learn the process and have something to tinker with.

ImportError: No module named _analog_swig

I am having issues getting python to import the _analog_swig gnuradio module in order to run gnuradio code on a Windows 8.1 64bit machine.
Some background: I am running Python 2.7.10 (installed in C:\Python27) and have installed the latest gnuradio binary (v3.7.11.1/v1.3 64-Bit Any CPU) from here: http://www.gcndevelopment.com/gnuradio/downloads.htm. I have installed gnuradio to C:\Program Files\GNURadio-3.7 .
I can run gnuradio companion and run flowgraphs from GRC successfully (which calls "C:\Program Files\GNURadio-3.7\bin\run_gr.bat" gnuradio-companion.py).
I have added & verified the following system variables are set:
Path: C:\Program Files\GNURadio-3.7\bin
PYTHONPATH: C:\Program Files\GNURadio-3.7\lib\site-packages
GRC_BLOCKS_PATH: C:\Program Files\GNURadio-3.7\share\gnuradio\grc\blocks
Now to the problem: If I run e.g. CMD and type:
python C:\test\top_block.py
I am returned the following ImportError:
File "C:\test\top_block.py", line 22, in <module>
from gnuradio import analog
File "C:\Program Files\GNURadio-3.7\lib\site-packages\gnuradio\analog\__init__.py", line 33, in <module>
from analog_swig import *
File "C:\Program Files\GNURadio-3.7\lib\site-packages\gnuradio\analog\analog_swig.py", line 17, in <module>
_analog_swig = swig_import_helper()
File "C:\Program Files\GNURadio-3.7\lib\site-packages\gnuradio\analog\analog_swig.py", line 16, in swig_import_helper
return importlib.import_module('_analog_swig')
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named _analog_swig
The folder content of C:\Program Files\GNURadio-3.7\lib\site-packages\gnuradio\analog is as follows:
Comparing this to the folder content on a linux machine, which has a working install of gnuradio that works with python as I want it:
The difference seems to be that the folder in windows contains only a _analog_swig.pyc file, whereas the folder in linux contains a _analog_swig_.so file.
Any idea why the _analog_swig module can apparently not be imported in windows?
My plan is to be able to run gnuradio code directly from my python interpreter and being able to create compiled gnuradio executables so any help on how this could be fixed is much appreciated.
I've been struggling with this for the past few days, but I finally figured it out. I was trying to run GnuRadio Companion generated code in IDLE and also in PyCharm. I kept failing miserably with this same error. I finally figured it out:
-As Flexo says, the PYD file (_analog_swig.pyd) is actually a Windows DLL. The error makes it sound like Python is not finding that file, but that is not at all what was happening. The PYD file, being a DLL, has dependencies itself. Python is able to find _analog_swig.pyd just fine, but it could not find the DEPENDENCIES of that library.
-To verify if that's what wrong in your installation, download and use DependencyWalker (Google it) to check if your system can find the dependencies to _analog_swig.pyd.
-The fix for me was to add the GnuRadio-3.7/bin folder to my PATH environment variable. Inside that folder are a number of DLLs that the _analog_swig.pyd library needs to load. If you don't have the folder in your PATH, the module will fail to load in Python and throw the error you see above.
-I see that you verified that this folder is in your PATH, so this is apparently not the same problem, although your symptoms are exactly the same as mine. i.e. the GRC code would run just fine when you start with "run_gr.bat", but not when you run from a normal CMD window.
Hopefully that helps someone else that wants to use GNURadio Python code on Windows.
Friend,
As you mentioned, the GNU Companion calls \bin\run_gr.bat gnuradio-companion.py. That batch script does quite a bit of work on windows environment variables (try opening it in a text editor if you're curious).
In a sense, the run_gr.bat script puts together a temporary, custom python workspace for gnuradio so it can import anything it needs. It receives python scripts to run in this environment as command line arguments; hence, you can use it to run any GNU radio python code you want in your windows command prompt. Generally, you would call
<gnuradio_install_path>\bin\run_gr.bat <gnu_radio_code>.py
To test your import, you can try
# test.py
from gnuradio import analog
try calling the following from the command prompt, in the test.py directory:
<gnuradio_install_path>\bin\run_gr.bat test.py

Import not working when file is located in same directory and calling script

I'm not sure if the title of this question is correct, mods please feel free to change it.
I'm working through cs231n Convolutional Neural Networks for Visual Recognition course online and I've hit a weird error. This is my first attempt at any real Python programming so it could be a simple error, or something more complicated.
I'm using Python 2.7, Anaconda, and Windows 7.
When trying to run a script I get the following error;
NameError: global name 'im2col_cython' is not defined
My understanding so far is that this occurs because this fails (and calls the exception);
try:
from cs231n.im2col_cython import col2im_cython, im2col_cython
from cs231n.im2col_cython import col2im_6d_cython
except ImportError:
print 'run the following from the cs231n directory and try again:'
print 'python setup.py build_ext --inplace'
print 'You may also need to restart your iPython kernel'
I've tried to figure out why this may be the case. First off I have to run setup.py to turn im2col_cython.pyx into other files. This seems to run but does at one point have the warning;
warning: extension name 'im2col_cython' does not match fully qualified name 'cs231n.im2col_cython' of 'im2col_cython.pyx'
My figuring here is that it's an issue to do with the fact that the folder tree I have looks like this;
Assignment 2
->cs231n
Inside cs231n is where the setup.py and im2col_cython.pyx files are located. I've installed cython, and I have vc for python2.7 installed. When I run setup.py is creates 2 new files;
im2col_cython.c
im2col_cython.pyd
But I have no idea if that's what it's meant to do or anything. I'm in way over my head with this (0 Python knowledge), but I'm keen to learn!
EDIT 1
The script that imports im2col_cython is here
The im2col_cython file is here
EDIT 2
When including the following in the exception clause;
import traceback; traceback.print_exc()
I get this output;
Traceback (most recent call last):
File "fast_layers.py", line 3, in <module>
from cs231n.im2col_cython import col2im_cython, im2col_cython
ImportError: No module named cs231n.im2col_cython
Add this in the file fast_layer.py before import cs231n.im2col_cython:
import pyximport
pyximport.install()
The problem you mentioned should be fixed.

GDB Python API: How to access events in Python

I am trying to write a Python script for GDB that uses the events gdb.events.inferior_call_pre and events.inferior_call_post. However, those events are not defined in gdb.events:
>(gdb) python print(dir(gdb.events))
['__doc__', '__name__', '__package__', 'cont', 'exited', 'new_objfile', 'stop']
The above was done without a program loaded. I have also loaded a C program, run it until a breakpoint, and then executed the command with the same result.
I am running CentOS 7 with gdb 7.6.1.
I downloaded and compiled the source (with --with-python=yes) for gdb 7.12 with less success:
(gdb) python print(dir(gdb.events))
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'gdb' is not defined
Error while executing Python code.
Any help is greatly appreciated.
According to gdb's NEWS file, support for the events gdb.events.inferior_call_pre and gdb.events.inferior_call_post was added in gdb 7.9.
If you're compiling gdb from source, the gdb python module can be found in the directory gdb-7.12.1/gdb/python/lib/gdb, which gets copied to gdb-7.12.1/gdb/data-directory/python/gdb.
When you do make install, it gets copied to <prefix directory>/share/gdb/python/gdb.
If the latter directory can't be found at runtime - for instance, if you run gdb from the source directory without having done make install - gdb ought to complain at startup:
$ ./gdb
Python Exception <type 'exceptions.ImportError'> No module named gdb:
./gdb: warning:
Could not load the Python gdb module from `<prefix directory>/share/gdb/python'.
Limited Python support is available from the _gdb module.
Suggest passing --data-directory=/path/to/gdb/data-directory.
The data directory also contains files with lists of available system calls for various target architectures. It's worth making sure that gdb has access to it.
If you can't run make install but have to run gdb directly from the source directory, cd to gdb-7.12.1/gdb and run ./gdb --data-directory=./data-directory .

How to run this .py script correctly?

I downloaded a program called "A ren'py script decompiler," and I cannot for the life of me work out how to run it.
I googled a bit to discover that the files I had downloaded, which were in ".py" format, referred to Python, (yes, this is the level I am on,) so I downloaded it, and after a bit more googling, managed to run the script.
However I have still no idea how to get this thing to actually do what I want, as when I try to copy the commands from the README, it just brings up errors, and half the time I don't even understand what the README is saying in the first place. For example: "You can either use the -b argument to specify the directory in which renpy lies or place the renpy module in your Python module search path." This is gibberish to me.
So I know this is a big ask, but apparently getting this to run is supposed to be pretty simple -- it's just a lightweight program/script/thing that decompiles .rpyc scripts. So does anyone know how I can get it to work?
This is the thing: https://github.com/yuriks/unrpyc
When I run the script in Python it just says:
usage: unrpyc.py [-h] [-c] [-b BASEDIR] [-d]
[--python-screens | --ast-screens | --no-screens | --single-line-screen-kwargs]
file [file ...]
unrpyc.py: error: too few arguments
And then after that I don't know what to type to get it to work anyways.
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
--basedir
NameError: name 'basedir' is not defined
I'm the maintainer of unpryc
The script should be ran with python 2.7. Also I'm glad to tell you that in the more recent version of the decompiler (http://github.com/CensoredUsername/unrpyc) the dependency on renpy has been removed, so you no longer have to fiddle with the --basedir option.
regarding the error:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
--basedir
NameError: name 'basedir' is not defined
I'd guess that's caused because you're trying to run the command in a python shell instead of a normal command prompt. If you want to call the script normally open a command prompt (I think you're on windows, so it'd be cmd.exe) and run the command:
path_to_python_executable unrpyc.py script_you_want_to_decompile.rpyc
path_to_python_executable is usually C:\Python27\python.exe
That should work.
You won't need most options; the only one you probably need is the -b switch, and of course the script you want to decompile.
The -b (or --basedir) option tells this script where to find the Ren'Py source code; you need to have that program installed too, and then give the directory where it's Python modules are located to this script. Presumably just downloading the SDK, extracting that somewhere and naming that path with teh -b switch is enough:
unrpyc.py -b /path/to/renpy/modules/directory script_you_want_to_decompile.rpy

Categories