问题描述
我正在Python虚拟环境中开发程序。运行命令
python -m venv .venv
在Windows上,将 python
符号链接放入 .venv\Scripts\
而
python3 -m venv .venv
$ p $在macOS上p>
将符号链接放在
.venv / bin /
上。我使用Visual Studio Code进行开发,有一个.vscode\\settings.json
,它需要指向可执行文件的符号链接。例如{
python.pythonPath: .venv\\path\\to \\python,
}
如何强制
venv
可以将符号链接放置在相同的位置,而不管平台如何?
PS1。 git会忽略c $ c> .venv 文件夹并将其包含在
.gitignore
文件中,因为AFIK并不是很好的发行方式
PS2。为了避免XY问题,最终目标是在不同平台上拥有相同的开发环境。无论采用哪种解决方案,无论程序包管理器如何,Visual Studio Code都应该能够在不同平台上找到可执行文件的符号链接。
PS3。我需要找到一种方法来更改
__ VENV_BIN_NAME __
参数。
PS4。来自,一种可能的解决方案是使用
python.pythonPath: $ {env:PYTHON_INSTALL_LOC},
PS5。我问了另一个问题。
解决方案两件事。第一,您不能在Windows上使用
bin /
虚拟环境(请参见
二,Python扩展正在运行一项实验,以摆脱
python.pythonPath
可以解决您的冲突。请参见可以发布博客文章了解详细信息以及如何选择加入。I am developing a program inside a Python virtual environment. Running the command
python -m venv .venv
on Windows, puts the
python
symlink in.venv\Scripts\
whilepython3 -m venv .venv
on macOS puts the symlinks on
.venv/bin/
. I'm using Visual Studio Code for development and there is a.vscode\\settings.json
which needs to point towards the executable's symlinks. For example{ "python.pythonPath": ".venv\\path\\to\\python", }
How can I force the
venv
to put the symlinks in identical locations regardless of the platform?P.S.1. The
.venv
folder is ignored by git and is included in the.gitignore
file, as AFIK it is not a good practice to ship it with the codebase.P.S.2. To avoid XY-problem, the final goal is to have an identical development environment on different platforms. Whatever the solution, regardless of the package manager, Visual Studio Code should be able to find the executable's symlinks on different platforms.
P.S.3. I need to find a way to change the
__VENV_BIN_NAME__
parameter.P.S.4. From here, one possible solution might be to use
"python.pythonPath": "${env:PYTHON_INSTALL_LOC}",
instead.P.S.5. I asked another question here.
解决方案Two things. One, you can't have a virtual environment use
bin/
on Windows (see the rejected idea).Two, the Python extension is running an experiment to get rid of
python.pythonPath
which will solve your conflict. See the May release blog post for details and how to opt in.这篇关于强制venv将python的符号链接放置在macOS和Windows上的相同位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!