Loading Adafruit_DHT from Jython - python

I'm having trouble importing a library called Adafruit_DHT while using the Jython interpreter. Here is what I'm doing:
Downloaded the Adafruit_DHT Library, put in on my Raspberry Pi 2, installed it with "sudo python setup.py install". When scrips using this library are executed through the normal interpreter, everything's fine.
Run my java program, which starts a Jython interpreter
First error: Adafruit_DHT module isn't found when using "import Adafruit_DHT"
Solved by adding a lot of paths to sys.path
Next error: "Exception ... File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.1.0-py2.7-linux-armv7l.egg/Adafrut_DHT/common.py", line 59, in get_platform
RuntimeError: Unknown platform." Don't really get it. Apparently the library doesnt work properly when called through Jython.
Solved by nearly deleting all of "get_platform" function in common.py and replacing it by hardcoding Raspberry_Pi_2 as the used platform.
Next problem: "File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.1.0-py2.7-linux-armv7l.egg/Adafrut_DHT/Raspberry_Pi_2_Driver.py", line 6, in bootstrap
ImportError: No module named Adafruit_DHT.Raspberry_Pi_2_Driver": Apparently the library itself makes use of modules. And those can't be loaded through Jython
I simply don't get what I should do to properly load and use an installed, rather complex, module like Adafruit_DHT through Jython. I mean, it works fine through the normal python interpreter, so there is no real reason why it shouldn't work through Jython.

Related

What does `ImportError: DLL load failed: The operating system cannot run %1` mean?

I have a project written in Python 3.9 and C++ 17, with pybind11 as the glue. It works just fine when running alone or through various debuggers, like VS's debugger and NVIDIA Nsight. However, when running through RenderDoc (a graphics API debugger, with it's own Python bindings which I don't use) I get the following error in the terminal:
ImportError: DLL load failed: The operating system cannot run %1
The error if given out for modules in my project trying to import modules from my project.
At first the error message feels similar to ImportError: DLL load failed: The specified module could not be found, so I investigated in Process Monitor, but the module seems to be found just fine.
So I'm wondering, what on earth does this error message mean? What is the OS trying to do but failing at? What might cause it? How might I debug it?
Some other threads suggest it might be to do with Python 3.8's new add_dll_directory, but I don't see why adding some specific debugger would cause this when everything runs fine without it?
I don't think it is an environment issue, as I've run everything through the same terminal. Also, it ran through RenderDoc just fine before performing various library upgrades, including an upgrade over the Python 3.8 boundary.

Importing NumPy to Geany (Python 3.5.1)

There is a bunch of pre-made code I simply have to run. However, the code requires the module NumPy, which for some reason is not installed. I am using Geany for the Python code, and when I click compile, the console states:
"Traceback (most recent call last):
File "chi2Fit.py", line 1, in <module>
import numpy as np
ImportError: No module named 'numpy'
I really tried to look it up, and I found the zipped NumPy packages on SourceForge, but I cannot install them. I am using Windows 10 (Virtual Machine is buggy, unfortunately). I usually run my Python programs by compiling them directly and don't use the commands within the console (so honestly I don't know how to open the command line. Yes, I am a beginner). What is the explanation?
Geany is just an editor, with the ability to run commands and such from menus and buttons. So you should be able to run this code 'by compiling them directly'. If that works while the 'geany compile' does not, then you need to check the 'compile' command. Is it using the right Python?
'compile' really doesn't make sense with Python code. You are just executing a script.
NumPy is a large package that does include compiled components. So installing it requires more than downloading a ZIP file. On Windows it is usually best to install one of the precompiled packages. Anaconda is popular one.
But we know nothing about this pre-made code, and whether it has included the necessary modules or not. You need to find out from the source of that code what is needed to run it.
You need to figure out how to install NumPy. It depends on what OS you are using.
There are pre-compiled packages for Windows. There is plenty of information here on SO (e.g., Installing NumPy on Windows) or you can use Google.

Using python "requests" module in a cygwin64 ZNC module

I'm positive that I'm doing something wrong, but I've looked around and the solutions presented have not worked for me.
I'm writing a bot for ZNC running under Windows 10/cygwin64 (which allows python based scripts). One of the functions I'm trying to write requires the "requests" python module, but when I try to run the python bot, it throws this error:
ImportError: No module named 'requests'
I've tried placing the "requests" source in the same folder as the bot's .py file. I've also tried easy_install to no avail.
Oddly enough, I was toying around with another python module that was required, and it worked as soon as I placed it's source in the same folder.
The version of python that ZNC is running is 3.4.
Edit: I noticed that cygwin64 stores the python bins and libs for ZNC under a specific sub-folder. I've therefore installed the "requests" module under the relative lib/site-packages directory. I think it worked, as far as the module being visible, but now ZNC crashes as soon as I load that bot script. It throws this:
cygwin_exception::open_stackdumpfile: Dumping stack trace to
znc.exe.stackdump
When I check that stackdump, it has the following:
Exception: STATUS_ACCESS_VIOLATION at rip=001801A62CD

No module named sqlite3 exception

I'm using boost::python in my Visual C++ application and I have a script that wants to connect to an SQLite database and read some data from it.
In my script, I imported sqlite3 and it works fine when I run it with Python IDLE but, when it runs inside my Visual C++ application, I get an exception:
No module named _sqlite3
Can anyone tell me why it happens? What did I miss here?
Even this line in my code returns the same exception:
boost::python::object objSQLite3 = boost::python::import("sqlite3");
I finally found the problem!!!
I install the python via inno setup in silent mode. For first time since there is no python on system all libraries copy successfully But if u do it again since it try to install python again (/i), It some how mess with some library like sqlite3.
So u need change your inno setup script to reinstall the python if it exists (/a).
PS : If you have this problem and you don't use inno setup just reinstall your python to fix this problem.
Best Regards

Using Module for different python version

The default version of python (ie, one that opens on typing "python" in command line) is 2.6 on my server. I also have 2.7 installed. How do I import a module, in this case numpy, in python2.7? When I try to import right now, it gives me an error -
ImportError: No module named numpy
Is there any workaround, apart from downloading the package and doing a build install?
I agree with the comment above. You will have to compile it separately. I once tried a hack of importing and modifying the sys.path however I ran into issues with the .so files.

Categories

Resources