如何在FreeBSD中默认设置Python版本?

2024-05-23 19:28:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试安装应用程序node,但在我的环境中默认为python 3,需要python 2.6。如何更改FreeBSD中的默认python版本?

# cd /usr/local/bin
# ls -l | grep python
-r-xr-xr-x   2 root  wheel  1246256 Jul 12  2011 python
-r-xr-xr-x   2 root  wheel     1401 Jul 12  2011 python-config
-r-xr-xr-x   2 root  wheel     6060 Jul 12  2011 python-shared
-r-xr-xr-x   2 root  wheel     1408 Jul 12  2011 python-shared-config
-r-xr-xr-x   1 root  wheel     3720 Jul 12  2011 python-shared2.6
-r-xr-xr-x   1 root  wheel     1431 Jul 12  2011 python-shared2.6-config
-r-xr-xr-x   2 root  wheel     6060 Jul 12  2011 python-shared3.1
-r-xr-xr-x   2 root  wheel     1408 Jul 12  2011 python-shared3.1-config
-r-xr-xr-x   1 root  wheel  1182056 Jul 12  2011 python2.6
-r-xr-xr-x   1 root  wheel     1424 Jul 12  2011 python2.6-config
-r-xr-xr-x   2 root  wheel  1246256 Jul 12  2011 python3.1
-r-xr-xr-x   2 root  wheel     1401 Jul 12  2011 python3.1-config

Tags: 版本confignode应用程序bin环境usrlocal
3条回答

您可以删除/usr/local/bin/python,并创建指向Python 2.6的符号链接:

rm /usr/local/bin/python
ln -s /usr/local/bin/python2.6 /usr/local/bin/python

您应该删除python元端口/usr/ports/lang/python。 然后在/etc/make.conf中设置以下变量:

PYTHON_DEFAULT_VERSION='python3.2'

(如果你想要最新的版本。或者也可以使用python3.1。目前,默认值是python2.7。)

现在再次安装/usr/ports/lang/python。 注意,端口可以请求另一个版本的python!

更新:自2013年10月以来,有一种新的设置默认版本的方法

20131003:
  AFFECTS: users of lang/python* and ports
  AUTHOR: mva@FreeBSD.org

  The default versions of lang/python* have been changed to support the
  new DEFAULT_VERSIONS variable.

  PYTHON_DEFAULT_VERSION, PYTHON2_DEFAULT_VERSION and
  PYTHON3_DEFAULT_VERSION are deprecated. If you have set them in your
  make.conf, you should change them something like

  DEFAULT_VERSIONS=python=2.7 python2=2.7 python3=3.3

从FreeBSD 12.0开始,正确答案如下。

  1. /tmp/makePatchPython3.6.patch中创建包含以下内容的文件:
1,2d0
< DEFAULT_VERSIONS += python=3.6
< 

这将在/etc/make.conf的开头添加一行,这将更改系统上使用的默认python。

[/usr/ports/lang/python]$ sudo make deinstall
[/usr/ports/lang/python]$ sudo patch /etc/make.conf /tmp/makePatchPython3.6.patch
[/usr/ports/lang/python]$ sudo make reinstall
[/usr/ports/lang/python]$ python --version
Python 3.6.8 # This will be different depending on which python version you install.

相关问题 更多 >