I am developing python library in C++ using pybind11. The problem is that python 3.7/3.6 works well, but
python 3.8 cannot be imported. This is the error when importing the library( assume the library name is mylibrary).
ImportError: DLL load failed while importing mylibrary: The specified module could not be found.
Why Python3.8 can be built in pybind11, but cannot be imported ?
It could be that your C++ python library itself depends on a shared library / DLL. Python 3.7/3.6 would search for DLLs in PATH or the current working directory, but this is no longer the case in Python 3.8:
https://docs.python.org/3.8/whatsnew/3.8.html#ctypes
If this is the problem, you can add use add_dll_directory() to tell Python 3.8 where it should look for the DLLs.
Related
Trying to run the following code:
conn.executescript("""
CREATE VIRTUAL TABLE Hashes USING rtree(
gives the following error:sqlite3 operational error no such module: rtree
To fix this, I have built the windows dll from the sqlite source with rtrees enabled.
Where should i put the dll in order for the sqlite3 python module to recognize it?
Is there any other fix for enabling rtree module on sqlite3 python module?
python version 2.7
I believe that this should be copied into the Dlls directory
Question:
I want to compile a third-party library like Pillow or Numbpy but I want to change the name of the python27.dll to corepython27.dll. How do I do this during the compile process? Is it something I need to change in the setup.py? Or the distutils library?
I should explain that I have no experience in compiling at all. I just know that I will need to make this change as I learn more about the basics of compiling.
Explanation:
Corel's PaintShop Pro uses an embedded python interpreter to run scripts inside the program. And I would like to be able to use third-party libraries like pillow and numpy but they always fail to load. The version of python that is included with PaintShop Pro is 2.7.5. I've made sure to download the appropriate versions of these libraries but it always fails with a "DLL module doesn't exist" type error.
Using a PE viewer I was able to see that other libraries like TKinter were using imports corepython27.dll instead of python27.dll like pillow was.
Also pillow for 2.7 was using msvcr90.dll but the custom version of the tkinter library included with PSP was compiled with msvcr110.dll. Do you think this will be an issue? Do I need to compile pillow with the appropriate version of msvcr DLL? Or is matching versions (2.7) and making sure it uses the correct python.dll (corepython27.dll) the only important thing?
You can create a symbolic link named corepython27.dll showing to the installed python27.dll. You can do this in your console via the command
MKLINK <path_to_corepython.dll> <path_to_python27.dll>
I'm trying to get libarchive module working in python 3.4 on windows.
I've installed libarchive-c with pip and all went ok but whenever I try to import it into my code or even to run it alone I'me getting error:
OSError: [WinError 126] The specified module could not be found
This is coming from ffi.py from the code below:
libarchive_path = os.environ.get('LIBARCHIVE') or find_library('archive')
libarchive = ctypes.cdll.LoadLibrary(libarchive_path)
I've never used ctypes before but if I understand correctly it is looking for external DLL. So found and installed http://gnuwin32.sourceforge.net/packages/libarchive.htm also I've added C:\Program Files (x86)\GnuWin32\bin to my %PATH% in environmental variables but it still cannot load the module. As it does not give me the name I'm not sure what module it is looking for.
What am I missing?
(disclaimer) I contribute to https://github.com/Changaco/python-libarchive-c and I maintain https://github.com/nexB/scancode-toolkit
Both contain a ctypes binding for libarchive, though ScanCode is for extraction only.
My answer here is for python-libarchive-c, but ScanCode contains some of the DLL you are looking for so I am lacing in a bit of both.
To get python-libarchive-c going on Windows you need a libarchive DLL and its deps that can then be loaded.
There are no pre-built DLLs bundled in python-libarchive-c but I have prebuilt Windows binaries for another project here:
https://github.com/nexB/scancode-toolkit/tree/develop/src/extractcode/bin/win-32/bin
The corresponding source code is there: https://github.com/nexB/scancode-thirdparty-src
And you have MinGW32 build instructions there if you want to rebuild from source yourself: https://github.com/nexB/scancode-thirdparty-src/blob/master/libarchive/build.sh#L47
In general to load a DLL from a path -- assuming that the var libarchive contains the full path to that DLL -- use this:
lib = ctypes.CDLL(libarchive)
Now this is for Scancode. For python-libarchive-c, you could try to set the LIBARCHIVE variable to point the path of your DLL with:
set LIBARCHIVE="C:\.....\libarchive.dll"
Then start Python, import the library and use it.
NB: I did not test this (yet) , but this should work. IF not please file a bug.
I did not run any test on Python 3.4 either. I use primarily Python 2.7.
But the DLL and the code is not Python 2.7-specific at all.
FWIW, the way scancode loads the library is a tad more engaged since it can from the same code load DLLs Win/Linux/Mac for specific 32 or 64 bits archs using conventional locations. You can see the code in action there:
https://github.com/nexB/scancode-toolkit/blob/develop/src/extractcode/libarchive2.py#L64
ScanCode is NOT using python-libarchive-c ATM yet but a different/custom ctypes binding focused on a more specific use case of extraction only. At least it gives you access to a Win DLL and its deps (or instruction a build them) and an example on how to load it correctly.
/HTH
I'm trying to install Multicorn extension on PostgreSQL 9.3.3, but the problem I have that this extension only works with Python 2.7 or 3.3 whereas default version of python on my OS (Centos 6.5) is 2.6 and I can't change it without breaking the whole system.
I've installed python 2.7 alongside the default version and compiled Multicorn extension from source changing python references/paths in makefile to python 2.7, however I'm having trouble using the extension in Postgres.
Create extension command works just fine:
CREATE EXTENSION multicorn;
Creating the server, however fails:
CREATE SERVER csv_srv foreign data wrapper multicorn options (wrapper 'multicorn.csvfdw.CsvFdw');
ERROR: Error in python: ImportError
DETAIL: No module named multicorn
Is there a fix for this or at least a hint what to look for?
My assumption is that even though the extension itself was compiled with references to python 2.7 and all the files copied to the right folder /usr/local/lib/python2.7/dist-packages/multicorn-1.0.2-py2.7-linux-x86_64.egg/multicorn, PostgreSQL itself still uses the system default python 2.6 version and therefor fails to load the module. Is there any way to override python version that Postgres uses? Would that solve the problem?
You'll need to recompile PL/Python against Python 2.7.
Right now PL/Python will keep using Python 2.6. They aren't binary compatible and have separate sonames, libpython2.7.so and libpython2.6.so. So just changing the PATH and LD_LIBRARY_PATH will do nothing.
I would do this by downloading the PostgreSQL SRPM, modifying the spec file so it targets python 2.7, and rebuilding the RPMs.
Since python is bundled with the Tide SDK, I can't figure out how to use access external modules. I've tried copying the module folder "Lib/site-packages/YourModuleHere" to the tide SDK directory, and this suggestion here: TIdeSDK Python module import but with no success. The module I'm trying to use is https://github.com/burnash/gspread
Any ideas?
Thanks...
You may try http://www.py2exe.org/index.cgi/Tutorial
to convert your python code to exe with all needed modules then use Ti.Process.createProcess() to call your exe
In current version of TideSDK, loading custom python modules is not supported.It loads default set of Python modules compiled within the SDK.
I've had some luck installing a view external modules by running setup.py install from TideSDK's python.exe
This post helped:
Installing python modules in TideSDK
For Windows 7:
launch powershell
cd into the module folder
run:
C:\ProgramData\TideSDK\Modules\python\1.3.1-beta\python.exe setup.py install
It installs the module in \Lib\site-packages, as it should, and I'm able to use the import function in the python code.
This has worked for PIL and I'm trying to get it to function with pywin32. I'd love to hear if it works for other modules