2017-09-06 19 views
1

私は以前、Python拡張機能に組み込まれたC++パッケージを持っています。今私はそれをdistutilsの下で適切に編成したいと思います。これまでのところ、ここに私のsetup.pyです(Pythonの3.6.2を使用(新品のは、Windows 7上)をインストール):相対パスを持つdistutils include_dirs?

from distutils.core import setup, Extension 

drawbox_module = Extension(
    "drawbox", 
    include_dirs = ['..\Drawbox Library', '..\Drawbox Tools'], 
    sources = ["PyDrawbox.cpp", 'Drawbox.Win.cpp']) 

setup(name="drawbox", 
     version="1.0", 
     ext_modules= [drawbox_module]) 

をしかし、私は実際にそれが私のディレクトリを含める無視しているように思わ構築しようとすると、 、彼らは単にそれが生成するコマンドラインではありません。

C:\Users\Ken\Desktop\Drawbox\Python36 backup>py setup.py build 
running build 
running build_ext 
building 'drawbox' extension 
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c/
nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Python36\include -IC:\Python36\include "-IC 
:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Fil 
es (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x8 
6)\Windows Kits\10\include\10.0.14393.0\ucrt" "-IC:\Program Files (x86)\Windows 
Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\includ 
e\10.0.14393.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14 
393.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\winrt" 
/EHsc /TpPyDrawbox.cpp /Fobuild\temp.win-amd64-3.6\Release\PyDrawbox.obj 
PyDrawbox.cpp 
PyDrawbox.cpp(2): fatal error C1083: Cannot open include file: 'Drawbox.h': No s 
uch file or directory 

インクルードファイルを含めるだけで結構あります:

C:\Users\Ken\Desktop\Drawbox\Python36 backup>dir "..\Drawbox Library" 
Directory of C:\Users\Ken\Desktop\Drawbox\Drawbox Library 

07/21/2014 07:11 PM <DIR>   . 
07/21/2014 07:11 PM <DIR>   .. 
07/26/2001 08:45 AM    1,407 Color.cpp 
05/19/2005 08:00 AM    5,129 Color.h 
06/29/2002 11:33 AM   117,028 Drawbox.68K.Lib 
01/23/2008 03:33 AM   29,915 Drawbox.h 
. . . 

ディレクトリを含め、私の理由を任意のアイデアが無視されていますか?これらのディレクトリの相対パスを使用する際に問題はありますか?あなたが代わりにExtensionsetup方法にごinclude_dirsを渡す必要があります

C:\Users\Ken\Desktop\Drawbox\Python36 backup>set DISTUTILS_DEBUG=1 

C:\Users\Ken\Desktop\Drawbox\Python36 backup>py setup.py build 
options (after parsing config files): 
options (after parsing command line): 
option dict for 'build' command: 
    {} 
running build 
Distribution.get_command_obj(): creating 'build' command object 
running build_ext 
Distribution.get_command_obj(): creating 'build_ext' command object 
building 'drawbox' extension 
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c/
nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Python36\include -IC:\Python36\include "-IC 
:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Fil 
es (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x8 
6)\Windows Kits\10\include\10.0.14393.0\ucrt" "-IC:\Program Files (x86)\Windows 
Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\includ 
e\10.0.14393.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14 
393.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\winrt" 
/EHsc /TpPyDrawbox.cpp /Fobuild\temp.win-amd64-3.6\Release\PyDrawbox.obj 
PyDrawbox.cpp 
PyDrawbox.cpp(2): fatal error C1083: Cannot open include file: 'Drawbox.h': No s 
uch file or directory 
Traceback (most recent call last): 
    File "C:\Python36\lib\distutils\_msvccompiler.py", line 382, in compile 
    self.spawn(args) 
    File "C:\Python36\lib\distutils\_msvccompiler.py", line 501, in spawn 
    return super().spawn(cmd) 
    File "C:\Python36\lib\distutils\ccompiler.py", line 909, in spawn 
    spawn(cmd, dry_run=self.dry_run) 
    File "C:\Python36\lib\distutils\spawn.py", line 38, in spawn 
    _spawn_nt(cmd, search_path, dry_run=dry_run) 
    File "C:\Python36\lib\distutils\spawn.py", line 81, in _spawn_nt 
    "command %r failed with exit status %d" % (cmd, rc)) 
distutils.errors.DistutilsExecError: command ['"C:\\Program Files (x86)\\Microso 
ft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe"', '/c', '/nologo', '/Ox', '/W 
3', '/GL', '/DNDEBUG', '/MD', '-IC:\\Python36\\include', '-IC:\\Python36\\includ 
e', '"-IC:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\INCLUDE"', '" 
-IC:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\ATLMFC\\INCLUDE"', 
'"-IC:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.14393.0\\ucrt"', '" 
-IC:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6.1\\include\\um"', '"-IC:\ 
\Program Files (x86)\\Windows Kits\\10\\include\\10.0.14393.0\\shared"', '"-IC:\ 
\Program Files (x86)\\Windows Kits\\10\\include\\10.0.14393.0\\um"', '"-IC:\\Pro 
gram Files (x86)\\Windows Kits\\10\\include\\10.0.14393.0\\winrt"', '/EHsc', '/T 
pPyDrawbox.cpp', '/Fobuild\\temp.win-amd64-3.6\\Release\\PyDrawbox.obj'] failed 
with exit status 2 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "setup.py", line 7, in <module> 
    ext_modules= [drawbox_module]) 
    File "C:\Python36\lib\distutils\core.py", line 148, in setup 
    dist.run_commands() 
    File "C:\Python36\lib\distutils\dist.py", line 955, in run_commands 
    self.run_command(cmd) 
    File "C:\Python36\lib\distutils\dist.py", line 974, in run_command 
    cmd_obj.run() 
    File "C:\Python36\lib\distutils\command\build.py", line 135, in run 
    self.run_command(cmd_name) 
    File "C:\Python36\lib\distutils\cmd.py", line 313, in run_command 
    self.distribution.run_command(command) 
    File "C:\Python36\lib\distutils\dist.py", line 974, in run_command 
    cmd_obj.run() 
    File "C:\Python36\lib\distutils\command\build_ext.py", line 339, in run 
    self.build_extensions() 
    File "C:\Python36\lib\distutils\command\build_ext.py", line 448, in build_exte 
nsions 
    self._build_extensions_serial() 
    File "C:\Python36\lib\distutils\command\build_ext.py", line 473, in _build_ext 
ensions_serial 
    self.build_extension(ext) 
    File "C:\Python36\lib\distutils\command\build_ext.py", line 533, in build_exte 
nsion 
    depends=ext.depends) 
    File "C:\Python36\lib\distutils\_msvccompiler.py", line 384, in compile 
    raise CompileError(msg) 
distutils.errors.CompileError: command ['"C:\\Program Files (x86)\\Microsoft Vis 
ual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe"', '/c', '/nologo', '/Ox', '/W3', '/ 
GL', '/DNDEBUG', '/MD', '-IC:\\Python36\\include', '-IC:\\Python36\\include', '" 
-IC:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\INCLUDE"', '"-IC:\\ 
Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\ATLMFC\\INCLUDE"', '"-IC: 
\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.14393.0\\ucrt"', '"-IC:\\ 
Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6.1\\include\\um"', '"-IC:\\Progr 
am Files (x86)\\Windows Kits\\10\\include\\10.0.14393.0\\shared"', '"-IC:\\Progr 
am Files (x86)\\Windows Kits\\10\\include\\10.0.14393.0\\um"', '"-IC:\\Program F 
iles (x86)\\Windows Kits\\10\\include\\10.0.14393.0\\winrt"', '/EHsc', '/TpPyDra 
wbox.cpp', '/Fobuild\\temp.win-amd64-3.6\\Release\\PyDrawbox.obj'] failed with e 
xit status 2 

答えて

0

、誰もがより深く見たい場合は、ここでDISTUTILS_DEBUGとの出力がオンになっています。少なくとも私のここでのテストでは、cl.exeのコマンドラインで相対パスが正しく表示されます。また

、彼らは=>r"..\path\to\includes"


バックスラッシュが含まれている場合は、あなたの特定のinclude_dirは、テストのために追加でこれが、私が作ったcythonモジュールからのもので、あなたのパスの前に少しRを使用してください:

import sys 
from distutils.core import setup 
from Cython.Build import cythonize 
import numpy as np 

extension = cythonize("unpack.pyx", build_dir="build")[0] 
extension.extra_link_args.append("/OUT:unpack.pyd") # VCPP specific! 

setup(
    name = 'unpack', 
    include_dirs = [np.get_include(), "..\Drawbox Library"], 
    ext_modules = [extension], 
    script_args = ["build_ext", "--inplace"],  
) 

これはdistutilsので印刷し、CL.EXEするには、コマンドラインに表示されて"-I..\Drawbox Tools"になりました。

+0

Jeronimo、テストコードを表示できますか? – Joymaker

+0

テストコードが追加されました。 – Jeronimo