初始化tf.Session()时出现Segmentation fault (core dumped)问题求助
Hey there, let's work through this segmentation fault issue you're hitting when initializing tf.Session(). From the details you shared, here are targeted troubleshooting steps and potential fixes:
First, Let's Recap Your Environment
To make sure we're aligned, here's your setup:
- TensorFlow versions tested: 1.8, 1.5 (GPU edition)
- CUDA: 9.0.176
- NVIDIA Driver: 390.30
- Python: 3.6.5 (Anaconda environment)
- GCC: 5.4.0
- GPU: Tesla K80 (2 available, with full free memory)
Potential Causes & Fixes
1. Mismatched cuDNN Version (Most Likely Culprit)
TensorFlow GPU requires cuDNN alongside CUDA, and version compatibility is strict. For CUDA 9.0, you need cuDNN 7.0.x (newer versions like 7.1+ can conflict with TF 1.5/1.8).
Since you don't have root access:
- Download the compatible cuDNN 7.0.x archive for CUDA 9.0 from NVIDIA's platform (you'll need a free account)
- Extract it locally, then add its
lib64directory to your library path:
Add this line to yourexport LD_LIBRARY_PATH=/path/to/extracted/cudnn/lib64:$LD_LIBRARY_PATH~/.bashrcor~/.profileto keep the setting persistent.
2. Fix LD_LIBRARY_PATH Configuration
Your current LD_LIBRARY_PATH misses /usr/local/cuda/lib64 (where CUDA's 64-bit core libraries live) and incorrectly includes /usr/local/cuda/bin (which belongs in PATH, not library paths).
Update it with:
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH
3. Create a Clean Conda Environment
Existing dependencies in your Anaconda environment might clash with TensorFlow. Let's start fresh:
# Create a new isolated environment conda create -n tf-clean python=3.6 -y # Activate the environment conda activate tf-clean # Install the compatible TensorFlow GPU version pip install tensorflow-gpu==1.5 # Or 1.8, both support CUDA 9.0
Test tf.Session() in this clean environment to rule out dependency conflicts.
4. Test with CPU-Only Mode
To isolate whether the issue is GPU-specific, disable GPU access temporarily:
export CUDA_VISIBLE_DEVICES=""
Then launch Python and run:
import tensorflow as tf tf.Session()
If this works without a crash, the problem is definitely tied to GPU/CUDA configuration. If it still crashes, the issue lies with the CPU TensorFlow build or Python environment.
Debugging the Segmentation Fault
To get precise info on what's causing the crash, use gdb (GNU Debugger):
# Launch gdb with Python gdb python # Run the TensorFlow session initialization command run -c "import tensorflow as tf; tf.Session()" # When the crash happens, print the stack trace bt
The stack trace will show exactly which library or function triggers the fault—this can pinpoint whether it's a CUDA library, cuDNN, or TensorFlow itself.
Additional Checks
- Confirm your user has GPU access (your
nvidia-smioutput already verifies this) - Ensure no hidden processes are using the GPU (your
nvidia-smishows no running processes, so this is clear)
内容的提问来源于stack exchange,提问作者Benison Sam

