【问题标题】:How to change python-config version on ubuntu如何在 ubuntu 上更改 python-config 版本
【发布时间】:2023-09-25 07:05:01
【问题描述】:

我已经在我的桌面上安装了 python3.6,里面已经有 python3.5 和 python2.7。我将 python 和 python3 的默认路径更改为 python3.6,但似乎 python-config 仍在 python2.7 上,而 python3-config 仍在 python3.5 上。如何将默认的 python3-config 或 python-config 更改为 python3.6-config? 感谢您的帮助!

【问题讨论】:

  • python-config 通常是一个符号链接,因此您需要删除它们并将其指向正确的 python-config 版本

标签: python-config


【解决方案1】:

所以为了详细说明我的评论,python 通常附带一个这样的版本

ls -lisa /usr/local/bin/ | grep python
34138948    16 -r-xr-xr-x    2 root  wheel      5248 15 Apr. 03:12 python3.7
34138954     0 lrwxr-xr-x    1 root  wheel        17 15 Apr. 03:12 python3.7-config -> python3.7m-config
34138948    16 -r-xr-xr-x    2 root  wheel      5248 15 Apr. 03:12 python3.7m
34138949     8 -r-xr-xr-x    1 root  wheel      2936 15 Apr. 03:12 python3.7m-config
34127071    16 -r-xr-xr-x    1 root  wheel      5216 15 Apr. 10:59 python3.9
34127072     8 -r-xr-xr-x    1 root  wheel      3153 15 Apr. 10:59 python3.9-config

您可以看到一些名称已经是符号链接(带有 -> 的一次),因此如果您想以 python3-config 的形式访问 python3.9-config,您需要创建一个名称为 python3-config 的符号链接,指向二进制python3.9-config。

% sudo ln -s /usr/local/bin/python3.9-config /usr/local/bin/python3-config

所以现在应该给你

% which python3-config
/usr/local/bin/python3-config

再次查看目录会显示符号链接

% ls -lisa /usr/local/bin | grep python3
34127092     0 lrwxr-xr-x    1 root  wheel        31 22 Juni 14:09 python3-config -> /usr/local/bin/python3.9-config
34138948    16 -r-xr-xr-x    2 root  wheel      5248 15 Apr. 03:12 python3.7
34138954     0 lrwxr-xr-x    1 root  wheel        17 15 Apr. 03:12 python3.7-config -> python3.7m-config
34138948    16 -r-xr-xr-x    2 root  wheel      5248 15 Apr. 03:12 python3.7m
34138949     8 -r-xr-xr-x    1 root  wheel      2936 15 Apr. 03:12 python3.7m-config
34127071    16 -r-xr-xr-x    1 root  wheel      5216 15 Apr. 10:59 python3.9
34127072     8 -r-xr-xr-x    1 root  wheel      3153 15 Apr. 10:59 python3.9-config

干杯

马库斯

【讨论】:

  • 我有一个系统链接的例子,那里是你的朋友
  • 感谢您的帮助,它确实显示了符号链接。但似乎当我输入: python3-config --libs 它仍然显示: -lpython3.5m -lpthread -ldl -lutil -lm
  • 再次,您可能需要先删除现有的符号链接,如果 python3-config 指向 python3.5-config 则创建一个新符号链接,它将查看 3.5 的 configdir