flathub / flathub/com.visualstudio.code

Symlinks in python virtual environments will not work on systems that do not follow PEP 394

未关闭
#82 0 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Shell
星标
217
派生
82
平均合并
1 天 7 小时
30 天内合并 PR
1

描述

This is a combination of several quirks on the whole OS chain and I'm not entirely sure who should be considered responsible, so please tell me if it belongs elsewhere.

* Flatpak, as recommanded by [PEP 394][1], uses `python2` as the default `python` interpreter. That convention was put into place after Arch Linux (the distribution I'm currently using) decided to make `python3` the default interpreter instead.
* Python venv creates symlinks to the system binaries [for Python 3 specifically][2]. It [creates symlinks to `env_exe`, which normally points towards `/usr/bin/python3`][3], and appears to collapse those absolute symlinks into relative ones if multiple symlinks point towards the same binary. Thus:

```
$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root 7 26 mar 17:43 /usr/bin/python -> python3
lrwxrwxrwx 1 root root 9 26 mar 17:43 /usr/bin/python3 -> python3.7
-rwxr-xr-x 2 root root 14120 26 mar 17:43 /usr/bin/python3.7

$ mkdir test-python
$ cd test-python/
$ python -m venv .pyenv
$ ls -l .pyenv/bin/python*
lrwxrwxrwx 1 user user 15 1 jun 22:05 .pyenv/bin/python -> /usr/bin/python
lrwxrwxrwx 1 user user 6 1 jun 22:05 .pyenv/bin/python3 -> python
```

This would normally be harmless, except it creates a situation where both symlinks would, if executed inside the flatpak sandbox, point towards a python 2.7 executable. Creating the virtual environment through the internal VSCode terminal, which would be running from inside the Flatpak sandbox, creates the symlinks correctly.

```
sh-4.4$ python --version
Python 2.7.16
sh-4.4$ python3 -m venv .pyenv
sh-4.4$ ls -l .pyenv/bin/python*
lrwxrwxrwx 1 user user 7 Jun 1 22:36 .pyenv/bin/python -> python3
lrwxrwxrwx 1 user user 16 Jun 1 22:36 .pyenv/bin/python3 -> /usr/bin/python3
```

With all of that said, I have no idea who is supposed to be at fault here. I'm starting by submitting this here since I do not believe that this bug can surface anywhere else. Everyone is technically doing their part correctly, but the combination of non-issues ends up creating a non-trivial problem.

[1]:https://www.python.org/dev/peps/pep-0394/
[2]:https://www.python.org/dev/peps/pep-0405/
[3]: https://github.com/python/cpython/blob/3.7/Lib/venv/__init__.py#L202-L224

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。