Skip to content

Instantly share code, notes, and snippets.

@Wtower
Last active January 27, 2020 10:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wtower/547f78a8eaec60fe0d85ce2436d1c62f to your computer and use it in GitHub Desktop.
Save Wtower/547f78a8eaec60fe0d85ce2436d1c62f to your computer and use it in GitHub Desktop.
Setup dev environment with VSCode on Windows

Setup dev environment with VSCode on Windows

This gist is intended to guide on how to setup a dev environment in Windows 7 for developers coming from a Linux background.

For Windows 10 see file win10.md below.

Install

Install

  • Git for Windows
  • Python3 for Windows
  • Cygwin
  • VSCode
  • Nodist

Cygwin packages

  • chere
  • fish
  • vim
  • openssh

GIT

Configure git global:

> git config --global user.name "George K"
> git config --global user.email gk@9-dev.com
> git config --global credential.helper store

Do not install cygwin git, in order to let cygwin use the windows installed git that VScode will also use with the same global config. You can check the path to the global config with git config --list --show-origin.

Open VScode and use command git: clone. The git credential manager will ask for password if necessary.

Virtualenv

A previous attempt to use fish through cygwin as default shell and virtualfish for virtualenv management failed miserably. Cygwin pip is unable to properly install basic project requirements. When creating the virtualenv through powershell, pip seems to work properly.

Install (open powershell as admin):

pip install virtualenv virtualenvwrapper-win

Create virtualenv and activate:

PS> Set-ExecutionPolicy RemoteSigned  # once only, to allow execute of activate
PS> virtualenv \Users\Wtower\Envs\my-env  # create virtualenv
PS> \Users\Wtower\Envs\Scripts\activate.ps1  # activate virtualenv
PS> Get-Command python  # check python executable
PS> setprojectdir \Users\Wtower\Workspace\my-project  # set the project dir for the virtualenv
PS> pip list  # verify the install packages for the virtualenv
PS> deactivate

After that clone project (vscode command git pull remote), install requirements and run django.

Specify virtualenv in VScode in workspace settings:

{
    "python.pythonPath": "C:\\Users\\wtower\\Envs\\my-env\\Scripts\\python.exe",
}

Extensions

VScode installed extensions:

> code --list-extensions
DavidAnson.vscode-markdownlint
donjayamanne.githistory
eg2.vscode-npm-script
mkaufman.HTMLHint
ms-python.python
ritwickdey.LiveServer
samschneller.git-add-remote
searKing.preview-vscode

Nodist

The nodist package seems to work better than nvm for windows, with less active issues. Install using the installer and append the env variables in PS.

Relevant links

Run Ansible within Cygwin

Cygwin packages

Install the following packages from Cygwin setup (see gist's readme):

  • curl
  • python2
  • python2-jinja
  • python2-crypto
  • python2-openssl
  • python2-setuptools
  • git
  • vim
  • openssh
  • openssl
  • openssl-devel
  • make
  • gcc-g++
  • python2-devel

Pypi packages

Manually download the latest packages from pypi.org:

  • PyYAML
  • Jinja2
  • paramiko

Then, for each package:

tar -xvf xxxxxx.tar.gz
cd xxxxxx
python setup.py install

Ansible

git clone https://github.com/ansible/ansible /opt/ansible --recursive

If using fish shell (should), load ansible path and exports but using the appropriate paths /opt/ansible.

https://gist.github.com/Wtower/970bf009f0a9c3b0733a

Due to unresolved issues with file module as of 24 Jan 2019, checkout to v2.6:

git -C /opt/ansible checkout stable-2.6

Useful links

New-Alias fish C:\cygwin64\bin\fish
function workon ($env)
{
& C:\Users\wtower\Envs\$env\Scripts\activate.ps1
}
function which($name)
{
Get-Command $name | Select-Object -ExpandProperty Definition
}
$env:Path += ";C:\Program Files (x86)\nodist\bin"
$env:NODIST_PREFIX = "C:\Program Files (x86)\nodist"
{
// Autofetch git remotes
"git.autofetch": true,
// Add horizontal ruler
"editor.rulers": [100],
// Powershell terminal
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
// Cygwin fish terminal
//"terminal.integrated.shell.windows": "C:\\Cygwin64\\bin\\bash.exe",
//"terminal.integrated.shellArgs.windows": ["/bin/xhere", "/bin/fish"],
}

Setup dev environment on Windows 10

The latest Linux beta subsystem for Windows 10 offers a far better alternative than Cygwin as described below.

Enable Linux

  • Open 'Settings'
  • Open 'Update & Security', 'For developers'.
  • Toggle the 'Developer mode' option, and accept any warnings Windows pops up.
  • Wait for Windows to install packages and restart if necessary.
  • Open 'Control Panel'
  • Click on 'Programs'
  • Click on 'Turn Windows features on or off'
  • Check 'Windows Subsystem for Linux (Beta)', and then click OK.
  • Install Ubuntu from Windows Store.

https://www.jeffgeerling.com/blog/2017/using-ansible-through-windows-10s-subsystem-linux

Install

Install

  • VSCode
  • Git for Windows
  • Python3 for Windows (not required on Linux, and not required if Visual Studio Python is enabled).

Fish

Apt works properly in the Linux subsystem, but Fish shell is not in this particular repository:

sudo apt-add-repository ppa:fish-shell/release-2
sudo apt-get update
sudo apt-get install fish

https://gist.github.com/Wtower/970bf009f0a9c3b0733a https://www.hanselman.com/blog/InstallingFishShellOnUbuntuOnWindows10.aspx

@Wtower
Copy link
Author

Wtower commented Jun 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment