1

I use Visual Studio Code with flake8 linter but I don't know how to make a virtual environment with an access to globally installed package (flake8). virtualenv env --system-site-packages doesn't work like I would like because when I put a command pip freeze it shows me all global packages.

Sevy
  • 93
  • 10
  • Why not install `flake8` into the venv? – phd Dec 16 '19 at 15:48
  • 1
    @phd because it's not a solution and I don't want it there – Sevy Dec 16 '19 at 15:50
  • You're battling against your tools. Installing all necessary packages into every venv is the solution. Yes, there will be duplicates. – phd Dec 16 '19 at 15:52
  • @phd but flake8 is necessary for me, not for people who would pull my code from github for example. – Sevy Dec 16 '19 at 15:54
  • Nobody adds venvs to repositories. It's certainly one of the first thing to list in `.gitignore`. Anyway Python virtual environments are not portable. – phd Dec 16 '19 at 15:55
  • @phd I know but what about `pip freeze > requirements.txt` ? – Sevy Dec 16 '19 at 15:58
  • https://stackoverflow.com/a/53935334/7976758 – phd Dec 16 '19 at 16:04
  • `pip freeze | grep -v flake8 > requirements.txt` – phd Dec 16 '19 at 16:04
  • @phd that's what I wanted to know. thanks. – Sevy Dec 16 '19 at 16:07
  • 1
    That works not so good because `pip freeze` still outputs dependencies of `flake8`. Another approach we use at work: 2 parallel venvs, one "dirty" with development tools and one "clean" with only deployment dependencies. – phd Dec 16 '19 at 17:56

1 Answers1

1

You can set the "python.linting.flake8Path" setting to point to your global install of flake8.

As for keeping your dev tools separate from project's dependencies, pretty much all packaging tools for Python have a way to separate the two when listing dependencies. You can also keep a requirements.txt file that maintains your project's dependencies and a dev-requirements.txt that contains:

-r requirements.txt
flake8

and that can be what developers of your code install from.

Brett Cannon
  • 14,438
  • 3
  • 45
  • 40