Pyinstaller在生成一个文件可执行文件后找不到NVCC,Ubuntu 16.04LTS

Pyinstaller在生成一个文件可执行文件后找不到NVCC,Ubuntu 16.04LTS

我有一个使用 CUDA 和 Pycuda 作为实现一部分的 Python 项目。当作为 Python 文件执行时,它运行时没有错误。然后我使用 pyinstaller 生成了一个可执行文件,但它给了我一个错误,说找不到 nvcc。

这是我收到的错误:

Traceback (most recent call last):
  File "site-packages/pytools/prefork.py", line 50, in call_capture_output
  File "subprocess.py", line 729, in __init__
  File "subprocess.py", line 1364, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: 'nvcc': 'nvcc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_3.py", line 151, in <module>
  File "test_3.py", line 134, in align_downward_optimized
  File "site-packages/pycuda/compiler.py", line 292, in __init__
  File "site-packages/pycuda/compiler.py", line 255, in compile
  File "site-packages/pycuda/compiler.py", line 78, in compile_plain
  File "site-packages/pycuda/compiler.py", line 50, in preprocess_source
  File "site-packages/pytools/prefork.py", line 227, in call_capture_output
  File "site-packages/pytools/prefork.py", line 61, in call_capture_output
pytools.prefork.ExecError: error invoking 'nvcc --preprocess -arch sm_61 -Ipycuda/cuda /tmp/tmp83435g34.cu --compiler-options -P': [Errno 2] No such file or directory: 'nvcc': 'nvcc'

答案1

我已经找到了解决这个问题的方法,即将 nvcc 的路径传递给 SourceModule()。如果 pycuda 无法自动找到 nvcc,这将有所帮助。

from pycuda.compiler import SourceModule
import pycuda.driver as cuda
#CUDA C/C++ code goes inside SourceModule
mod = SourceModule("""kernel""", nvcc="path to nvcc")
....

相关内容