Windows Python Compile
ДЛЯ ОПРЕДЕЛЕННОЙ ВЕРСИИ ПИТОНА, НЕОБХОДИМО ИСПОЛЬЗОВАТЬ НУЖНУЮ ВЕРСИЮ КОМПИЛЯТОРА
Which Microsoft Visual C++ compiler to use with a specific Python version
Visual C++ 14.0\15.х, CPython 3.5, 3.6
Microsoft Visual C++ 14.0 \\ Visual C++ Build Tools 2015 (x86, x64, ARM) \\ Studio 2017 (x86, x64, ARM, ARM64)
Visual C++ 10.0, CPython 3.3, 3.4
Microsoft Visual C++ 10.0 standalone: Windows SDK 7.1 (x86, x64, ia64)
Microsoft Visual C++ 10.0 with Visual Studio 2010 (x86, x64, ia64)
Visual C++ 9.0, CPython 2.6, 2.7, 3.0, 3.1, 3.2
Microsoft Visual C++ 9.0 standalone: Visual C++ Compiler for Python 2.7 (x86, x64)
Microsoft Visual C++ 9.0 standalone: Windows SDK 7.0 (x86, x64, ia64)
Microsoft Visual C++ 9.0 standalone: Windows SDK 6.1 (x86, x64, ia64)
Microsoft Visual C++ 9.0 with Visual Studio 2008 (x86, x64, ia64)
Python version VC++ version _MSC_VER Alternative name C runtime C++ runtime
1.0 800 MSVCRT10.DLL
2.0 900 MSVCRT20.DLL
4.0 1000 MSVCRT40.DLL
4.2 1020 MSVCRT.DLL
5.0 1100 Visual Studio 97 MSVCRT.DLL MSVCP50.DLL
6.0 1200 MSVCRT.DLL MSVCP60.DLL
7.0 1300 Visual Studio 2002 MSVCR70.DLL MSVCP70.DLL
2.5.6 7.1 1310 Visual Studio 2003 MSVCR71.DLL MSVCP71.DLL
8.0 1400 Visual Studio 2005 MSVCR80.DLL MSVCP80.DLL
2.6.9 9.0 1500 Visual Studio 2008 MSVCR90.DLL MSVCP90.DLL
2.7.6 9.0 1500 Visual Studio 2008 MSVCR90.DLL MSVCP90.DLL
3.2.3 9.0 1500 Visual Studio 2008 MSVCR90.DLL MSVCP90.DLL
3.3.5 10.0 1600 Visual Studio 2010 MSVCR100.DLL MSVCP100.DLL
3.4.0 10.0 1600 Visual Studio 2010 MSVCR100.DLL MSVCP100.DLL
11.0 1700 Visual Studio 2012 MSVCR110.DLL MSVCP110.DLL
12.0 1800 Visual Studio 2013 MSVCR120.DLL MSVCP120.DLL
3.5.0 14.0 1900 Visual Studio 2015 See notes MSVCP140.DLL
3.6.0 14.0 1900 Visual Studio 2015 See notes MSVCP140.DLL
15.0(2017) 1910 191025017
https://matthew-brett.github.io/pydagogue/python_msvc.html
https://sourceforge.net/p/predef/wiki/Compilers/
Compiling C extension modules on Microsoft Visual C++ Compiler
Package for Python 2.7 \\ Visual C++ 2008 \\
For Python 2.7 you need to get Microsoft Visual C++ Compiler for Python 2.7
http://aka.ms/vcpython27
ПЕРВЫЙ способ
Using Microsoft Visual C++ Compiler for Python (only for Python
2.7.x)\\ VCForPython27.msi \\ vcvarsall.bat in folders with a different path layout than the VS2008 SDK
Install Microsoft Visual C++ Compiler for Python from http://www.microsoft.com/en-us/download/details.aspx?id=44266
Window opened with "run as administrator", like this:
msiexec /i VCForPython27.msi ALLUSERS=1
Launch MSVC for Python command prompt \\vcvarsall.bat
(go to start menu > Microsoft Visual C++ Compiler Package for Python 2.7 > Visual C++ 2008 32-bit Command Prompt)
cmd.exe /k ""C:\Users\%username%\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat" x86"
Enter the following commands:
SET DISTUTILS_USE_SDK=1
SET MSSdk=1
You can then "cd X:yourpath"\\"cd C:\Downloads\winrandom-1.2" to navigate to your Python app and then build your C extensions by entering:
python.exe setup.py build_ext --inplace --compiler=msvc
ВТОРОЙ способ
Another way to workaround this issue, without needing to set variables everytime, is to patch the file
E:\Anaconda2\Lib\distutils\msvc9compiler.py
by adding the following code at the top of the
find_vcvarsall()
function:
def find_vcvarsall(version):
"""Find the vcvarsall.bat file
At first it tries to find the productdir of VS 2008 in the registry. If
that fails it falls back to the VS90COMNTOOLS env var.
"""
vsbase = VS_BASE % version
vcpath = os.environ['ProgramFiles']
vcpath = os.path.join(vcpath, 'Common Files', 'Microsoft',
'Visual C++ for Python', '9.0', 'vcvarsall.bat')
if os.path.isfile(vcpath): return vcpath
vcpath = os.path.join(os.environ['LOCALAPPDATA'], 'Programs', 'Common', 'Microsoft', 'Visual C++ for Python', '9.0', 'vcvarsall.bat')
if os.path.isfile(vcpath): return vcpath
...
Then, create a file distutils.cfg \\ E:\Anaconda2\Lib\distutils\ in the same folder, and put this inside:
[build]
compiler=msvc
python.exe setup.py build_ext --inplace --compiler=msvc
Using Windows SDK C/C++ compiler (works for all Python versions)
The standard way to compile C extensions for CPython (including Cython extensions) is to install the compiler that was used to compile the CPython interpreter. CPython is always compiled using Visual Studio.
In order to do this, you either need the Visual Studio that compiled CPython or a Windows SDK C/C++ compiler. Now the problem is that depending on which Python version you want to compile your extension for, you need a different version of the SDK, because they are not cross-compatible.
Luckily, people have compiled the list of CPython versions with their corresponding SDK, and in fact, you can use the free
Visual Studio Express v9.0 package to compile Python between versions 2.6.9 - 3.3.4,
VSE v10.0 (2010) to compile Python 3.3.5 - 3.4.x,
and Visual Studio 2015 Community Edition for Python 3.5.
Make sure that you check the "Common tools for Visual C++" option during the Visual Studio install (in order to avoid the dreaded vcvarsall.bat error). Note that this only works for compiling 32-bits extensions, for 64-bits extensions you will need to install in addition the corresponding Windows SDK below.
Alternative: Victor Stinner argues that just installing the Windows SDKs (v7.0 for Python 2.7, v7.1 for Python 3.3 and 3.4) is enough if you prepare the environment (inconvenient in my opinion):
setenv /x64 /release
set MSSDK=1
set DISTUTILS_USE_SDK=1
If you don't want to install Visual Studio, you can choose to install the Windows SDK C/C++ compiler, as indicated in the table below:
Python 2.6 2.7 3.1 MS Windows SDK for Windows 7 and .NET Framework
3.5 SP1 Windows SDK (.NET 3.5 SP1) \\ Download the GRMSDKX_EN_DVD.iso
\\ http://www.microsoft.com/en-us/download/details.aspx?id=18950
Python 3.3 \\ MS Windows SDK for Windows 7 and .NET Framework 4 \\ Windows SDK (.NET
4) \\ Download the GRMSDKX_EN_DVD.iso \\ https://www.microsoft.com/en-us/download/details.aspx?id=8442
For Pythons 3.3 and 3.4 you will need MSVC 2010.
At this point it does not matter if you want to compile for 64 or 32 bit. The version you downloaded can do both.
install or build a package, you do have to start a SDK Command Prompt or CMD Shell and set some environment variables.
By default the shell starts in at the installation path of the Windows SDK (C:\Program Files\Microsoft SDKs\Windows\v7.0. There, we have to to two things:
Tell distutils / setuptools to use the Microsoft SDK compiler
Tell the compiler to compile a 32 or 64 bit release and whether it should be a debug or a release build
Thus, we have to enter two commands
set DISTUTILS_USE_SDK=1
setenv /x64 /release
Assuming you haven't changed the Windows SDK installation path, this looks something like this
C:\Program Files\Microsoft SDKs\Windows\v7.0>set DISTUTILS_USE_SDK=1
C:\Program Files\Microsoft SDKs\Windows\v7.0>setenv /x64 /release
As you might have guessed, you can swap out x64 for x86 or /release for /debug and vice versa.
Python 3.4 \\ Install Visual C++ 2010 Express (download).\\
http://go.microsoft.com/?linkid=9709949 \\
For Pythons 3.3 and 3.4 you will need MSVC 2010.
Before installing the Windows SDK v7.1 (these gave me a bad time):
Do not install Microsoft Visual Studio 2010 Service Pack 1 yet. If you did then you have to reinstall everything. Uninstalling the Service Pack removes components so you have to reinstall Visual C++ 2010 Express again.
Remove all the Microsoft Visual C++ 2010 Redistributable packages from Control Panel\Programs and Features.
If you don't do those then the install is going to fail with an obscure "Fatal error during installation" error.
Install Windows SDK for Visual Studio 2010 (v7.1) (download). This is required for 64bit extensions.
On Windows 10 the web installer gets confused:
Some Windows SDK components require the RTM .NET Framework 4. Setup detected a pre-release version of the .NET Framework 4.
You certainly don't need any of the .NET stuff so you can work around
by getting the offline version of the SDK (ISO) (download). \\ https://www.microsoft.com/en-us/download/details.aspx?id=8442
Make sure you download GRMSDKX_EN_DVD.iso (X means 64bit).
Windows has builtin mounting for ISOs. Just mount the ISO and run Setup\SDKSetup.exe instead of setup.exe.
Create a vcvars64.bat file in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64 that contains [2]:
CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64
ПРОДОЛЖЕНИЕ
https://blog.ionelmc.ro/2014/12/21/compiling-python-extensions-on-windows/
Python 3.5 \\ Install Visual Studio 2015 \\ Visual C++ 2015 Build Tools
It seems Visual Studio 2015 Community Edition just works without any fuss. Get it here. It's quite big and doesn't let you skip the irrelevant SQL Server and .NET tools so I had to manually remove them from Control Panel\Programs and Features.
Alternative: Get the Visual C++ 2015 Build Tools instead. It doesn't come with Visual Studio and all the useless cruft but make sure you select the Windows 8.1 SDK during the install.
Visual C++ 2015 Build Tools \\ http://landinghub.visualstudio.com/visual-cpp-build-tools
ПРЕДУПРЕЖДЕНИЕ, на сколько существенна, практика покажет
** Do not use MinGW-w64. As you will notice, the MinGW import library for Python (e.g. libpython27.a) is omitted from the AMD64 version of Python. This is deliberate. Do not try to make one using dlltool. There is no official MinGW-w64 release yet, it is still in "beta" and considered unstable, although you can get a 64-bit build from e.g. TDM-GCC. There have also been issues with the mingw runtime conflicting with the MSVC runtime; this can happen from places you don't expect, such as inside runtime libraries for g++ or gfortran. To stay on the safe side, avoid MinGW-w64 for now.
ПРИМЕЧАНИЕ в мини примерах
CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64
Compile Python extensions on Windows
Install Windows SDK
Run "Windows SDK Command Prompt"
Type:
setenv /x64 /release
set MSSDK=1
set DISTUTILS_USE_SDK=1
python.exe -m pip install wheel
Run "Windows SDK Command Prompt"
Setup the environment to build code in 64-bit mode (replace /x64 with /x86 for 32bit):
CALL "C:\...\...\Bin\SetEnv.cmd" /x64
CALL "C:\...\...\Bin\SetEnv.cmd" /x86
setenv /x64 /release
setenv /x86 /release
set MSSDK=1
set DISTUTILS_USE_SDK=1
option is: x86 | amd64 | arm | x86_amd64 | x86_arm | amd64_x86 | amd64_arm
cmd /k "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
set MSSDK=1
set DISTUTILS_USE_SDK=1
"development mode" to Python, to get a few checks
to detect bugs earlier: a new -X dev command line option. Example:
python3.6 -X dev script.py
* Debug hooks on Python memory allocators: PYTHONMALLOC=debug
Basically, replace:
python3.6 -X dev ...
with
PYTHONMALLOC=debug python3.6 -Wd -b -X faulthandler ...
For example, we may enable
the debug mode of asyncio: PYTHONASYNCIODEBUG=1
PYTHONMALLOC=debug python3.6 -Wd -bb -X faulthandler script.py
Strict developer mode:
PYTHONMALLOC=debug python3.6 -Werror -bb -X faulthandler script.py
Developer mode:
PYTHONMALLOC=debug python3.6 -Wd -b -X faulthandler script.py
Show DeprecationWarning and ResourceWarning warnings: python -Wd
Show BytesWarning warning: python -b
Enable faulthandler to get a Python traceback on segfault and fatal errors: python -X faulthandler
Debug hooks on Python memory allocators: PYTHONMALLOC=debug
Enable Python assertions (assert) and set __debug__ to True: remove (or just ignore) -O or -OO command line arguments
See also PYTHONASYNCIODEBUG=1 for asyncio.
Building Python wheels for Windows
ПРИМЕР bat файла для проекта
https://cowboyprogrammer.org/2014/06/building-python-wheels-for-windows/
GCC - MinGW (x86) \\ mingw-w64
Open MinGW Installation Manager, check mingw32-base and mingw32-gcc-g++, and Apply Changes in the Installation menu.
Add C:\MinGW\bin to the PATH environment variable (With ";" before if PATH is not empty).
Create a distutils.cfg file with the following contents in the folder \Lib\distutils in Python install directory :
Toggle line numbers distutils.cfg:
[build]
compiler=mingw32
[build_ext]
compiler=mingw32
PATCH, Mingw-w64 and python on windows x64
http://bugs.python.org/issue4709
http://bugs.python.org/issue11723
mingwpy - the python friendly windows compiler toolchain
https://anaconda.org/carlkl/mingwpy/files
GCC - cygwin compiler
PATCH, Python 3.4, Python 3.3, Python 2.7http://bugs.python.org/issue12641
https://hg.python.org/cpython/rev/7d9a1aa8d95e/
Чтиво
http://ascend4.org/Setting_up_a_MinGW-w64_build_environment
https://github.com/kivy/kivy/wiki/Using-Kivy-with-an-existing-Python-installation-on-Windows-%2864-or-32-bit%29
https://github.com/kivy/kivy/wiki/Creating-a-64-bit-development-environment-with-MinGW-on-Windows
https://bitbucket.org/carlkl/mingw-w64-for-python/downloads/
https://github.com/mingwpy/mingwpy
https://github.com/mingwpy/mingw-builds
https://github.com/numpy/numpy/wiki/Mingw-static-toolchain
https://github.com/numpy/numpy/wiki/building_scipy_superpack
https://mingwpy.github.io/proposal_december2015.html
https://wiki.qt.io/MinGW-64-bit
Компиляция в формат .whl
Configuration
For our minimal Python-only project, we'll only need four lines in setup.cfg:
[bdist_wheel]
universal = 1
[metadata]
license_file = LICENSE
If your project is python 2 and 3 compatible you can create a universal wheel distribution. Create a file called setup.cfg with the following content and upload your package.
[bdist_wheel]
universal = 1
Building a source distribution and a wheel of your project is just a matter of
python setup.py sdist bdist_wheel
Компиляция в cython
Compiling from the command line
cython -a yourmod.pyx
gcc -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing \
-I/usr/include/python2.7 -o yourmod.so yourmod.c
create a setup.py script:
from distutils.core import setup
from Cython.Build import cythonize
setup(
name = "My hello app",
ext_modules = cythonize('yourmod.pyx'), # accepts a glob pattern
)
Now, run the command:
python setup.py build_ext --inplace
КАК приимер
https://github.com/MacPython/numpy-wheels
ЮЗЕР полезн. комманды с параметрами
python.exe -c "import struct; print(8*struct.calcsize('P'))"
cmd.exe /k ""C:\Users\%username%\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat" x86"
cmd.exe /k ""C:\Users\Nikolay\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat" amd64"
setenv /x86 /release
set MSSDK=1
set DISTUTILS_USE_SDK=1
set PYTHONHOME=e:\Anaconda2\envs\py27-32
set PYTHONPATH=e:\Anaconda2\envs\py27-32\Lib
set PATH=e:\Anaconda2\envs\py27-32\scripts;e:\Anaconda2\envs\py27-32;%PATH%
cmd /V /K "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
cmd /k ""C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86"
call "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
setenv /x64 /release
set MSSDK=1
set DISTUTILS_USE_SDK=1
set PYTHONPATH=e:\Anaconda2\Lib
set PYTHONHOME=e:\Anaconda2
set PATH=e:\Anaconda2\scripts;e:\Anaconda2;%PATH%
cmd /V /K "C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.Cmd" /x86 /release
setenv /x64 /release
set MSSDK=1
set DISTUTILS_USE_SDK=1
set PYTHONPATH=e:\Anaconda2\Lib
set PYTHONHOME=e:\Anaconda2
set PATH=e:\Anaconda2\scripts;e:\Anaconda2;%PATH%
python.exe -m pip install -U git+https://github.com/kivy/kivy
ошибка, делаем локально
git clone https://github.com/kivy/kivy
cd kivy
python.exe setup.py build build_ext --inplace --compiler=msvc
set LLVM_DIR=E:\tools\LLVM
python.exe -m pip install -U kivy build_ext --inplace --compiler=msvc
python.exe -m easy_install kivy build_ext --inplace --compiler=msvc
python.exe -m pip install --force-reinstall git+https://github.com/conda/conda
conda config --add channels diffpy
conda install diffpy-cmi
conda install -c bioconda multiqc
conda install -c conda-forge pthreads-win32
conda install -n root conda-build
conda install anaconda-client
conda config --add channels conda-forge
conda config --add channels conda-canary
conda update conda
conda info --envs
set CONDA_FORCE_32BIT=1
conda create -n py27-32 python=2.7 anaconda ipython notebook ipykernel
activate py27-32
conda install anaconda
conda config --remove channels conda-forge
conda install ipython notebook ipykernel
python -c "import struct; print(8*struct.calcsize('P'))
conda info
conda info -e
python -V
conda install -n root conda-build
conda install conda-build
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
pip install --force -U conda
pip install -U -i https://pypi.anaconda.org/carlkl/simple mingwpy
python.exe pip install -U ipykernel ipython ipython-genutils jupyter-client jupyter-console jupyter-core path.py pyzmq traitlets
python -m IPython --version
easy_install http://www.voidspace.org.uk/downloads/pycrypto26/pycrypto-2.6.win32-py2.7.exe
pip install -U pysqlite build_ext --inplace --compiler=msvc
python.exe setup.py build_ext --compiler=msvc
python.exe setup.py build_ext --inplace --compiler=msvc
python setup.py build build_ext --compiler=msvc
python setup.py build build_ext --force
pip install -U pysqlite build_ext --compiler=msvc
python setup.py clean --all build_ext --force
pip install --upgrade --no-deps git+https://github.com/CamDavidsonPilon/lifelines.git
python -m pip install ipykernel
python -m easy_install pyyaml
python -m pip install -U pathlib2 ipython jupyter-core jupyter-client certifi tornado ipykernel futures ipyparallel
set CONDA_SUBDIR=win-32
conda create --name py275 python=2.7.5 ipython notebook ipykernel
conda install ipykernel ipython ipython_genutils jupyter_client jupyter_console jupyter_core path.py pyzmq traitlets
pip install "ipython[notebook]" --upgrade
pip install -U "pip>=1.4" "setuptools>=0.9" "wheel>=0.21" twine
ipykernel --ip=192.168.0.4 -f /tmp/hydrogen/connection.json
enpkg --update-all --forceall
enpkg enstaller --forceall
pip install -U git+https://github.com/enthought/enstaller
Using the mingw64 suite
There is a minor hurdle to sort before being able to use the mingw64 suite: Python requires msvcr90, but mingw 64 does not provide a stub (libmsvcr90.a) for it. This problem doesn’t exist in the 32 bit version as the stub is provided. To get the stub to the following.
Be sure to have a mingw64 version with gendef.exe. Some builds do not have it. Get one that does
do copy C:\Windows\winsxs\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcr90.dll .
gendef.exe msvcr90.dll
dlltool.exe -D msvcr90.dll -l libmsvcr90.a -d msvcr90.def
copy libmsvcr90.a MINGW64_PATH\lib
gendef glew32.dll
dlltool --dllname glew32.dll --def glew32.def --output-lib libglew32.a
cd C:\dev-64\Python27\libs
rename python27.lib old_python27.lib
gendef python27.dll
dlltool --dllname python27.dll --def python27.def --output-lib libpython27.a
$ gendef
Usage: gendef [OPTION]... [DLL]...
Dumps DLL exports information from PE32/PE32+ executables
Options:
- Dump to stdout
-h, --help Show this help.
-a, --assume-stdcall Assume functions with ambiguous call
convention as stdcall.
-I, --include-def-path <path>
Add additional search paths to find
hint .def files.
-f, --no-forward-output Don't output forwarders in .def file
-r, --disable-fs-redirector
Disable Win64 FS redirection, for 32-bit
gendef on 64-bit Windows
Usage example:
By default, the output files are named after their DLL counterparts
gendef MYDLL.DLL Produces MYDLL.def
gendef - MYDLL.DLL Prints the exports to stdout
Built on Jun 10 2015
Report bugs to <mingw-w64-public@lists.sourceforge.net>
$ dlltool --help
Usage e:\Anaconda2\scripts\..\share\mingwpy\bin\dlltool.exe <option(s)> <object-file(s)>
-m --machine <machine> Create as DLL for <machine>. [default: i386:x86-64]
possible <machine>: arm[_interwork], i386, mcore[-elf]{-le|-be}, ppc, thumb
-e --output-exp <outname> Generate an export file.
-l --output-lib <outname> Generate an interface library.
-y --output-delaylib <outname> Create a delay-import library.
-a --add-indirect Add dll indirects to export file.
-D --dllname <name> Name of input dll to put into interface lib.
-d --input-def <deffile> Name of .def file to be read in.
-z --output-def <deffile> Name of .def file to be created.
--export-all-symbols Export all symbols to .def
--no-export-all-symbols Only export listed symbols
--exclude-symbols <list> Don't export <list>
--no-default-excludes Clear default exclude symbols
-b --base-file <basefile> Read linker generated base file.
-x --no-idata4 Don't generate idata$4 section.
-c --no-idata5 Don't generate idata$5 section.
--use-nul-prefixed-import-tables Use zero prefixed idata$4 and idata$5.
-U --add-underscore Add underscores to all symbols in interface library.
--add-stdcall-underscore Add underscores to stdcall symbols in interface library.
--no-leading-underscore All symbols shouldn't be prefixed by an underscore.
--leading-underscore All symbols should be prefixed by an underscore.
-k --kill-at Kill @<n> from exported names.
-A --add-stdcall-alias Add aliases without @<n>.
-p --ext-prefix-alias <prefix> Add aliases with <prefix>.
-S --as <name> Use <name> for assembler.
-f --as-flags <flags> Pass <flags> to the assembler.
-C --compat-implib Create backward compatible import library.
-n --no-delete Keep temp files (repeat for extra preservation).
-t --temp-prefix <prefix> Use <prefix> to construct temp file names.
-I --identify <implib> Report the name of the DLL associated with <implib>.
--identify-strict Causes --identify to report error when multiple DLLs.
-v --verbose Be verbose.
-V --version Display the program version.
-h --help Display this information.
@<file> Read options from <file>.
Report bugs to <http://www.sourceware.org/bugzilla/>
ГОТОВЫЕ пакеты в формате wheel
http://pythonwheels.com/
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Чтиво
https://github.com/numpy/numpy/blob/master/doc/HOWTO_RELEASE.rst.txt#wine
https://github.com/numpy/numpy/wiki/Building-with-MSVC
https://matthew-brett.github.io/pydagogue/python_msvc.html
https://hynek.me/articles/conditional-python-dependencies/
http://haypo-notes.readthedocs.io/python.html#build-a-python-wheel-package-on-windows
https://cowboyprogrammer.org/2014/06/building-python-wheels-for-windows/
https://wiki.python.org/moin/WindowsCompilers#Microsoft_Visual_C.2B-.2B-_10.0_standalone:_Windows_SDK_7.1_.28x86.2C_x64.2C_ia64.29
https://wiki.python.org/moin/WindowsCompilers
https://github.com/cython/cython
https://github.com/cython/cython/wiki/CythonExtensionsOnWindows
http://docs.cython.org/en/latest/src/reference/compilation.html
https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/
Which Microsoft Visual C++ compiler to use with a specific Python version
Visual C++ 14.0\15.х, CPython 3.5, 3.6
Microsoft Visual C++ 14.0 \\ Visual C++ Build Tools 2015 (x86, x64, ARM) \\ Studio 2017 (x86, x64, ARM, ARM64)
Visual C++ 10.0, CPython 3.3, 3.4
Microsoft Visual C++ 10.0 standalone: Windows SDK 7.1 (x86, x64, ia64)
Microsoft Visual C++ 10.0 with Visual Studio 2010 (x86, x64, ia64)
Visual C++ 9.0, CPython 2.6, 2.7, 3.0, 3.1, 3.2
Microsoft Visual C++ 9.0 standalone: Visual C++ Compiler for Python 2.7 (x86, x64)
Microsoft Visual C++ 9.0 standalone: Windows SDK 7.0 (x86, x64, ia64)
Microsoft Visual C++ 9.0 standalone: Windows SDK 6.1 (x86, x64, ia64)
Microsoft Visual C++ 9.0 with Visual Studio 2008 (x86, x64, ia64)
Python version VC++ version _MSC_VER Alternative name C runtime C++ runtime
1.0 800 MSVCRT10.DLL
2.0 900 MSVCRT20.DLL
4.0 1000 MSVCRT40.DLL
4.2 1020 MSVCRT.DLL
5.0 1100 Visual Studio 97 MSVCRT.DLL MSVCP50.DLL
6.0 1200 MSVCRT.DLL MSVCP60.DLL
7.0 1300 Visual Studio 2002 MSVCR70.DLL MSVCP70.DLL
2.5.6 7.1 1310 Visual Studio 2003 MSVCR71.DLL MSVCP71.DLL
8.0 1400 Visual Studio 2005 MSVCR80.DLL MSVCP80.DLL
2.6.9 9.0 1500 Visual Studio 2008 MSVCR90.DLL MSVCP90.DLL
2.7.6 9.0 1500 Visual Studio 2008 MSVCR90.DLL MSVCP90.DLL
3.2.3 9.0 1500 Visual Studio 2008 MSVCR90.DLL MSVCP90.DLL
3.3.5 10.0 1600 Visual Studio 2010 MSVCR100.DLL MSVCP100.DLL
3.4.0 10.0 1600 Visual Studio 2010 MSVCR100.DLL MSVCP100.DLL
11.0 1700 Visual Studio 2012 MSVCR110.DLL MSVCP110.DLL
12.0 1800 Visual Studio 2013 MSVCR120.DLL MSVCP120.DLL
3.5.0 14.0 1900 Visual Studio 2015 See notes MSVCP140.DLL
3.6.0 14.0 1900 Visual Studio 2015 See notes MSVCP140.DLL
15.0(2017) 1910 191025017
https://matthew-brett.github.io/pydagogue/python_msvc.html
https://sourceforge.net/p/predef/wiki/Compilers/
Compiling C extension modules on Microsoft Visual C++ Compiler
Package for Python 2.7 \\ Visual C++ 2008 \\
For Python 2.7 you need to get Microsoft Visual C++ Compiler for Python 2.7
http://aka.ms/vcpython27
ПЕРВЫЙ способ
Using Microsoft Visual C++ Compiler for Python (only for Python
2.7.x)\\ VCForPython27.msi \\ vcvarsall.bat in folders with a different path layout than the VS2008 SDK
Install Microsoft Visual C++ Compiler for Python from http://www.microsoft.com/en-us/download/details.aspx?id=44266
Window opened with "run as administrator", like this:
msiexec /i VCForPython27.msi ALLUSERS=1
Launch MSVC for Python command prompt \\vcvarsall.bat
(go to start menu > Microsoft Visual C++ Compiler Package for Python 2.7 > Visual C++ 2008 32-bit Command Prompt)
cmd.exe /k ""C:\Users\%username%\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat" x86"
Enter the following commands:
SET DISTUTILS_USE_SDK=1
SET MSSdk=1
You can then "cd X:yourpath"\\"cd C:\Downloads\winrandom-1.2" to navigate to your Python app and then build your C extensions by entering:
python.exe setup.py build_ext --inplace --compiler=msvc
ВТОРОЙ способ
Another way to workaround this issue, without needing to set variables everytime, is to patch the file
E:\Anaconda2\Lib\distutils\msvc9compiler.py
by adding the following code at the top of the
find_vcvarsall()
function:
def find_vcvarsall(version):
"""Find the vcvarsall.bat file
At first it tries to find the productdir of VS 2008 in the registry. If
that fails it falls back to the VS90COMNTOOLS env var.
"""
vsbase = VS_BASE % version
vcpath = os.environ['ProgramFiles']
vcpath = os.path.join(vcpath, 'Common Files', 'Microsoft',
'Visual C++ for Python', '9.0', 'vcvarsall.bat')
if os.path.isfile(vcpath): return vcpath
vcpath = os.path.join(os.environ['LOCALAPPDATA'], 'Programs', 'Common', 'Microsoft', 'Visual C++ for Python', '9.0', 'vcvarsall.bat')
if os.path.isfile(vcpath): return vcpath
...
Then, create a file distutils.cfg \\ E:\Anaconda2\Lib\distutils\ in the same folder, and put this inside:
[build]
compiler=msvc
python.exe setup.py build_ext --inplace --compiler=msvc
Using Windows SDK C/C++ compiler (works for all Python versions)
The standard way to compile C extensions for CPython (including Cython extensions) is to install the compiler that was used to compile the CPython interpreter. CPython is always compiled using Visual Studio.
In order to do this, you either need the Visual Studio that compiled CPython or a Windows SDK C/C++ compiler. Now the problem is that depending on which Python version you want to compile your extension for, you need a different version of the SDK, because they are not cross-compatible.
Luckily, people have compiled the list of CPython versions with their corresponding SDK, and in fact, you can use the free
Visual Studio Express v9.0 package to compile Python between versions 2.6.9 - 3.3.4,
VSE v10.0 (2010) to compile Python 3.3.5 - 3.4.x,
and Visual Studio 2015 Community Edition for Python 3.5.
Make sure that you check the "Common tools for Visual C++" option during the Visual Studio install (in order to avoid the dreaded vcvarsall.bat error). Note that this only works for compiling 32-bits extensions, for 64-bits extensions you will need to install in addition the corresponding Windows SDK below.
Alternative: Victor Stinner argues that just installing the Windows SDKs (v7.0 for Python 2.7, v7.1 for Python 3.3 and 3.4) is enough if you prepare the environment (inconvenient in my opinion):
setenv /x64 /release
set MSSDK=1
set DISTUTILS_USE_SDK=1
If you don't want to install Visual Studio, you can choose to install the Windows SDK C/C++ compiler, as indicated in the table below:
Python 2.6 2.7 3.1 MS Windows SDK for Windows 7 and .NET Framework
3.5 SP1 Windows SDK (.NET 3.5 SP1) \\ Download the GRMSDKX_EN_DVD.iso
\\ http://www.microsoft.com/en-us/download/details.aspx?id=18950
Python 3.3 \\ MS Windows SDK for Windows 7 and .NET Framework 4 \\ Windows SDK (.NET
4) \\ Download the GRMSDKX_EN_DVD.iso \\ https://www.microsoft.com/en-us/download/details.aspx?id=8442
For Pythons 3.3 and 3.4 you will need MSVC 2010.
At this point it does not matter if you want to compile for 64 or 32 bit. The version you downloaded can do both.
install or build a package, you do have to start a SDK Command Prompt or CMD Shell and set some environment variables.
By default the shell starts in at the installation path of the Windows SDK (C:\Program Files\Microsoft SDKs\Windows\v7.0. There, we have to to two things:
Tell distutils / setuptools to use the Microsoft SDK compiler
Tell the compiler to compile a 32 or 64 bit release and whether it should be a debug or a release build
Thus, we have to enter two commands
set DISTUTILS_USE_SDK=1
setenv /x64 /release
Assuming you haven't changed the Windows SDK installation path, this looks something like this
C:\Program Files\Microsoft SDKs\Windows\v7.0>set DISTUTILS_USE_SDK=1
C:\Program Files\Microsoft SDKs\Windows\v7.0>setenv /x64 /release
As you might have guessed, you can swap out x64 for x86 or /release for /debug and vice versa.
Python 3.4 \\ Install Visual C++ 2010 Express (download).\\
http://go.microsoft.com/?linkid=9709949 \\
For Pythons 3.3 and 3.4 you will need MSVC 2010.
Before installing the Windows SDK v7.1 (these gave me a bad time):
Do not install Microsoft Visual Studio 2010 Service Pack 1 yet. If you did then you have to reinstall everything. Uninstalling the Service Pack removes components so you have to reinstall Visual C++ 2010 Express again.
Remove all the Microsoft Visual C++ 2010 Redistributable packages from Control Panel\Programs and Features.
If you don't do those then the install is going to fail with an obscure "Fatal error during installation" error.
Install Windows SDK for Visual Studio 2010 (v7.1) (download). This is required for 64bit extensions.
On Windows 10 the web installer gets confused:
Some Windows SDK components require the RTM .NET Framework 4. Setup detected a pre-release version of the .NET Framework 4.
You certainly don't need any of the .NET stuff so you can work around
by getting the offline version of the SDK (ISO) (download). \\ https://www.microsoft.com/en-us/download/details.aspx?id=8442
Make sure you download GRMSDKX_EN_DVD.iso (X means 64bit).
Windows has builtin mounting for ISOs. Just mount the ISO and run Setup\SDKSetup.exe instead of setup.exe.
Create a vcvars64.bat file in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64 that contains [2]:
CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64
ПРОДОЛЖЕНИЕ
https://blog.ionelmc.ro/2014/12/21/compiling-python-extensions-on-windows/
Python 3.5 \\ Install Visual Studio 2015 \\ Visual C++ 2015 Build Tools
It seems Visual Studio 2015 Community Edition just works without any fuss. Get it here. It's quite big and doesn't let you skip the irrelevant SQL Server and .NET tools so I had to manually remove them from Control Panel\Programs and Features.
Alternative: Get the Visual C++ 2015 Build Tools instead. It doesn't come with Visual Studio and all the useless cruft but make sure you select the Windows 8.1 SDK during the install.
Visual C++ 2015 Build Tools \\ http://landinghub.visualstudio.com/visual-cpp-build-tools
ПРЕДУПРЕЖДЕНИЕ, на сколько существенна, практика покажет
** Do not use MinGW-w64. As you will notice, the MinGW import library for Python (e.g. libpython27.a) is omitted from the AMD64 version of Python. This is deliberate. Do not try to make one using dlltool. There is no official MinGW-w64 release yet, it is still in "beta" and considered unstable, although you can get a 64-bit build from e.g. TDM-GCC. There have also been issues with the mingw runtime conflicting with the MSVC runtime; this can happen from places you don't expect, such as inside runtime libraries for g++ or gfortran. To stay on the safe side, avoid MinGW-w64 for now.
ПРИМЕЧАНИЕ в мини примерах
CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64
Compile Python extensions on Windows
Install Windows SDK
Run "Windows SDK Command Prompt"
Type:
setenv /x64 /release
set MSSDK=1
set DISTUTILS_USE_SDK=1
python.exe -m pip install wheel
Run "Windows SDK Command Prompt"
Setup the environment to build code in 64-bit mode (replace /x64 with /x86 for 32bit):
CALL "C:\...\...\Bin\SetEnv.cmd" /x64
CALL "C:\...\...\Bin\SetEnv.cmd" /x86
setenv /x64 /release
setenv /x86 /release
set MSSDK=1
set DISTUTILS_USE_SDK=1
option is: x86 | amd64 | arm | x86_amd64 | x86_arm | amd64_x86 | amd64_arm
cmd /k "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
set MSSDK=1
set DISTUTILS_USE_SDK=1
"development mode" to Python, to get a few checks
to detect bugs earlier: a new -X dev command line option. Example:
python3.6 -X dev script.py
* Debug hooks on Python memory allocators: PYTHONMALLOC=debug
Basically, replace:
python3.6 -X dev ...
with
PYTHONMALLOC=debug python3.6 -Wd -b -X faulthandler ...
For example, we may enable
the debug mode of asyncio: PYTHONASYNCIODEBUG=1
PYTHONMALLOC=debug python3.6 -Wd -bb -X faulthandler script.py
Strict developer mode:
PYTHONMALLOC=debug python3.6 -Werror -bb -X faulthandler script.py
Developer mode:
PYTHONMALLOC=debug python3.6 -Wd -b -X faulthandler script.py
Show DeprecationWarning and ResourceWarning warnings: python -Wd
Show BytesWarning warning: python -b
Enable faulthandler to get a Python traceback on segfault and fatal errors: python -X faulthandler
Debug hooks on Python memory allocators: PYTHONMALLOC=debug
Enable Python assertions (assert) and set __debug__ to True: remove (or just ignore) -O or -OO command line arguments
See also PYTHONASYNCIODEBUG=1 for asyncio.
Building Python wheels for Windows
ПРИМЕР bat файла для проекта
https://cowboyprogrammer.org/2014/06/building-python-wheels-for-windows/
GCC - MinGW (x86) \\ mingw-w64
Open MinGW Installation Manager, check mingw32-base and mingw32-gcc-g++, and Apply Changes in the Installation menu.
Add C:\MinGW\bin to the PATH environment variable (With ";" before if PATH is not empty).
Create a distutils.cfg file with the following contents in the folder \Lib\distutils in Python install directory :
Toggle line numbers distutils.cfg:
[build]
compiler=mingw32
[build_ext]
compiler=mingw32
PATCH, Mingw-w64 and python on windows x64
http://bugs.python.org/issue4709
http://bugs.python.org/issue11723
mingwpy - the python friendly windows compiler toolchain
https://anaconda.org/carlkl/mingwpy/files
pip install -i https://pypi.anaconda.org/carlkl/simple mingwpy
GCC - cygwin compiler
PATCH, Python 3.4, Python 3.3, Python 2.7http://bugs.python.org/issue12641
https://hg.python.org/cpython/rev/7d9a1aa8d95e/
Чтиво
http://ascend4.org/Setting_up_a_MinGW-w64_build_environment
https://github.com/kivy/kivy/wiki/Using-Kivy-with-an-existing-Python-installation-on-Windows-%2864-or-32-bit%29
https://github.com/kivy/kivy/wiki/Creating-a-64-bit-development-environment-with-MinGW-on-Windows
https://bitbucket.org/carlkl/mingw-w64-for-python/downloads/
https://github.com/mingwpy/mingwpy
https://github.com/mingwpy/mingw-builds
https://github.com/numpy/numpy/wiki/Mingw-static-toolchain
https://github.com/numpy/numpy/wiki/building_scipy_superpack
https://mingwpy.github.io/proposal_december2015.html
https://wiki.qt.io/MinGW-64-bit
Компиляция в формат .whl
Configuration
For our minimal Python-only project, we'll only need four lines in setup.cfg:
[bdist_wheel]
universal = 1
[metadata]
license_file = LICENSE
If your project is python 2 and 3 compatible you can create a universal wheel distribution. Create a file called setup.cfg with the following content and upload your package.
[bdist_wheel]
universal = 1
Building a source distribution and a wheel of your project is just a matter of
python setup.py sdist bdist_wheel
Компиляция в cython
Compiling from the command line
cython -a yourmod.pyx
gcc -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing \
-I/usr/include/python2.7 -o yourmod.so yourmod.c
create a setup.py script:
from distutils.core import setup
from Cython.Build import cythonize
setup(
name = "My hello app",
ext_modules = cythonize('yourmod.pyx'), # accepts a glob pattern
)
Now, run the command:
python setup.py build_ext --inplace
КАК приимер
https://github.com/MacPython/numpy-wheels
ЮЗЕР полезн. комманды с параметрами
python.exe -c "import struct; print(8*struct.calcsize('P'))"
cmd.exe /k ""C:\Users\%username%\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat" x86"
cmd.exe /k ""C:\Users\Nikolay\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat" amd64"
setenv /x86 /release
set MSSDK=1
set DISTUTILS_USE_SDK=1
set PYTHONHOME=e:\Anaconda2\envs\py27-32
set PYTHONPATH=e:\Anaconda2\envs\py27-32\Lib
set PATH=e:\Anaconda2\envs\py27-32\scripts;e:\Anaconda2\envs\py27-32;%PATH%
cmd /V /K "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
cmd /k ""C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86"
call "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
setenv /x64 /release
set MSSDK=1
set DISTUTILS_USE_SDK=1
set PYTHONPATH=e:\Anaconda2\Lib
set PYTHONHOME=e:\Anaconda2
set PATH=e:\Anaconda2\scripts;e:\Anaconda2;%PATH%
cmd /V /K "C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.Cmd" /x86 /release
setenv /x64 /release
set MSSDK=1
set DISTUTILS_USE_SDK=1
set PYTHONPATH=e:\Anaconda2\Lib
set PYTHONHOME=e:\Anaconda2
set PATH=e:\Anaconda2\scripts;e:\Anaconda2;%PATH%
python.exe -m pip install -U git+https://github.com/kivy/kivy
ошибка, делаем локально
git clone https://github.com/kivy/kivy
cd kivy
python.exe setup.py build build_ext --inplace --compiler=msvc
Using the mingw64 suite
There is a minor hurdle to sort before being able to use the mingw64 suite: Python requires msvcr90, but mingw 64 does not provide a stub (libmsvcr90.a) for it. This problem doesn’t exist in the 32 bit version as the stub is provided. To get the stub to the following.
Be sure to have a mingw64 version with gendef.exe. Some builds do not have it. Get one that does
do copy C:\Windows\winsxs\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcr90.dll .
gendef.exe msvcr90.dll
dlltool.exe -D msvcr90.dll -l libmsvcr90.a -d msvcr90.def
copy libmsvcr90.a MINGW64_PATH\lib
gendef glew32.dll
dlltool --dllname glew32.dll --def glew32.def --output-lib libglew32.a
cd C:\dev-64\Python27\libs
rename python27.lib old_python27.lib
gendef python27.dll
dlltool --dllname python27.dll --def python27.def --output-lib libpython27.a
$ gendef
Usage: gendef [OPTION]... [DLL]...
Dumps DLL exports information from PE32/PE32+ executables
Options:
- Dump to stdout
-h, --help Show this help.
-a, --assume-stdcall Assume functions with ambiguous call
convention as stdcall.
-I, --include-def-path <path>
Add additional search paths to find
hint .def files.
-f, --no-forward-output Don't output forwarders in .def file
-r, --disable-fs-redirector
Disable Win64 FS redirection, for 32-bit
gendef on 64-bit Windows
Usage example:
By default, the output files are named after their DLL counterparts
gendef MYDLL.DLL Produces MYDLL.def
gendef - MYDLL.DLL Prints the exports to stdout
Built on Jun 10 2015
Report bugs to <mingw-w64-public@lists.sourceforge.net>
$ dlltool --help
Usage e:\Anaconda2\scripts\..\share\mingwpy\bin\dlltool.exe <option(s)> <object-file(s)>
-m --machine <machine> Create as DLL for <machine>. [default: i386:x86-64]
possible <machine>: arm[_interwork], i386, mcore[-elf]{-le|-be}, ppc, thumb
-e --output-exp <outname> Generate an export file.
-l --output-lib <outname> Generate an interface library.
-y --output-delaylib <outname> Create a delay-import library.
-a --add-indirect Add dll indirects to export file.
-D --dllname <name> Name of input dll to put into interface lib.
-d --input-def <deffile> Name of .def file to be read in.
-z --output-def <deffile> Name of .def file to be created.
--export-all-symbols Export all symbols to .def
--no-export-all-symbols Only export listed symbols
--exclude-symbols <list> Don't export <list>
--no-default-excludes Clear default exclude symbols
-b --base-file <basefile> Read linker generated base file.
-x --no-idata4 Don't generate idata$4 section.
-c --no-idata5 Don't generate idata$5 section.
--use-nul-prefixed-import-tables Use zero prefixed idata$4 and idata$5.
-U --add-underscore Add underscores to all symbols in interface library.
--add-stdcall-underscore Add underscores to stdcall symbols in interface library.
--no-leading-underscore All symbols shouldn't be prefixed by an underscore.
--leading-underscore All symbols should be prefixed by an underscore.
-k --kill-at Kill @<n> from exported names.
-A --add-stdcall-alias Add aliases without @<n>.
-p --ext-prefix-alias <prefix> Add aliases with <prefix>.
-S --as <name> Use <name> for assembler.
-f --as-flags <flags> Pass <flags> to the assembler.
-C --compat-implib Create backward compatible import library.
-n --no-delete Keep temp files (repeat for extra preservation).
-t --temp-prefix <prefix> Use <prefix> to construct temp file names.
-I --identify <implib> Report the name of the DLL associated with <implib>.
--identify-strict Causes --identify to report error when multiple DLLs.
-v --verbose Be verbose.
-V --version Display the program version.
-h --help Display this information.
@<file> Read options from <file>.
Report bugs to <http://www.sourceware.org/bugzilla/>
ГОТОВЫЕ пакеты в формате wheel
http://pythonwheels.com/
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Чтиво
https://github.com/numpy/numpy/blob/master/doc/HOWTO_RELEASE.rst.txt#wine
https://github.com/numpy/numpy/wiki/Building-with-MSVC
https://matthew-brett.github.io/pydagogue/python_msvc.html
https://hynek.me/articles/conditional-python-dependencies/
http://haypo-notes.readthedocs.io/python.html#build-a-python-wheel-package-on-windows
https://cowboyprogrammer.org/2014/06/building-python-wheels-for-windows/
https://wiki.python.org/moin/WindowsCompilers#Microsoft_Visual_C.2B-.2B-_10.0_standalone:_Windows_SDK_7.1_.28x86.2C_x64.2C_ia64.29
https://wiki.python.org/moin/WindowsCompilers
https://github.com/cython/cython
https://github.com/cython/cython/wiki/CythonExtensionsOnWindows
http://docs.cython.org/en/latest/src/reference/compilation.html
https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/
Комментарии
Отправить комментарий