我正在安装带有前缀的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:
''
我当然可以export PYTHONPATH=/home/user/some_prefix/lib64/python3.4/site-packages:$PYTHONPATH
.但是鉴于该路径具有python版本,我从如何找到我的Python站点包目录的位置中找到了一个奇特的方法?
$ 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.sysconfig distutils.sysconfig.get_python_lib([plat_specific[, standard_lib[, 前缀]]](¶
$ 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修补各种Python模块来改变安装位置,请参阅这篇ServerFault帖子关于/usr/lib
和/usr/lib64
之间的区别。
请注意,/usr/lib64
路径仅用于特定于平台的代码,而不用于纯 python 库。因此,正确的方法是将plat_specific
参数设置为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