我正在尝试安装应用程序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
答案 0 :(得分: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: 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
答案 1 :(得分:6)
您可以删除/usr/local/bin/python
并创建Python 2.6的符号链接:
rm /usr/local/bin/python
ln -s /usr/local/bin/python2.6 /usr/local/bin/python
答案 2 :(得分:0)
从FreeBSD 12.0开始的正确答案如下。
/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.
答案 3 :(得分:-1)
mv python python.old
ln -s /usr/bin/pythonX.X /usr/bin/python
X.X中的写下你的版本