gpt4 book ai didi

python - python 包安装位置与前缀不一致

转载 作者:行者123 更新时间:2023-12-01 09:20:07 24 4
gpt4 key购买 nike

我正在安装带有前缀的 python 包,并收到以下错误。

$ python3 setup.py install --prefix=$HOME/some_prefix
running install

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

/home/user/some_prefix/lib64/python3.4/site-packages/

and your PYTHONPATH environment variable currently contains:

''

我当然可以导出 PYTHONPATH=/home/user/some_prefix/lib64/python3.4/site-packages:$PYTHONPATH。但考虑到该路径有python版本,我从 How do I find the location of my Python site-packages directory? 找到了一个奇特的方法

$ python3 -c "import distutils.sysconfig as sc; print(sc.get_python_lib(prefix=\"$HOME/some_prefix\"));"
/home/user/some_prefix/lib/python3.4/site-packages

不幸的是,除了可以忽略不计的尾随 / 之外,它们在 lib 部分不匹配。所以还是失败了。

$ python3 setup.py install --prefix=$HOME/some_prefix
running install

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

/home/user/some_prefix/lib64/python3.4/site-packages/

and your PYTHONPATH environment variable currently contains:

'/home/user/some_prefix/lib/python3.4/site-packages'

现在,我该如何正确匹配它?

我检查了文档,但我认为没有相关的论据。

https://docs.python.org/3/distutils/apiref.html#module-distutils.sysconfigdistutils.sysconfig.get_python_lib([plat_specific[, standard_lib[, prefix]]])¶

$ python3 -c "import distutils.sysconfig as sc; print(sc.get_python_lib(\"A\", \"B\", \"C\"));"
C/lib64/python3.4

另外,哪个是正确的?是lib还是lib64?我在 /usr/lib 中看到更多软件包。

$ ll /usr/lib/python3.4/site-packages/ | wc
70 554 5408
$ ll /usr/lib64/python3.4/site-packages/ | wc
11 82 764

我使用的是来自 centos 7 的标准 python。

$ uname -a
Linux localhost 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
$ which python3
/usr/bin/python3
$ python3 --version
Python 3.4.8

最佳答案

Fedora/CentOS patches various Python module要更改安装位置,请参阅 this ServerFault post on the difference between /usr/lib and /usr/lib64 .

请注意,/usr/lib64 路径仅用于平台特定代码,而不用于纯 python 库。所以正确的使用方法是设置plat_specific argument to get_python_lib() (第一个)为 True:

$ python3 -c "import distutils.sysconfig as sc; print(sc.get_python_lib(True, prefix=\"$HOME/some_prefix\"))"

但是,如果您的目标前缀目录用于没有 Fedora/CentOS 补丁的单独 Python 安装,那么您实际上应该使用安装在该前缀中的 Python 二进制文件处理安装:

$HOME/some_prefix/bin/python3 setup.py install

它将配备所有正确的系统配置,包括未修补的 distutils 和具有正确本地 $PREFIX 值的 sysconfig 模块,并且不会发出 PYTHONPATH 警告。

如果您想将软件包与系统安装隔离,请使用 virtualenv并使用特定于环境的 Python 二进制文件进行安装:

$ virtualenv name_of_virtualenv_directory
$ name_of_virtualenv_directory/bin/python setup.py install

关于python - python 包安装位置与前缀不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50858012/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com