swig and building project with visual studios 2017 command line - python

I need to create a .pyd from a .cxx file that was generated from SWIG. I am bit of a noob when it comes to VS2017 and command line and I'm hoping for a little help.
Here is what I have done so far:
SWIG Setup for Windows
1). Download anaconda (using python 3.6 x64 version)
2). Download VS community version
- installed all the c++ extensions
3). Downloaded the FGDB API (windows 2017):
https://github.com/Esri/file-geodatabase-api/blob/master/FileGDB_API_1.5.1/FileGDB_API_1_5_1-VS2017.zip
4). Set the Python Environment Variables:
PYTHON_INCLUDE: C:\ProgramData\Anaconda3\include
PYTHON_LIB: C:\ProgramData\Anaconda3\libs\python36.lib
5). Download and unzip Swig
6). Add swig path to PATH environmental variable
7). Download the file-geodatabase-api files from google hosting or github.
https://storage.googleapis.com/google-code-archive-source/v2/code.google.com/file-geodatabase-api-python-wrapper/source-archive.zip
8). Create folder: C:\fgdb_code
There should be a .i, .py and a make file in the folder
9). Place the files from step #7 in this folder
10). Unzip the file from step #3 in folder from step #8
c:\fgdb_code\FGDB
Generating the .cxx file
11). Open a command line window as administrator (admin might not be needed)
12). Navigate to the c:\fgdb_code folder
13). Run: swig -python -IFGDB/include -c++ filegdbapi.i
This generates a .cxx file
```
Output Message:
FGDB\include\Util.h(819) : Warning 312: Nested union not currently supported (ignored).
FGDB\include\Util.h(838) : Warning 312: Nested union not currently supported (ignored).
FGDB\include\Util.h(843) : Warning 312: Nested union not currently supported (ignored).
FGDB\include\Util.h(849) : Warning 312: Nested union not currently supported (ignored).
FGDB\include\Geodatabase.h(307) : Warning 503: Can't wrap 'FileGDBAPI::CreateGeodatabase' unless renamed to a valid identifier.
FGDB\include\Geodatabase.h(308) : Warning 503: Can't wrap 'FileGDBAPI::OpenGeodatabase' unless renamed to a valid identifier.
FGDB\include\Geodatabase.h(309) : Warning 503: Can't wrap 'FileGDBAPI::CloseGeodatabase' unless renamed to a valid identifier.
FGDB\include\Geodatabase.h(310) : Warning 503: Can't wrap 'FileGDBAPI::DeleteGeodatabase' unless renamed to a valid identifier.
```
Generating the .pyd file from VS 2017
This is where I get stuck.
I've tried creating a new VS project for generating a DLL, but I can't seem to get the interface to work (i am finding the VS studios interface a bit daunting). Is there a way to do this via command line without creating a project? If so, can someone provide some guidance on how I can do this?
I should only need the .i and .cxx file to compile the code.
UPDATE
Generating the .pyd file from VS 2017
14). Open Visual Studios
15). Select File -> From Existing Code
16). Select c++
17). Enter the following:
- Project file location: folder from step #8
- project name: filegdbapi
- Check add files (should be checked by default)
- Click Next
18). For project type: Dynamically linked library (DLL) project
19). Press Finish
20). Build the project
Fails with:
1>------ Build started: Project: filegdbapi, Configuration: Release x64 ------
1>XSD : error : The CodeDom provider type "Microsoft.VisualC.CppCodeProvider, CppCodeProvider, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" could not be located.
1>
1>If you would like more help, please type "xsd /?".
1>Done building project "filegdbapi.vcxproj" -- FAILED.
Thank you

The libraries are incompatible with your version of Visual Studio

Related

Cython and clang on mac, "Python.h not found"

I'm running clang on mac to compile a c file created by running a very simple program through cython, but the compiler always give me a "Python.h not found" fatal error. I've tried every solution I could find, reinstalling python 3.9, using the -I/path/to/headerfile method, and rewriting the include statement in the code to contain the full filepath, but nothing has worked. When I do include the full filepath, I get fatal error: 'cpython/initconfig.h' file not found. What could the issue possibly be, and how would I fix it? The program itself works fine in the standard python interpreter, pyinstaller, and nuitka.
Today I needed to embed Python into a C application developed on XCode with Clang compiler, and I've met the same problems and solved them. Let me share the tips:
1. Python not found error
You should install a Python framework to your MacOS, and attach it into Frameworks and Libraries project settings tab. Also, specify it's path in Framework Search Paths inside Build Settings tab if XCode hasn't done it automatically.
2. Undefined symbols / Implicit declaration errors
Verify you're using a modern version of Python framework. Versions prior to 3.6 had different ABI which leads to the mentioned errors.
3. cpython/initconfig.h file not found
Versions prior to ~3.9 had some header inclusion problem for the cpython/initconfig.h file (issues 40642, 39026).
Check the builds of Python that your OS currently has. I found Pythons installed in the following paths:
# Default 2.7 MacOSX installation is here
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/
/Library/Frameworks/
Or install a recent Python version. I recommend using "universal binary" build, see the docs.

Boost Python "cannot open source file 'pyconfig.h'" when importing using "#include <boost\python.hpp>"

I am attempting to use Boost Python for a project. I have downloaded and build version 1.70 on Windows 10, and I am using Visual Studio Code. When attempting to import boost into my c++ project with the line:
#include <boost\python.hpp>
, I receive the following error:
cannot open source file "pyconfig.h" (dependency of "boost\python.hpp")
I have looked into similar issues, and the primary solution I have found was to edit user-config.jam to include the location of my python installation. I have done so, and the line within user-config.jam looks like this:
using python : 3.7 : C:\Users\broke\AppData\Local\Programs\Python\Python37 ;
After adding this line, I rebuilt Boost Python. This did nothing to remedy the issue. I would greatly appreciate help on this matter. Thank you.
you need to make sure the python/include folder is added to your includes. C:\Python\Python37\include for me on windows. You will also need to link the python library.

How to build PJSUA2 (swig) with Visual Studio 2015

I try to compile PJSUA2 for Python. I could manage to compile the source with Visual Studio 2015 Community edition.
My question is, how can I install the Python module now?
The guide suggests to use make and make install. I tried to install also minwg, but it is not working as the project was compiled with VS.
I have also tried to compile with minwg, but I never could succeed due to undefined requirements. Also official PJSUA guide recommend to use VS for Windows.
Following settings have been applied to build from source:
Swig location has been added to path
JAVA_home system variable has been added
Java location has been added to path
Empty pjlib/include/pj/config_site.h has been created
Opened source in VS 2015 Community (all suggested VS package and module has been installed)
Set following project to do not compile:
pjsua_cli_uwp_comp
pjsua_cli_wp8
pjsua_cli_wp8_comp
Set swig_java_pjsua2 to build.
Add following folders to swig_java_pjsua2 VC++ include directories
c:\Program Files\Java\jdk-11.0.2\include
c:\Program Files\Java\jdk-11.0.2\include\win32
Build solution
I could make a workaround to compile pjsua2 for Python 3.7. If you have a better solution or just suggestion to this workaround, let me know
Preconditions:
List item
Download and extract swig (swigwin 4.0.0)
Download and install JDK
Download and install Python (Python 3.7.3 x64) and set at custom installation:
tick "Add Python to environment variables"
tick "Precompile standard library"
tick "Download debugging symbols"
tick "Download debug binaries (requires VS 2015 or later)"
set custom path if you want
add swigwin location to system path
add Python location to system path
add JAVA_HOME system variable
add %JAVA_HOME%\bin to system path
Install Visual Studio 2015 Community edition
Steps:
Download and extract pjsip 2.8
Create empty config_site.h under pjlib/inlclude/pj/ folder
Open pjproject-vs14.sln in VS
There will be an unsupported warning window, press OK
At the "Install Missing Features" windows, press install
VS installer will be started, and VS has to be closed to complete installation.
I have also added "Windows 10 SDK (10.0.10586)" to the installation.
I have also enabled developer mode on my Windows 10, but this could be optional
Open project again in VS
Set project to Release and x64 on the top dropdown
Right click on the solution, and go to Configuration Properties> Configuration
Remove all uwp and wp8 related projects from selection, like pjsua_cli_uwp_comp, pjsua_cli_wp8_comp
press OK, and build solution
I have had 34 succeeded and 0 failed solution after build.
Add following lines to pjsua2.i in pjsip-apps/src/swig folder
%inline %{
pj_ssize_t new_pj_ssize_t(int s) {
return (pj_ssize_t) s;
}
%}
this extra inline swig function provides workaround for create recorder issue
Open a command line (powershell did not work for this)
go to pjsip-apps/src/swig/python
Execute following command:
swig -I../../../../pjlib/include -I../../../../pjlib-util/include -I../../../../pjmedia/include -I../../../../pjsip/include -I../../../../pjnath/include -py3 -c++ -python -threads ../pjsua2.i
Add new "Empty Project" (Visual C++) to solution with swig_python_pjsua2 name
Add libpjproject and pjsua2_lib as reference to this new project
Right click on the Header Files>Add>Existing Item...
Add pjsip-apps\src\swig\pjsua2_wrapp.h
Add a "new filter" to the project with name "Generated Code"
Right click on "Generated code" and add new existing item.
Add pjsip-apps\src\swig\pjsua2_wrapp.cxx
Right click on the project and Linker>Input
Add "Ws2_32.Lib" to "Additional Dependencies"
Go to "VC++ Directories"
Add following folder to include path(I have used full path!):
c:\python37\include
pjnath\include
pjsip\include
pjmedia\include
pjlib-util\include
pjlib\include
Add following folder to Library Directories:
C:\Python36\libs
Set at General:
Target Name: _$(ProjectName)
Target Extension: .pyd
Configuration Type: Dynamic Library (.dll)
Go to properties of the solution, and select swig_python_pjsua2 to build
Right click on swig_python_pjsua2 and build
Build should complete successfully
You will need to file to use pjsua2 library in python.
pjsua.py located under pjsip-apps/src/swig/python
x64/Release/_swig_python_pjsua2.pyd (rename this to _pjsua2.pyd)
To test, copy those to file into a folder, start python from same folder and type:
import pjsua2
Thank You very much Krisz for this awesome work!
I just got it working for Python 2.7 / 32bit and some things are slightly different, so I will add them here:
Environment:
Windows 10
SWIG 4.0.1
PJSIP 2.9
Python 2.7.14 (32bit)
Visual Studio Express 2015 (V 14.0.25431.01 Update 3)
Whaddado:
Important: Check if your Python-interpreter is really x64 or win32 like the following:
start a python session and enter:
import platform
platform.architecture()
If you have 32bit, consider this in your choice for target platform in VS.
when you add this %inline%-Snippet to pjsip-apps/src/swig/pjsua2.i, add it at the end of the file!
when starting the swig-command, omit the "-py3"-parameter, if you use Python 2.x
there is a little typo in Krisz' description, at "pjsua.py located under pjsip-apps/src/swig/python" -> of course pjsua2.py is meant. Do not use the pjsua.py.
finally copy _pjsua2.lib and pjsua2.py into \Lib\site-packages\ and the _pjsua2.pyd into \DLLs\ to make them available everywhere.

How to install SIP & PyQT on windows 7

I'm a newbie to Python environment & really struggling to install SIP & PyQt on my Win 7 machine.
This is what I've done so far,
I've downloaded SIP-4.16.9 and extracted files from the zip folder
The extracted folder is then copied to C:\Python34\Lib
Launched a command prompt(cmd) and changed path to C:\Python34\Lib
Then when I entered python configure.py at C:\Python34\Lib and I get the response as below
At this stage I'm not sure whether it's been installed successfully, to verify I looked for SIP.h at C:\Python34\Include(according to above response - in red), but I cant find any such header file, so I assume the installation hasn't been successful.
Could any one help me, what am I missing here?
Additional System Info:
Windows 7 64 Bit
Python 3.4
Environment Variable (Path : C:\Python34;C:\Python34\Lib;C:\Python34\Lib\site-packages)
Note: There are several questions posted before, but none of them helped so far, I'm sure I must be missing something silly.
Thanks for your time.
For next users who need to build sip (or pyqt) in windows using sources
ALL these instructions are for 32-bits, it will work even if you have a 64-bit system.
For Qt 5.9.x :
Since Qt 5.9, there is only one version of Qt downloadable for Windows that includes the pre-built components for MSVC201x and MinGW.
The instructions follow the same steps as for Qt 5.8
Since Microsoft Visual Studio 2015 Community Edition is not available to download anymore, next users should use Microsoft Visual Studio 2017 Community Edition with Qt 5.9 and follow the same instructions below.
Microsoft Visual Studio 2017 Community Edition (32-bits)
https://www.visualstudio.com/downloads/
Qt 5.9.x
http://download.qt.io/archive/qt/
When Installing Qt, make sure to select the correct pre-built components you have (for e.g Microsoft Visual Studio 2017)
For Qt 5.8 and earlier :
Downloads
Download Python 3.6.x (32-bits) any version will do it :
https://www.python.org/downloads/
(if you also have python 2.7, make sure to use verions 3 of python)
Download sources for sip and PyQt5: Under "Source Packages", download the "Windows Source"
https://www.riverbankcomputing.com/software/sip/download
https://www.riverbankcomputing.com/software/pyqt/download5
Microsoft Visual Studio 2015 Community Edition (32-bits)
https://www.microsoft.com/en-us/download/details.aspx?id=48146
Qt 5.8.0 for Windows 32-bit (VS 2015, 1.0 GB)
http://download.qt.io/archive/qt/
Qt download link must match the Visual Studio (VS) version installed (here VS 2015) and the PyQt5 version you need to install
For example:
PyQt5.8.2
Qt5.8.0 (Link for VS 2015)
Microsoft Visual Studio 2015
Compilation
Open a terminal and stay on it.
It is important you stay on the same terminal (cmd.exe) during the whole process so you don't have to source your environment twice.
Let's create an environment to compile PyQt and SIP (in order to compile PyQt, you need first to compile sip)
Create a folder "compilation" in your Desktop for example:
Extract the content of your sip archive in this forlder
Extract the content of your PyQt5 archive in this forlder
You should have now :
.
├── compilation
| ├── sip-4.19.2/
| └── PyQt5_gpl-5.8.2/
Make sure you are using Python 3.x:
1 - SIP
Go to sip-4.19.2 folder and run :
python configure.py
At this step, you did not install sip, you only configured it (basically its installation dir, etc...)
VERY IMPORTANT STEP: source your environment variables by running in the terminal :
Keep the double quotes, windows does not like spaces ...
"C:\Qt\Qt5.8.0\5.8\msvc2015\bin\qtenv2.bat"
After running this command, it automatically change your current directory, stay on the terminal and re-go to your sip-4.19.2 directory and run:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
In windows, "make" is substituted by "nmake" !
Then (always in the same terminal) you run :
nmake
[...]
nmake install
This will create a sip.exe in your Python dir, for me it is C:\Python36, it may elsewhere, depending on where you installed Python.
2 - PyQt5
The steps are almost the same as sip but it will take more time.
Go to PyQt5_gpl-5.8.2 folder and run :
python configure.py --disable QtNfc --confirm-license
Note that this command disable QtNfs because of a compilation problem I could not resolve.. and automatically accepts the license.
Then, run (the compilation will take a while) :
nmake
nmake install
Hope this helps.
There's a ONE SHOT solution to all your installation problems on Windows. Go to this website. http://www.lfd.uci.edu/~gohlke/pythonlibs/. Navigate to the library you want and download the .whl file for your python version and your computer (32 or 64 bit.) Then run pip install YourWhlFileName.whl, and you're done! (CAUTION: MAKE SURE NOT TO CHANGE THE NAME OF THE WHL FILE OR IT WON'T WORK.)
This is for all that want to build PyQt4 with latest Qt4 and Python 3.4.x.
Download Visual Studio 2010 from here:
http://download.cnet.com/Microsoft-Visual-Studio-2010-Ultimate/3000-2383_4-75450998.html
then install it.
Download SIP source code (in my case version 4.19.5) from here:
https://www.riverbankcomputing.com/software/sip/download
Download PyQt4 source code (in my case version 4.12.1) from here:
https://www.riverbankcomputing.com/software/pyqt/download
Extract SIP and PyQt .zip archive in \Users\your_username\Desktop\compilation\
Download latest Qt 4.x (vs2010 version) installer from here:
http://download.qt.io/archive/qt/
Install Qt (in my case qt-opensource-windows-x86-vs2010-4.8.6.exe).
Open a command prompt (use this one for all the process) and execute these commands:
cd \Users\<your_username>\Desktop\compilation\sip-4.19.5
python configure.py
"C:\Qt\4.8.6\bin\qtvars.bat"
In the output take note of QMAKESPEC value, in my case win32-msvc2010, then use it later on --spec option for PyQt4 configure-ng script.
If the current directory has been changed, execute again:
cd \Users\<your_username>\Desktop\compilation\sip-4.19.5
Now, if you use 64-bit version of Python execute:
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
otherwise, if you use 32-bit version of Python execute:
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
nmake
nmake install
cd \Users\<your_username>\Desktop\compilation\PyQt4_gpl_win-4.12.1
Now use previous QMAKESPEC value in --spec option:
python configure-ng.py --spec win32-msvc2010
nmake
nmake install
That's all ;-)
NOTE: in some cases, in order to avoid this error
ImportError: DLL load failed: The specified procedure could not be found.
it is necessary to copy .dll files from
C:\Qt\4.8.6\bin
to
C:\Python34\Lib\site-packages\PyQt4

I cannot build Pythonqt

It is PythonQt : pythonqt.sourceforge.net. I am using PythonQt-1.1 . Qt version 4.6.2 and Python 2.6.4.10 . Visual studio 2008
From instruction:
cd PythonQtRoot
vcvars32
qmake
nmake
after I typed qmake, it generated makefile, then I entered nmake but it said "makefile(22) :fatal error U1000: syntax error: ')' missing in macro invocation Stop." What did I do wrong here?
Thanks in advance....
I remember running into similar problems when building other packages with recent releases of Qt on Win32. I'm running under cygwin, by the way. After a fair amount of debugging, I discovered that 'qmake' was using the wrong 'mkspec'. One thing that helped this situation was to force the use of the correct mkspec, like so:
export QMAKESPEC=win32-msvc2008
or
export QMAKESPEC=win32-msvc
To find the list of all valid mkspecs, I looked in the directory:
c:\Qt\4.6.0\mkspecs
or
c:\Qt\2010.01\qt\mkspecs
For one particular package, I had some conflicts with other tools installed on my system and had to edit the actual mkspec file to point to the correct tool using an absolute path, but it sounds like that is not your problem here. It sounds like yours is generating a gmake-compatible Makefile instead of an nmake-compatible Makefile, so this fix should work.
-- Glenn
My suggestion is to include the PythonQt project as part of your very same project with CMake.
You then simply have to build it as part of your project statically (remove the SHARED from the add_library in the base CMakeLists.txt, by remembering that if you want it to be so, you have to remove the project(PythonQt) from its base CMakeLists.txt and then adding to your proper CMakeLists.txt base file the following:
if( PYTHON_QT_SUPPORT )
message(STATUS ":::: Including support for PythonQT Shell ::::")
# Include Python directories
find_package(PythonLibs REQUIRED)
include_directories("${PYTHON_INCLUDE_DIR}")
# Include PythonQt
include_directories(YOURPATHTOPYTHONQT/pythonqt/src)
add_subdirectory(YOURPATHTOPYTHONQT/pythonqt)
endif(PYTHON_QT_SUPPORT)
Have you made sure to update the Python/Qt versions in the build folder, and include everything you need in your environment?
In build\python.prf:
update python version
Use a Visual Studio Command Prompt and skip the vcvars32.
set your environment paths:
set PATH=E:\toolkits\Trolltech\Qt-4.8.6\Win_x64_6.1_v12_debug\lib;%PATH%
set PATH=E:\toolkits\Trolltech\Qt-4.8.6\Win_x64_6.1_v12_debug\bin;%PATH%
set PYTHON_PATH=E:\toolkits\Python\2.7.9\Win_x64_6.1_v12
set PYTHON_LIB=E:\toolkits\Python\2.7.9\Win_x64_6.1_v12\libs
In those paths, you should have available:
all qt libraries (QtCore4.dll, etc.)
all qt executables (uic, moc, etc)
python26.dll, python.exe
I've also had to update the other .prf files to make sure the debug extensions are properly done when i'm binding on debug dlls.

Categories

Resources