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

Ops*_*psa 13 python freebsd environment-variables

我正在尝试安装应用程序节点,但默认情况下我的环境是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
Run Code Online (Sandbox Code Playgroud)

Rol*_*ith 26

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

PYTHON_DEFAULT_VERSION='python3.2'
Run Code Online (Sandbox Code Playgroud)

(如果你想要最新版本.或者你也可以使用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
Run Code Online (Sandbox Code Playgroud)


zee*_*kay 6

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

rm /usr/local/bin/python
ln -s /usr/local/bin/python2.6 /usr/local/bin/python
Run Code Online (Sandbox Code Playgroud)

  • 每次更新默认python后必须重做一次!端口makefile中的安装后目标将特定于版本的二进制文件硬链接到无版本的二进制文件。 (2认同)