Skip to content

The path of *.pyd or *.so (created by cffi) is changed. #5542

Closed

Description

@Qinka

(old title) When build C extension, the error: FileNotFoundError was got.

  • OS: Windows 10 pro
  • PyTorch version: 0.4.0a0+0de5443
  • How you installed PyTorch (conda, pip, source): source
  • Python version: 3.6.4
  • CUDA/cuDNN version: CUDA 9.0
  • GCC version (if compiling from source): msvc 14/15 (then compiling with CUDA I use VS2015, but when build extension, the program automatically use vs2017)

When building c extension on Windows, I got the error:

...
正在生成代码
已完成代码的生成
Traceback (most recent call last):
  File "build.py", line 28, in <module>
    ffi.build();
  File "C:\Users\qinka\Anaconda3\envs\torch_src\lib\site-packages\torch\utils\ffi\__init__.py", line 186, in build
    _build_extension(ffi, cffi_wrapper_name, target_dir, verbose)
  File "C:\Users\qinka\Anaconda3\envs\torch_src\lib\site-packages\torch\utils\ffi\__init__.py", line 111, in _build_extension
    os.path.join(target_dir, libname))
  File "C:\Users\qinka\Anaconda3\envs\torch_src\lib\shutil.py", line 241, in copy
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "C:\Users\qinka\Anaconda3\envs\torch_src\lib\shutil.py", line 120, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\qinka\\AppData\\Local\\Temp\\tmp6mft329i\\dot_power._ext.dow_power._dow_power.pyd'

(The Chinese above means compiler success compile the library, and generated *.lib and *.exp)

And the same error was got on a Linux Work Station.

...
gcc -pthread -shared -B /home/qinka/anaconda3/envs/qinka_pytorch/compiler_compat -L/home/qinka/anaconda3/envs/qinka_pytorch/lib -Wl,-rpath=/home/qinka/anaconda3/envs/qinka_pytorch/lib -Wl,--no-as-needed -Wl,--sysroot=/ ./my_package/_ext/my_lib/_my_lib.o ./raid/qinka/pytorch-ext-demo/dot_power.pytorch/extension-ffi/package/my_package/src/my_lib.o ./raid/qinka/pytorch-ext-demo/dot_power.pytorch/extension-ffi/package/my_package/src/my_lib_cuda.o -o ./my_package/_ext/my_lib/my_package._ext.my_lib._my_lib.so
Traceback (most recent call last):
  File "build.py", line 32, in <module>
    ffi.build()
  File "/home/qinka/anaconda3/envs/qinka_pytorch/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 167, in build
    _build_extension(ffi, cffi_wrapper_name, target_dir, verbose)
  File "/home/qinka/anaconda3/envs/qinka_pytorch/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 105, in _build_extension
    os.path.join(target_dir, libname))
  File "/home/qinka/anaconda3/envs/qinka_pytorch/lib/python3.6/shutil.py", line 241, in copy
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/home/qinka/anaconda3/envs/qinka_pytorch/lib/python3.6/shutil.py", line 120, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpv1yqw2m6/my_package._ext.my_lib._my_lib.so'

(gcc is 5.4.0)

Activity

  1. Qinka commented on Mar 3, 2018

    @Qinka
    Author

    In torch/utils/ffi/init.py _build_extension(), shutil.copy copy the linked file from os.path.join(tmpdir,, libname), for example C:\Users\qinka\AppData\Local\Temp\tmpwp84qchn\dot_power._ext.dow_power._dow_power.pyd, but
    in my Windows, and a Linux work station, the linked one is in:

    outprefix = cffi_wrapper_name.split('.')[0:-1] #
    shutil.copy(os.path.join(tmpdir, *outprefix, libname), #
                      os.path.join(target_dir, libname))

    ,for example C:\Users\qinka\AppData\Local\Temp\tmpwp84qchn\dot_power\_ext\dow_power\dot_power._ext.dow_power._dow_power.pyd.

    So, there must be a bug, or error in pytorch's ffi or python's ffi. (pyhton 3.6.4, cffi 1.11.4),

    If it broke down because of change in cffi, I think I can create a PR.
    I do think this is because of the change of cffi api,

  2. changed the title [-]When build C extension, the error: FileNotFoundError was got.[/-] [+]The path of *.pyd or *.so (created by cffi) is changed.[/+] on Mar 3, 2018
  3. ezyang commented on Mar 4, 2018

    @ezyang
    Contributor

    CC @peterjc123 who enabled extension build for Windows on 02317d9

  4. added
    module: windows
    on Mar 4, 2018
  5. peterjc123 commented on Mar 4, 2018

    @peterjc123
    Collaborator

    @Qinka Is this change documented in somewhere like Python SDK?

  6. added a commit that references this issue on Mar 4, 2018
    e9bb962
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: windows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions