Skip to content

Instantly share code, notes, and snippets.

@WeltonThomasFerreira
Last active May 30, 2022 19:06
Show Gist options
  • Save WeltonThomasFerreira/178f560d2c3c9a6317513544ff97505e to your computer and use it in GitHub Desktop.
Save WeltonThomasFerreira/178f560d2c3c9a6317513544ff97505e to your computer and use it in GitHub Desktop.
Python in VS Code: Setup

Python in Visual Studio Code

Install python and the extensions

Python3

Extensions

Python environment tools

  1. pip (default)
  2. pipenv
  3. venv
  4. conda

Install pipenv and create Pipfile

pip install --user pipenv

Add pipenv to $PATH and enable .venv in project directory

# .bashrc || .zshrc

export PATH=$PATH:$HOME/.local/bin
export PIPENV_VENV_IN_PROJECT=1

pipenv init + shell

pipenv shell

Install dev dependencies

pipenv install autopep8 -d

Formatting and linting

VS Code Settings

Ctrl + Shift + I

Errors

Errno 2: Pipenv searches virtual environment's python binary in wrong path

Solution: replace 'posix_prefix' with 'venv' in file above:

$HOME/.local/lib/python3.10/site-packages/pipenv/environment.py
// .vscode
{
"recommendations": [
"ms-toolsai.jupyter",
"ms-toolsai.jupyter-keymap",
"ms-toolsai.jupyter-renderers",
"ms-python.vscode-pylance",
"ms-python.python",
"VisualStudioExptTeam.vscodeintellicode"
]
}
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
[dev-packages]
autopep8 = "*"
[requires]
python_version = "3.10"
// .vscode
{
"python.linting.enabled": true,
"python.linting.pycodestyleEnabled": true,
"python.formatting.autopep8Path": ".venv/bin/autopep8"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment