【问题标题】:How to set Python version by default in FreeBSD?如何在 FreeBSD 中默认设置 Python 版本?
【发布时间】:2012-03-10 03:02:26
【问题描述】:

我正在尝试安装应用程序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


    【解决方案1】:

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

    PYTHON_DEFAULT_VERSION='python3.2'
    

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

    现在再次安装/usr/ports/lang/python。 请注意,ports 可以请求另一个版本的 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
    

    【讨论】:

    • 感谢您更新您的答案!!!!当我看到您答案中已过时的更新部分时,我知道这已经改变了,并且正要再次谷歌寻找答案。
    • 您能解释一下应该如何删除元端口吗?
    【解决方案2】:

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

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

    【讨论】:

    • 这必须在每次更新默认 python 后重做!端口 makefile 中的安装后目标将特定于版本的二进制文件硬链接到无版本的二进制文件。
    • zeekay 你摇滚,我的朋友。在尝试完成这项工作并阅读数十条愚蠢的回复的痛苦之后......大多数其他回复试图告诉你你不应该这样做,因为......但我无法安装明确的软件调用“python”期望它被连接到 python3.6 或其他。所以,头部游戏是没有用的。谢谢这有效!谢谢...谢谢...
    【解决方案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.
    
    

    【讨论】:

      【解决方案4】:
      mv python python.old
      
      ln -s /usr/bin/pythonX.X  /usr/bin/python
      

      在 X.X 中写下你的版本

      【讨论】:

        猜你喜欢
        • 2016-04-29
        • 2020-04-09
        • 1970-01-01
        • 2020-02-10
        • 1970-01-01
        • 2018-01-14
        • 2018-02-20
        • 1970-01-01
        相关资源
        最近更新 更多