使用tsnecuda包运行t-SNE时遇OSError:找不到预期扩展名文件
问题:tsnecuda安装后运行报错
OSError: no file with expected extension 安装情况
- 环境:CUDA 12.2
- 执行安装命令:
pip3 install tsnecuda==3.0.1+cu122 -f https://tsnecuda.isx.ai/tsnecuda_stable.html
测试代码
from tsnecuda import TSNE X = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]]) X_embedded = TSNE().fit_transform(X)
报错信息
--------------------------------------------------------------------------- OSError Traceback (most recent call last) Cell In[19], line 3 1 from tsnecuda import TSNE 2 X = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]]) ----> 3 X_embedded = TSNE().fit_transform(X) File ~\anaconda3\envs\spyder\Lib\site-packages\tsnecuda\TSNE.py:139, in TSNE.__init__(self, n_components, perplexity, early_exaggeration, learning_rate, num_neighbors, force_magnify_iters, pre_momentum, post_momentum, theta, epssq, n_iter, n_iter_without_progress, min_grad_norm, perplexity_epsilon, metric, init, return_style, num_snapshots, verbose, random_seed, use_interactive, viz_timeout, viz_server, dump_points, dump_file, dump_interval, print_interval, device, magnitude_factor) 137 # Build the hooks for the BH T-SNE library 138 self._path = os.path.dirname(__file__) --> 139 self._lib = N.ctypeslib.load_library( 140 'libtsnecuda', self._path) # Load the ctypes library 142 # Hook the BH T-SNE function 143 self._lib.pymodule_tsne.restype = None File ~\anaconda3\envs\spyder\Lib\site-packages\numpy\ctypeslib.py:161, in load_library(libname, loader_path) 159 raise 160 ## if no successful return in the libname_ext loop: --> 161 raise OSError("no file with expected extension") OSError: no file with expected extension
解决建议
- 检查安装目录的动态库:找到tsnecuda的安装路径(如
~\anaconda3\envs\spyder\Lib\site-packages\tsnecuda),确认是否存在对应系统的动态库文件:Windows下为libtsnecuda.dll,Linux下为libtsnecuda.so,macOS下为libtsnecuda.dylib。若缺失,说明预编译安装包损坏或不兼容当前系统。 - 手动源码编译:克隆tsnecuda仓库,按照官方编译步骤针对CUDA 12.2手动构建,避免预编译包的兼容性问题。
- 验证CUDA环境变量:确保
CUDA_PATH、PATH等环境变量正确指向CUDA 12.2的安装目录,防止动态库加载时找不到依赖的CUDA组件。 - 尝试降级CUDA版本:如果上述方法无效,可降级到CUDA 11.x(如11.8),安装对应版本的tsnecuda(如
tsnecuda==3.0.1+cu118),高版本CUDA的预编译包支持可能存在不完善的情况。 - 确认Python版本兼容性:当前Python版本建议在3.8-3.10区间,避免版本不匹配导致动态库加载失败。
内容的提问来源于stack exchange,提问作者Amy Hassett
相关产品推荐
相关产品推荐

