1

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\ while

python3 -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.

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
  • I'd recommend that you read the all of the answers and comments on this question before you add `.vscode/settings.json` to source control - https://stackoverflow.com/questions/32964920/should-i-commit-the-vscode-folder-to-source-control – Ben Cottrell May 23 '20 at 17:30

2 Answers2

2

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.

Brett Cannon
  • 14,438
  • 3
  • 45
  • 40
  • on Windows vscode automatically detects the python executable but not the others such as pylint... on macOS I had to explicitly specify the location in 'settings.json'. – Foad S. Farimani May 25 '20 at 22:46
1

Why does it matter where each OS puts the venv python? If you've correctly made sure that .venv is not in the code base but making sure it's in .gitignore than it doesn't matter if someone who loads up your code even need venv. It's good practice and guarantees that whoever has your code on whichever OS their python, with any dependencies your program needs, is going to be used.

If you are using multiple OS to develop than, create a workspace or project .vscode settings file with those specific settings to the python you want to use but also make sure that .vscode directory in your project is in your .gitignore. Then set up separate .vscode settings on different machines for those OS-specific settings.

macshaggy
  • 357
  • 1
  • 4
  • 17