栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

使用Geant4遇到的一系列问题(在wsl、anaconda中遇到)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Geant4遇到的一系列问题(在wsl、anaconda中遇到)

Gean4的安装 路径问题

在WSL中安装时,需注意Geant4的安装路径是否:

  • 路径过长
  • 路径中包含中文
  • 路径中包含空格 " "
  • 路径中包含别的特殊字符
使用anaconda安装

参考官方手册,使用anaconda安装的命令:

 conda create -c conda-forge --name  geant4

注意,conda中启用geant4的命令是:

conda activate 

conda安装的example/B1的位置在 "~/.conda/envs/geant4/share/Geant4-10.7.2/examples/basic/B1"可以通过如下命令找到:

find ~/.conda/env -name "B1"

但是我在wsl1中似乎无法这样安装,会出很多奇奇怪怪的问题。不过在wsl2和ubuntu虚拟机中没问题。(不懂…)
但是在使用wsl2安装后,编译例子出现:

Could NOT find EXPAT: Found unsuitable version "2.2.9", but required is at
  least "2.4.1" (found /usr/lib/x86_64-linux-gnu/libexpat.so)
Call Stack (most recent call first):

看起来应该是因为libexpat1版本的问题,但是Ubuntu20的最新版就是2.2.9,。。。。。可以在这里或者这里下载到libexpat2.4.1。
试了一下,即便是安装了最新版的libexpat2.4.1仍然不能编译(而且为了避免坑,还得重新下载老版本,并用dpkg -i 手动退回去)。似乎wsl2中用conda安装geant4此路不通。(有待研究 —> 已经解决)

在WSL中使用conda安装Geant4(不推荐)

有个异常曲折的方法, 参考这篇和这篇,将wsl的ubuntu升级到ubuntu21.10,然后安装sudo apt-get install libfreetype6-dev就好了。详细如下:
先给ubuntu换apt源,此过程不赘述。接着更新系统:

sudo apt update && sudo apt upgrade # 确保更新到最新
vim /etc/update-manager/release-upgrades # 编辑该文件使得最后一行为normal,而不是lts
比如,将/etc/update-manager/release-upgrades修改为:

```bash
# Default behavior for the release upgrader.

[DEFAULT]
# Default prompting behavior, valid options:
#
#  never  - Never check for a new release.
#  normal - Check to see if a new release is available.  If more than one new
#           release is found, the release upgrader will attempt to upgrade to
#           the release that immediately succeeds the currently-running
#           release.
#  lts    - Check to see if a new LTS release is available.  The upgrader
#           will attempt to upgrade to the first LTS release available after
#           the currently-running one.  Note that this option should not be
#           used if the currently-running release is not itself an LTS
#           release, since in that case the upgrader won't be able to
#           determine if a newer release is available.
prompt=normal
```

然后开始更新ubuntu的大版本

sudo do-release-upgrad

接着根据提示重启、确认等一步步完成ubuntu大版本的更新。
重复上述步骤,直到将ubuntu版本更新到ubuntu21.10(当前最新版)就可以了。然后执行

sudo apt-get install libfreetype6-dev # 安装编译geant4的依赖。

现在可以开始使用conda安装Geant4了,下载并安装conda并换源的过程不赘述。
执行如下命令即可完成geant4的安装,并进入相应环境,就可以开始使用了。

 conda create -c conda-forge --name  geant4 # 这里可以写"geant4"
 conda activate 
 cd ~/.conda/envs//share/Geant4-10.7.2/examples/basic/B1/

效果如下图所示:

Geant4的使用

主要是遇到了关于QT的问题,有很多:

编译时错误 /usr/lib/x86_64-linux-gnu/libSM.so: undefined reference to `uuid_generate@UUID_1.0’

这个主要是conda的库和ubuntu自带库冲突引起的,(如果没有装anaconda,就不会有这个问题)。
参考这篇和这篇

尝试运行下面命令以解决,

conda install -c conda-forge xorg-libsm

或者,最简单的方法:

  1. 删除掉Anaconda自带的过期库文件
  2. 用系统的库文件替换之
export condapath=`whereis anaconda3` # ${condapath:10} 表示安装anaconda3的位置
sudo mv ${condapath:10}/lib/libuuid.so.1 ${condapath:10}/lib/back_libuuid.so.1
sudo ln -s /lib/x86_64-linux-gnu/libuuid.so.1 ${condapath:10}/lib/libuuid.so.1
运行时错误 01 error while loading shared libraries: libQt5Core.so.5: cannot open shared object file: No such file or directory

解决方案:

sudo strip --remove-section=.note.ABI-tag /usr/lib64/libQt5Core.so.5

参考:
https://askubuntu.com/questions/1034313/ubuntu-18-4-libqt5core-so-5-cannot-open-shared-object-file-no-such-file-or-dir
https://github.com/dnschneid/crouton/wiki/Fix-error-while-loading-shared-libraries:-libQt5Core.so.5

02 QXcbConnection: XCB error: 170 (Unknown), sequence: 170, resource id: 90, major code: 146 (Unknown), minor code: 20 Segmentation fault (core dumped)

可以通过键入如下命令修复:

export LIBGL_ALWAYS_INDIRECT=0

参考:
https://answers.ros.org/question/292272/qxcb-connection-xcb-error-170/
LIBGL_ALWAYS_INDIRECT 指令是用来干什么的?

03 QStandardPaths: XDG_RUNTIME_DIR not set

可以通过键入如下命令修复

export XDG_RUNTIME_DIR=/some/directory/you/specify 

其实就是将这个XDG_RUNTIME_DIR设置为某个你拥有权限的目录。任何你拥有权限的目录都行。
参考:
https://dev.to/winebaths/getting-up-and-running-with-the-windows-subsystem-for-linux-8oc

04 Errors linking blit shader:
Could not create shader of type 2.
Warning: “” failed to compile!

重装Geant4可以解决,没找到别的办法…

05 No protocol specified
qt.qpa.xcb: could not connect to display 你主机的ip.1:0.0

这是因为WSL2在开启x服务器时要求勾选上 No Access Control

注意,WSL2和WSL1可以直接使用localhost不一样,WSL2的display应当使用主机的IP,可以通过如下命令获得:

cat /etc/resolv.conf | grep "nameserver" |grep 192| cut -f 2 -d " " # 查看主机ip
host_ip=$(cat /etc/resolv.conf | grep "nameserver" |grep 192| cut -f 2 -d " ")
export DISPLAY=$host_ip:0.0
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/488793.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号