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

问题描述 投票:13回答:4

我正在尝试安装应用程序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
python environment-variables freebsd
4个回答
6
投票

你可以删除/usr/local/bin/python并为Python 2.6创建一个符号链接:

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

26
投票

你应该删除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: [email protected]

  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

0
投票

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.


-2
投票
mv python python.old

ln -s /usr/bin/pythonX.X  /usr/bin/python

在X.X中写下你的版本

© www.soinside.com 2019 - 2024. All rights reserved.