python安装pytorch@FreeBSD

先上结论,最后在conda下安装成功了!

PyTorch是一个开源的人工智能深度学习框架,由Facebook人工智能研究院(FAIR)基于Torch库开发并维护。PyTorch提供了一个高效、灵活且易于使用的工具集,用于构建和训练深度学习模型。

pip 安装

在FreeBSD系统下pip安装pytorch,报错

Building wheels for collected packages: pytorchBuilding wheel for pytorch (setup.py) ... errorerror: subprocess-exited-with-error× python setup.py bdist_wheel did not run successfully.│ exit code: 1╰─> [6 lines of output]Traceback (most recent call last):File "<string>", line 2, in <module>File "<pip-setuptools-caller>", line 34, in <module>File "/tmp/pip-install-08n_s_43/pytorch_94d503f93a464e71b575ea1cfef78bdc/setup.py", line 15, in <module>raise Exception(message)Exception: You tried to install "pytorch". The package named for PyTorch is "torch"[end of output]note: This error originates from a subprocess, and is likely not a problem with pip.ERROR: Failed building wheel for pytorchRunning setup.py clean for pytorch
Failed to build pytorch
ERROR: Could not build wheels for pytorch, which is required to install pyproject.toml-based projects

安装pyproject

 pip install pyproject

再pip 安装pytorch还是同样的报错:

Building wheels for collected packages: pytorch
  Building wheel for pytorch (setup.py) ... error
  error: subprocess-exited-with-error
 
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-n_l8ufvy/pytorch_20c01d7c94e04917a97f282d03e31d92/setup.py", line 15, in <module>
          raise Exception(message)
      Exception: You tried to install "pytorch". The package named for PyTorch is "torch"
      [end of output]
 
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pytorch

查找帮助说:

运行编译过程中出现错误,并提示“Too many arguments to functions call, expected....”的信息:

遇到这种情况时,该如何解决呢?解决方法是将属性“Enable Strict Checking of objc_msgSend Calls”的值设置成“No”,即TARGETS——>项目——>Build Settings——>Apple LLVM 6.0 - Preprocessing——>Enable Strict Checking of objc_msgSend Calls

pkg安装

到pkg里发现有现成的pytorch包,于是pkg 安装:pkg install pytorch

报错冲突:

Proceed with this action? [y/N]: y
[1/1] Fetching libdca-0.0.7_1.pkg: 100%  113 KiB 115.3kB/s    00:01    
Checking integrity... done (2 conflicting)- pytorch-2.2.1 conflicts with libfmt-10.2.1 on /usr/local/include/fmt/args.h- pytorch-2.2.1 conflicts with libfmt-10.2.1 on /usr/local/include/fmt/args.h
Cannot solve problem using SAT solver, trying another plan
Checking integrity... done (0 conflicting)
Conflicts with the existing packages have been found.
One more solver iteration is needed to resolve them.
The following 2 package(s) will be affected (of 0 checked):Installed packages to be UPGRADED:libdca: 0.0.7 -> 0.0.7_1Installed packages to be REINSTALLED:pkg-1.21.1Number of packages to be upgraded: 1
Number of packages to be reinstalled: 1Proceed with this action? [y/N]: 

根据提示,是pytorch和fmt文件冲突了。删除libfmt包试试

pkg remove libfmt

删除之后再安装pytorch,会自动再安装上libfmt并继续报冲突。

pip安装python39-pytorch包

pkg install py39-pytorch

安装好之后导入torch报错:

>>> import torch
Traceback (most recent call last):File "<stdin>", line 1, in <module>File "/usr/local/lib/python3.9/site-packages/torch/__init__.py", line 237, in <module>from torch._C import *  # noqa: F403
ImportError: /usr/local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so: Undefined symbol "_ZN4onnx7checker11check_modelERKNS_10ModelProtoEbbb"

源码编译安装

下载源代码

git clone --depth 2 https://github.com/pytorch/pytorch

设置环境变量

# 直接在终端中输入即可,重启需要重新输入
export USE_CUDA=0
export USE_DISTRIBUTED=0
export USE_MKLDNN=0
export MAX_JOBS=8

编译

cd pytorch
mkdir build
cd build
cmake ..
make -j 8

报错

--   Private Dependencies : Threads::Threads;cpuinfo;fbgemm;fp16;caffe2::openmp;foxi_loader;rt;fmt::fmt-header-only;kineto;dl
--   Public CUDA Deps.    :
--   Private CUDA Deps.   :
--   USE_COREML_DELEGATE     : OFF
--   BUILD_LAZY_TS_BACKEND   : ON
--   USE_ROCM_KERNEL_ASSERT : OFF
-- Configuring incomplete, errors occurred!

配置这里就没有过去。这个报错指向了这里

CMake Error at third_party/FP16/CMakeLists.txt:94 (ADD_SUBDIRECTORY):
  The source directory

    /home/skywalk/github/pytorch/third_party/psimd

  does not contain a CMakeLists.txt file.

原来psimd目录是空的啊,删除这个目录,然后执行:

third_party]$ git submodule update --init --recursive

问题解决。后面发现foxi 、 sleef目录也是空的,同样处理,先删除目录,再git submodule update

现在终于cmake成功了,然后make:

make install -j 8

编译到40%左右的时候报错

In file included from /home/skywalk/github/pytorch/aten/src/ATen/native/sparse/ValidateCompressedIndicesKernel.cpp:1:
/home/skywalk/github/pytorch/aten/src/ATen/native/sparse/ValidateCompressedIndicesCommon.h:93:9: error: too many arguments provided to function-like macro invocation"`0 <= crow_indices[..., 1:] - crow_indices[..., :-1] <= ncols` is not satisfied.");^
/usr/include/assert.h:52:9: note: macro '_assert' defined here
#define _assert(e)      ((void)0)^
In file included from /home/skywalk/github/pytorch/aten/src/ATen/native/sparse/ValidateCompressedIndicesKernel.cpp:1:
/home/skywalk/github/pytorch/aten/src/ATen/native/sparse/ValidateCompressedIndicesCommon.h:97:9: error: too many arguments provided to function-like macro invocation"`0 <= ccol_indices[..., 1:] - ccol_indices[..., :-1] <= nrows` is not satisfied.");^
/usr/include/assert.h:52:9: note: macro '_assert' defined here
#define _assert(e)      ((void)0)^
In file included from /home/skywalk/github/pytorch/aten/src/ATen/native/sparse/ValidateCompressedIndicesKernel.cpp:1:

更新源代码:

~/github/pytorch]$ git pull

还是这个报错

h:112:24: error: too many arguments provided to function-like macro invocation     _assert(invariant, "`0 <= row_indices < nrows` is not satisfied.");

改方法,python安装

python setup.py develop --cmake

报错:

[533/2242] Building CXX object c10/test/CMa.../c10_Scalar_test.dir/core/Scalar_test.cpp.o
FAILED: c10/test/CMakeFiles/c10_Scalar_test.dir/core/Scalar_test.cpp.o

又重新安装下,报错:

/usr/home/skywalk/github/pytorch/c10/test/core/Scalar_test.cpp:53:10: error: conversion from 'long long' to 'c10::Scalar' is ambiguous
  Scalar longlongOne = 1LL;
         ^             ~~~
/usr/home/skywalk/github/pytorch/c10/core/Scalar.h:59:7: note: candidate constructor
      DEFINE_IMPLICIT_CTOR)

ports 编译安装

 安装时会有一些库安装的比较慢,可以采取各种方法改进,比如手工下载文件然后放到/usr/ports/distfiles目录里。pkg手动安装一些依赖库,比如:

pkg install psimd
pkg install kineto
cd /usr/ports/misc/pytorch 
make install 
===>  Installing for pytorch-2.1.2
===>  Checking if pytorch is already installed
===>   Registering installation for pytorch-2.1.2
Installing pytorch-2.1.2...
pkg-static: pytorch-2.1.2 conflicts with libfmt-10.2.1 (installs files into the same place).  Problematic file: /usr/local/include/fmt/args.h
*** Error code 1Stop.
make[1]: stopped in /usr/ports/misc/pytorch
*** Error code 1

还是安装的时候报冲突

conda安装pytorch

参考这篇文档:安装Miniconda@FreeBSD13-CSDN博客

使用linux-miniconda-install安装miniconda

pkg search minicondapkg install linux-miniconda-installer

运行安装程序

miniconda-installer This miniconda requires python3.8.  Install lang/python38 and try again.

当然我自己是用的笨方法安装的,

手动安装miniconda

下载软件:

wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh

 设置和启动linux兼容服务,需要在root账户下执行

kldload linux64
sysrc linux_enable="YES"
service linux start

将linux的md5sum放在路径第一位:

export PATH=/compat/linux/usr/bin:$PATH

安装

执行兼容linux命令安装,因为我们的bash不是默认的FreeBSD /bin下的,而是/compat/linux/bin/下的。 后面跟下载的Miniconda文件名。 -u参数是覆盖安装,即如果指定的安装目录存在,则不退出,而是继续覆盖安装。

执行命令:

 /compat/linux/bin/bash Miniconda3-py310_23.9.0-0-Linux-x86_64.sh -u

激活conda

source ~/miniconda3/bin/activate

使用conda安装pytorch

conda install pytorch

 哦也,没设置conda镜像安装速度也挺快!测试:

    python                                         
    Python 3.10.13 (main, Sep 11 2023, 13:44:35) [GCC 11.2.0] on linux                       
    Type "help", "copyright", "credits" or "license" for more information.                   
    import pytorch                                                                           
    >>> import pytorch                                                                       
    Traceback (most recent call last):                                                       
      File "<stdin>", line 1, in <module>                                                    
    ModuleNotFoundError: No module named 'pytorch'                                           
    >>> import torch                                                                         
    x = torch.randn(>>> x = torch.randn((2,3))                                               
    >>> y = x+1                                                                              
    >>> y                                                                                    
    tensor([[0.3041, 1.6502, 0.2174],                                                        
            [2.3316, 0.0055, 1.1459]])                                                       
     

测试通过!

总结

真是好事多磨,终于安装好pytorch拉!最终安装好miniconda,后面一通百通了!什么python包都可以安装了,不管是科学计算还是人工智能,统统到碗里来!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/3088.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

用Python自动获取PDF图纸的图纸大小,并依此分类整理

在建筑行业&#xff0c;设计师用CAD设计完建筑图纸后&#xff0c;常常需要上传到市、省二级图审平台上&#xff0c;故需要将每张图纸转成PDF文档&#xff0c;并盖电子章&#xff08;出图章、建造师章和结构章&#xff09;&#xff0c;然后上传图审系统。如果设计师在CAD转PDF时…

SpringMVC基础篇(一)

文章目录 1.基本介绍1.特点2.SpringMVC跟SpringBoot的关系 2.快速入门1.需求分析2.图解3.环境搭建1.创建普通java工程2.添加web框架支持3.配置lib文件夹1.导入jar包2.Add as Library3.以后自动添加 4.配置tomcat1.配置上下文路径2.配置热加载 5.src下创建Spring配置文件applica…

找不到openjdk-1.8-tools和openjdk-1.8-jconsole

每次打包都报找不到openjdk-1.8-tools和openjdk-1.8-jconsole&#xff0c;但是在项目中并没有用到。 这个是在maven仓库下的druid下的pom文件中。根本没有用到&#xff0c;于是把这两行注释调。解决 .m2\repository\com\alibaba\druid\1.2.6\druid-1.2.6.pom

内网穿透!如何配置frp新版0.56.0的配置文件.toml:提供web、samba、ssh远程连接示例

最新版本的frp在配置上与之前有很大不同&#xff0c;需要使用.toml文件进行配置。其中主要问题出现在toml文件内部。因此&#xff0c;本文将专门讨论这个问题。 一、服务端配置 下载并解压&#xff08;以debian系统为例&#xff09;&#xff1a; sudo apt update sudo apt i…

钡铼IOy系列模块在无人值守智能仓库中的成功运用,提升仓储物流效率

随着科技的不断发展&#xff0c;无人值守智能仓库正成为现代物流行业的一个重要趋势。在这个快节奏的时代&#xff0c;提升仓储物流效率是企业追求的目标之一。钡铼IOy系列模块为无人值守智能仓库的成功运作提供了关键支持。本文将探讨钡铼IOy系列模块在无人值守智能仓库中的应…

Java面试之数据类型

在Java中&#xff0c;数据类型用于声明变量并指定变量能够存储的数据类型。Java的数据类型可以分为两大类&#xff1a;基本数据类型和引用数据类型。 一、基本数据类型&#xff1a; 1.1、整型&#xff1a;用于表示整数值&#xff0c;包括byte、short、int和long。 byte&…

java读取过来的文件乱码?指定字符集。操作文件的几种方式

从文件读取字符串的几种方式 1 使用BufferedReader和FileReader&#xff08;无法指定读取字符集&#xff09; public static void main(String[] args) {StringBuilder content new StringBuilder();try (BufferedReader reader new BufferedReader(new FileReader("f…

深入Linux下的GCC编译器:从入门到精通

目录标题 1、GCC编译器概述2、安装GCC3、GCC的基本使用4、高级功能4.1 多文件编译4.2 静态和动态链接4.3 什么是链接&#xff1f;4.4 静态链接优点缺点 4.5 动态链接优点缺点 4.6 实际应用4.7 编译优化 GCC&#xff08;GNU Compiler Collection&#xff09;是一款免费、开源的编…

Elasticsearch下载

1 最新版下载地址 Download Elasticsearch | Elastic https://www.elastic.co/cn/downloads/elasticsearch 2 其他版本下载地址 https://www.elastic.co/cn/downloads/past-releases#elasticsearch 7.9.2:https://artifacts.elastic.co/downloads/elasticsearch/elasticsear…

基于springboot+vue+Mysql的篮球竞赛预约平台

开发语言&#xff1a;Java框架&#xff1a;springbootJDK版本&#xff1a;JDK1.8服务器&#xff1a;tomcat7数据库&#xff1a;mysql 5.7&#xff08;一定要5.7版本&#xff09;数据库工具&#xff1a;Navicat11开发软件&#xff1a;eclipse/myeclipse/ideaMaven包&#xff1a;…

在AD中导出所有用户的信息,修改之后导入

方法一 导出用户的名字&#xff0c;上次登录时间&#xff0c;上次密码重置时间&#xff0c;邮件并以CSV格式保存。 Get-ADUser - Filter * -Properties * -SearchBase " dcsuperdoor,dcco, dcnz" |Select -Object Name, lastlogondate, passwordlastset, mail |…

使用uni-app开发app时遇到mqtt.js不可用的问题

使用uni-app开发app时遇到mqtt.js不可用的问题 1 问题背景 基于 Vue3 版本创建了 uni-app 项目用于开发微信小程序&#xff0c;项目中用到了 mqtt.js&#xff08;v4.1.0&#xff09;&#xff0c;编译为微信小程序能够正常运行&#xff0c;但是编译为 APP 后&#xff0c;控制台…

【vue功能】多张图片合并

多张图片合并成一张图片 步骤一&#xff0c;多张图片上传步骤二&#xff0c;循环获取所有绘制图片的总高度new FileReader()方法作用new Image()方法作用介绍 步骤三&#xff0c;合并多张图片canvas.toDataURL()作用-dpr作用 步骤四&#xff0c;下载图片 步骤一&#xff0c;多张…

(六)JSP与Servlet的关系

JSP与Servlet的关系 JSP&#xff08;Java Server Pages&#xff09;是继Servlet后Sun公司推出的新技术。JSP技术在传统的HTML文件中插入Java程序段和JSP标记&#xff0c;从而形成JSP文件&#xff08;*.jsp&#xff09;。用JSP开发的Web应用是跨平台的&#xff0c;既能在Window…

【006期】游戏的开始和结束界面,得分和生命值及其游戏逻辑。

核心代码 int score; int lives;boolean gameOver; void draw() {background(255);if (!gameOver) {/*游戏中的其他所有逻辑写在此处*/displayScoreAndLives(); // 显示得分和生命值} else {displayGameOverScreen(); // 显示游戏结束画面} } void displayScoreAndLives() {fil…

NASA数据集——有源空腔辐射计辐照度监测仪(ACRIM)II 本地格式的 UARS 机载太阳总辐照度(TSI)2022年1月版本

Active Cavity Radiometer Irradiance Monitor (ACRIM) II Total Solar Irradiance (TSI) aboard UARS in Native format 简介 ACRIMII_TSI_UARS_NAT 数据是上层大气研究卫星&#xff08;UARS&#xff09;上的有源空腔辐射计辐照度监测仪 II&#xff08;ACRIM II&#xff09;…

云安全防御篇:如何识别并做好服务器DDoS防护?

伴随着全球互联网业务和云计算的快速发展&#xff0c;作为一种破坏力巨大的攻击方式&#xff0c;DDoS攻击正以超出服务器承受能力的流量淹没网站&#xff0c;导致服务器宕机、企业营业额下跌&#xff0c;甚至企业品牌形象受损。越是面对复杂的攻击&#xff0c;就需要性能更强的…

C++:缺省函数

目录 缺省函数的概念 缺省函数的类型 全缺省 半缺省 缺省函数的声明 C语言和C中函数的区别 缺省函数的概念 缺省函数是对于有参数的函数而言的,缺省的意思就是在函数的定义的时候对函数的参数进行初始化值;在调用的时候在缺省的参数的位置上可以不进行传参; 缺省函数的…

测试大语言模型在嵌入式设备部署的可能性——模型TinyLlama-1.1B-Chat-v1.0

测试模型TinyLlama-1.1B-Chat-v1.0修改推理参数&#xff0c;观察参数变化与推理时间变化之间的关系。 本地环境&#xff1a; 处理器 Intel Core™ i5-8400 CPU 2.80GHz 2.80 GHz 机带 RAM 16.0 GB (15.9 GB 可用) 集显 Intel UHD Graphics 630 独显 NVIDIA GeForce GTX 1050 主…

2万8金句美句格言签名句子ACCESS\EXCEL数据库

优美句子类的数据已经有《33万多优美句子经典句子ACCESS数据库》、《近2万签名的句子网络签名ACCESS数据库》、《24万QQ伤感签名微信签名ACCESS数据库》、《2万多条QQ签名论坛签名大全ACCESS数据库》&#xff0c;今天又遇到一个&#xff0c;感觉也很不错&#xff0c;发上来看看…