TensorRT Python包与Python3.6不兼容,求手动安装方案
Yep, you absolutely can get TensorRT 4 working with Python 3.6 by manually copying the necessary files—I’ve tackled this exact scenario before. Here’s a step-by-step breakdown:
Step 1: Extract the Python 3.5 Wheel File
The .whl file is just a zip archive under the hood. Unpack it to access the internal files:
unzip tensorrt-4.0.0.3-cp35-cp35m-linux_x86_64.whl -d tensorrt_temp
Step 2: Copy the TensorRT Python Module to Your Python 3.6 Site Packages
First, find the path to your Python 3.6’s site-packages directory (this is where Python looks for installed modules):
python3.6 -c "import site; print(site.getsitepackages()[0])"
Then copy the extracted tensorrt folder into that path. For example, if the path is /usr/local/lib/python3.6/dist-packages:
sudo cp -r tensorrt_temp/tensorrt /usr/local/lib/python3.6/dist-packages/
Step 3: Install the Required Shared Libraries
The TensorRT tarball should include a lib directory (usually at TensorRT-4.0.0.3/lib) containing the core TensorRT shared libraries. You need to make these accessible to Python:
- Option 1 (Global Installation): Copy the libraries to a system-wide library path and update the cache:
sudo cp TensorRT-4.0.0.3/lib/*.so /usr/local/lib/ sudo ldconfig - Option 2 (Local/Environment-Specific): Add the TensorRT lib directory to your
LD_LIBRARY_PATHenvironment variable. You can add this line to your~/.bashrcor~/.zshrcto make it permanent:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/TensorRT-4.0.0.3/lib
Step 4: Verify the Installation
Test if TensorRT loads correctly in Python 3.6:
python3.6 -c "import tensorrt; print(f'TensorRT version: {tensorrt.__version__}')"
Notes & Potential Fixes
- If you get import errors related to missing symbols, double-check that your CUDA and cuDNN versions are compatible with TensorRT 4 (TensorRT 4 typically requires CUDA 9.0/9.1 and cuDNN 7.0.x).
- Rarely, you might run into ABI compatibility issues between Python 3.5 and 3.6. If this happens, you can try modifying the wheel’s metadata (editing the
tensorrt_temp/tensorrt.dist-info/WHEELfile to listcp36as a supported platform) and repacking it into a new wheel, then installing withpip—but the manual copy method usually works without this extra step.
内容的提问来源于stack exchange,提问作者Sam

