No module named '_swigfaiss' in Windows - python

I have an existing linux python project that uses faiss.
The project has the following swigfaiss wrapper as detailed here: https://github.com/facebookresearch/faiss/blob/master/INSTALL.md
And the python source code includes faiss as follows:
import faiss
When I run it in windows (in Visual Studio 2019) I get the error:
No module named '_swigfaiss'
I think I need to convert the program to run on Windows as the _swigfaiss.so is obviously built for Linux.
I have downloaded and built the Windows version of faiss using Visual Studio here: https://github.com/bitsun/faiss-windows. This produces a library file faissd.lib
How can I use this library file in my python program?
Or get the original to work on Windows?

Related

AttributeError: module 'guidedlda' has no attribute '_guidedlda'

I am using the GuidedLDA library which is a modified version of LDA on my Windows 10 machine with Python 3.6 in Jupyter Notebook. The packages have the following structure:
Pacakge Folder screenshot
Since the _guidedlda.c file is written in Cython, I am getting the following error in the import stage itself.
AttributeError: module 'guidedlda' has no attribute '_guidedlda'
Would be great if anyone could help.
Found a fix (not really a fix, just a way around) myself:
Use Microsoft Visual Studio Code and not Jupyter/PyCharm or any other editors. VS Code supports C and C++ build tools well.
I would recommend creating a new Python 3.6 virtual environment in VS Code solely for using this guidedLDA library.

how to build .exe for python 3.5+, 3.6 if possible?

Is there now an easy protocol to build a .exe from python 3.5+, using modules pyqtgraph, qt5, theano, pymc3, numpy, scipy, os and sys, and opening a simple GUI stored in a '.ui' file ? I lost hours and eventually failed to make one (for w7-64 bits). Help !
preliminary failure with py2exe: I first install py2exe for python 3 but it turns out this is not compatible with my python 3.6 yet, so I downgraded to python 3.5… to get a bunch of errors. Then I went to forums and tried the proposed cures but failed (I’m uneasy with windows), the alternative being to downgrade to python 3.4… So I downgraded to python 3.4 to get an error concerning a missing ‘msvcr100.dll’ that I tried to install following instructions on forums but by default I don’t have the permission to modify system directories… When I eventually had this permission it turns out the ‘regsvr32’ command fails (isn’t this for 32 bits ? but there is no ‘regsvr64’…). Following episodes are described below.
update august 23, 2017, 1pm:
I also tried pyinstaller as advised but it failed (see my related question build a .exe for Windows from a python 3 script importing theano with pyinstaller)
I also tried cx_freeze but it failed (see my related question build a .exe for Windows from a python 3 script)
I also tried pynsist but it fails (same link than above)
what's next ?
update september, 2, 2pm:
I eventually managed to build a .exe with pyinstaller after many episodes.
Unfortunately I failed to deal with the ‘theano’ module (that is required in my case by the ‘pymc3’ module) and I had to modify the .py files and give up part of the application. Could anyone help me building a .exe for windows 7+, with the ‘theano’ module ?
see build a .exe for Windows from a python 3 script importing theano with pyinstaller
Pyinstaller Works with Python 3.5 and it is working even for packages like tensor-flow, scipy , etc (The packages I worked with)
py -3.5 pip install pyinstaller
then go the C:\Users\user\AppData\Local\Programs\Python\Python35\Scripts
and run the command
pyinstaller <code .py file along with directory> --onefile
--onefile : is for compressing the build and get a single file as output
I would suggest pyinstaller see http://www.pyinstaller.org/
The pyinstaller already supports 3.5
The development version supports 3.6
It is better to use spec file to import other hidden libraries. I listed all Sklearn libraries and add them to spec file as a hiddenimports, you can add libraries you used in your project.

gdal installation for Python Visual Studio

I want to develop GIS based GUI in python using Visual Studio 2013.
But when I am trying to using gdal it is showing error given below-
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named gdal
It would be helpful, if you let me know how to install gdal for python?
I am using Visual studio 2013 for python.
For windows, you may download from here.
Add the installation directory bin folder to your system PATH, remember to put a semicolon in front of it before you add to the existing path.
C:\gdalwin32-1.6\bin
Create a new user or system variable with the data folder from your installation.
Name : GDAL_DATA
Path : C:\gdalwin32-1.6\data
If you don't know how to do this, than suggested Microsoft KnowledgeBase documentation
For more details you may take look here for other platforms.
You should be able to install the components for various versions of MSVC and Python at this website:
http://www.gisinternals.com/
I've only used the above resource for running GDAL under Python. I've never used Visual Studio 2013 for Python, but hopefully the above resource provides the necessary components.

How do I build pysvn on Windows32?

I'm trying to build PySVN from source on my Windows 7 PC. It's running 64bit Windows, but for various reasons I need to compile it so that it works on 32bit Python. That's what we run on a lot of our automation servers.
I've downloaded the PySvn extensions source, I've got Visual Studio 2008 Express Edition installed. I've tried to a batch to automate the process, it looks like this:
set PROJECT_DIR=%~dp0
set SRC_DIR=%PROJECT_DIR%pysvn-1.7.8
cd %SRC_DIR%\Builder
set SVN_VER_MAJ_MIN=1.8
call builder_custom_init.cmd
cd %SRC_DIR%\Source
python setup.py configure --platform=win32
When I get to the last line I get the error message:
Info: Configure for python 2.7.6 in exec_prefix c:\python27
('Error:', 'cannot find PyCXX include CXX/Version.hxx - use --pycxx-dir')
My python - include directory does not contain a file called Version.hxx. Where do I get this file, how do I fix this bug?
One way is to install PYCXX by hand - it installs a Version.hxx under the Include folder on windows.
The source for PYCXX is here: http://cxx.sourceforge.net/
Another way is to point the C/L parameter --pycxx-dir at the Import folder under the pysvn root where the corresponding version of PYCXX for the version of pysvn is kept.
(On top of this you will have to build the subversion libraries on windows.)

ImportError when moving custom python module between PCs

I have an algorithm written in C++ that I want to use in ArcGIS. Arc supports python scripting, so I figured I'd write a python wrapper. I built python on my development PC and then built a module (called "delaunay", to calculate Delaunay triangulations) to wrap the algorithm. On that PC I was using cygwin with mingw g++ and put the .dll that I built into /usr/local/lib/python2.6/site-packages. Works fine.
So now I'm trying to get it to work on the PC that I run GIS on. ArcGIS installs python as part of its own installation, so I put the .dll in /Python26/ArcGIS10.0/Lib/site-packages (which is in the sys.path) and tried to import it. I got the following error:
ImportError: No module named delaunay
Renamed delaunay.dll to delaunay.pyd and got this error:
ImportError: DLL load failed: The specified module could not be found.
I have a feeling it'd work if I put the source on the GIS machine and built and installed it with distutils, but I don't really want to install cygwin or Visual Studio on that machine.
Anyway, I have no idea why I get different messages, what the significance of the messages is, or whether this will work at all (i.e. is the ArcGIS distro of Python incompatible with mine 'cause we used different compilers?)
Also, the dev machine has a Jun 12, 2010 revision of Python 2.6.5 and the GIS machine has a Mar 19, 2010 revision. Maybe that is significant?
Help?
Run python -vvv and you'll see import debug info.
You are probably mixing 32-bit and 64-bit binaries. Binaries from different Python builds are incompatible.
Renamed delaunay.dll to delaunay.pyd and got this error:
ImportError: DLL load failed: The specified module could not be found.
This sounds like delaunay.pyd depends on some other dll that is not found.

Categories