Issue: pip install peewee fails on Windows
Author: Mastergalen
State: closed
Created: 2018-02-24 15:45:31

`pip install peewee` in an administrator PowerShell fails due to `error: [WinError 2] The system cannot find the file specified`

* OS: Windows 10
* Python: 3.6.4 Anaconda 64 bit
* Cython v0.27.3

The same error occurs when installing via git:

```
git clone https://github.com/coleifer/peewee.git
cd peewee
python setup.py install
```

## Full error
```
PS C:\WINDOWS\system32> pip install peewee
Collecting peewee
  Using cached peewee-3.1.0.tar.gz
Building wheels for collected packages: peewee
  Running setup.py bdist_wheel for peewee ... error
  Complete output from command c:\programdata\anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\MASTER~1\\AppData\\Local\\Temp\\pip-build-t74nv3gg\\peewee\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\MASTER~1\AppData\Local\Temp\tmp9jj2p59dpip-wheel- --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.6
  copying peewee.py -> build\lib.win-amd64-3.6
  copying pwiz.py -> build\lib.win-amd64-3.6
  creating build\lib.win-amd64-3.6\playhouse
  copying playhouse\apsw_ext.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\dataset.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\db_url.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\fields.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\flask_utils.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\hybrid.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\migrate.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\pool.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\postgres_ext.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\reflection.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\shortcuts.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\signals.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\sqlcipher_ext.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\sqliteq.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\sqlite_ext.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\sqlite_udf.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\test_utils.py -> build\lib.win-amd64-3.6\playhouse
  copying playhouse\__init__.py -> build\lib.win-amd64-3.6\playhouse
  running build_ext
  error: [WinError 2] The system cannot find the file specified

  ----------------------------------------
  Failed building wheel for peewee
  Running setup.py clean for peewee
Failed to build peewee
Installing collected packages: peewee
  Running setup.py install for peewee ... error
    Complete output from command c:\programdata\anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\MASTER~1\\AppData\\Local\\Temp\\pip-build-t74nv3gg\\peewee\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\MASTER~1\AppData\Local\Temp\pip-i4m4596t-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.6
    copying peewee.py -> build\lib.win-amd64-3.6
    copying pwiz.py -> build\lib.win-amd64-3.6
    creating build\lib.win-amd64-3.6\playhouse
    copying playhouse\apsw_ext.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\dataset.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\db_url.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\fields.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\flask_utils.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\hybrid.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\migrate.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\pool.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\postgres_ext.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\reflection.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\shortcuts.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\signals.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\sqlcipher_ext.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\sqliteq.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\sqlite_ext.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\sqlite_udf.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\test_utils.py -> build\lib.win-amd64-3.6\playhouse
    copying playhouse\__init__.py -> build\lib.win-amd64-3.6\playhouse
    running build_ext
    error: [WinError 2] The system cannot find the file specified

    ----------------------------------------
Command "c:\programdata\anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\MASTER~1\\AppData\\Local\\Temp\\pip-build-t74nv3gg\\peewee\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\MASTER~1\AppData\Local\Temp\pip-i4m4596t-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\MASTER~1\AppData\Local\Temp\pip-build-t74nv3gg\peewee\

PS C:\WINDOWS\system32> python --version
Python 3.6.4 :: Anaconda custom (64-bit)
```

+1 This error is often due to dependency of GCC, however for me it still fails on WSL (GCC installed via `sudo apt-get install build-essentials`)

I don't understand that traceback. What file is missing? Is this a recent regression or common to all 3.x?

Do you have a C compiler and Cython installed? Have you tried installing different versions?

https://www.microsoft.com/en-us/download/details.aspx?id=44266

My guess is that you have Cython installed, but perhaps it was installed as a binary package, and that you don't actually have a C compiler? The setup.py for peewee checks if you have Cython, and only if you have Cython, will it include instructions for building the C extensions... So my guess is that Cython is there, but somehow the build_ext command is failing when attempting to compile the actual extension?

@coleifer 

I am running WSL (Windows subsystem linux) which in my case using Ubuntu distro so no, there is no need for Cython.

The build essential should be enough for a C and C++ compiler
```bash
sudo apt-get install build-essential
```

## Linux (WSL) Error
The WSL is similar to @Mastergalen's error interestingly.

```
pip install peewee
Collecting peewee
  Using cached peewee-3.1.0.tar.gz
Building wheels for collected packages: peewee
  Running setup.py bdist_wheel for peewee ... error
  Complete output from command /home/keto/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-t_5tqb83/peewee/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmproueelbcpip-wheel- --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  copying peewee.py -> build/lib.linux-x86_64-3.6
  copying pwiz.py -> build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/__init__.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/apsw_ext.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/dataset.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/db_url.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/fields.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/flask_utils.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/hybrid.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/migrate.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/pool.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/postgres_ext.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/reflection.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/shortcuts.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/signals.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/sqlcipher_ext.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/sqlite_ext.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/sqlite_udf.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/sqliteq.py -> build/lib.linux-x86_64-3.6/playhouse
  copying playhouse/test_utils.py -> build/lib.linux-x86_64-3.6/playhouse
  running build_ext
  cythoning playhouse/_speedups.pyx to playhouse/_speedups.c
  building 'playhouse._speedups' extension
  creating build/temp.linux-x86_64-3.6
  creating build/temp.linux-x86_64-3.6/playhouse
  gcc -pthread -B /home/keto/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/keto/anaconda3/include/python3.6m -c playhouse/_speedups.c -o build/temp.linux-x86_64-3.6/playhouse/_speedups.o
  gcc -pthread -shared -B /home/keto/anaconda3/compiler_compat -L/home/keto/anaconda3/lib -Wl,-rpath=/home/keto/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.6/playhouse/_speedups.o -L/home/keto/anaconda3/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/playhouse/_speedups.cpython-36m-x86_64-linux-gnu.so
  cythoning playhouse/_sqlite_udf.pyx to playhouse/_sqlite_udf.c
  building 'playhouse._sqlite_udf' extension
  gcc -pthread -B /home/keto/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/keto/anaconda3/include/python3.6m -c playhouse/_sqlite_udf.c -o build/temp.linux-x86_64-3.6/playhouse/_sqlite_udf.o
  gcc -pthread -shared -B /home/keto/anaconda3/compiler_compat -L/home/keto/anaconda3/lib -Wl,-rpath=/home/keto/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.6/playhouse/_sqlite_udf.o -L/home/keto/anaconda3/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/playhouse/_sqlite_udf.cpython-36m-x86_64-linux-gnu.so
  cythoning playhouse/_sqlite_ext.pyx to playhouse/_sqlite_ext.c
  warning: playhouse/_sqlite_ext.pyx:313:57: local variable 'pNew' referenced before assignment
  warning: playhouse/_sqlite_ext.pyx:341:55: local variable 'pCur' referenced before assignment
  warning: playhouse/_sqlite_ext.pyx:1017:48: local variable 'bf' referenced before assignment
  building 'playhouse._sqlite_ext' extension
  gcc -pthread -B /home/keto/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/keto/anaconda3/include/python3.6m -c playhouse/_sqlite_ext.c -o build/temp.linux-x86_64-3.6/playhouse/_sqlite_ext.o
  playhouse/_sqlite_ext.c:531:21: fatal error: sqlite3.h: No such file or directory
  compilation terminated.
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for peewee
  Running setup.py clean for peewee
Failed to build peewee
Installing collected packages: peewee
  Running setup.py install for peewee ... error
    Complete output from command /home/keto/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-t_5tqb83/peewee/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-jszvpzby-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    copying peewee.py -> build/lib.linux-x86_64-3.6
    copying pwiz.py -> build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/__init__.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/apsw_ext.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/dataset.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/db_url.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/fields.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/flask_utils.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/hybrid.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/migrate.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/pool.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/postgres_ext.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/reflection.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/shortcuts.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/signals.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/sqlcipher_ext.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/sqlite_ext.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/sqlite_udf.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/sqliteq.py -> build/lib.linux-x86_64-3.6/playhouse
    copying playhouse/test_utils.py -> build/lib.linux-x86_64-3.6/playhouse
    running build_ext
    skipping 'playhouse/_speedups.c' Cython extension (up-to-date)
    building 'playhouse._speedups' extension
    creating build/temp.linux-x86_64-3.6
    creating build/temp.linux-x86_64-3.6/playhouse
    gcc -pthread -B /home/keto/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/keto/anaconda3/include/python3.6m -c playhouse/_speedups.c -o build/temp.linux-x86_64-3.6/playhouse/_speedups.o
    gcc -pthread -shared -B /home/keto/anaconda3/compiler_compat -L/home/keto/anaconda3/lib -Wl,-rpath=/home/keto/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.6/playhouse/_speedups.o -L/home/keto/anaconda3/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/playhouse/_speedups.cpython-36m-x86_64-linux-gnu.so
    skipping 'playhouse/_sqlite_udf.c' Cython extension (up-to-date)
    building 'playhouse._sqlite_udf' extension
    gcc -pthread -B /home/keto/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/keto/anaconda3/include/python3.6m -c playhouse/_sqlite_udf.c -o build/temp.linux-x86_64-3.6/playhouse/_sqlite_udf.o
    gcc -pthread -shared -B /home/keto/anaconda3/compiler_compat -L/home/keto/anaconda3/lib -Wl,-rpath=/home/keto/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.6/playhouse/_sqlite_udf.o -L/home/keto/anaconda3/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/playhouse/_sqlite_udf.cpython-36m-x86_64-linux-gnu.so
    skipping 'playhouse/_sqlite_ext.c' Cython extension (up-to-date)
    building 'playhouse._sqlite_ext' extension
    gcc -pthread -B /home/keto/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/keto/anaconda3/include/python3.6m -c playhouse/_sqlite_ext.c -o build/temp.linux-x86_64-3.6/playhouse/_sqlite_ext.o
    playhouse/_sqlite_ext.c:531:21: fatal error: sqlite3.h: No such file or directory
    compilation terminated.
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/home/keto/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-t_5tqb83/peewee/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-jszvpzby-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-t_5tqb83/peewee/
```


Cython is installed
```
$ pip show cython
Name: Cython
Version: 0.27.3
Location: c:\programdata\anaconda3\lib\site-packages
```

Installing the latest Visual Studio Build Tools produces the same error as before.

I'm temporarily working around this by just setting `cython_installed = False` in `setup.py`

Thanks for sharing the traceback, this is the problem:

```
playhouse/_sqlite_ext.c:531:21: fatal error: sqlite3.h: No such file or directory
```

It looks like you've got Cython and a C compiler installed, but are missing the SQLite3 headers. You should be able to:

```
sudo apt-get install libsqlite3-dev
```

I wonder if there's a way, in setup.py, to test for the existence of the appropriate headers?

Regarding checking for the existence of the appropriate headers, just look at the lengths one has to go to:

https://github.com/PyTables/PyTables/blob/develop/setup.py

Unfortunately, I don't think this is one I'm going to be able to fix... If you have a compiler and Cython, you'll need libsqlite3 as well.

I'm open to fixing if there's a clean way of doing it... I'm not very keen on setup.py so someone may have good ideas.

Got this error again and forgot `sudo apt-get install libsqlite3-dev`, would it be possible to print a reminder note on pip installs?

I'm not sure how one would know to display a warning.

> `sudo apt-get install libsqlite3-dev`

Thanks!
Maybe it should be specified in the [installation docs](http://docs.peewee-orm.com/en/latest/peewee/installation.html#installing-and-testing)?