Sanic: Installing Sanic on Ubuntu 16.04 LTS and Python 3.6

Created on 29 Nov 2018  路  9Comments  路  Source: sanic-org/sanic

Description:
Tried to install sanic with pip install sanic.

Collecting sanic
  Using cached https://files.pythonhosted.org/packages/31/56/537629e5bba8e15e43d411e492f1c83b8242d5b2e5066a3f4acff66bb355/sanic-0.8.3-py3-none-any.whl
Collecting uvloop>=0.5.3; sys_platform != "win32" and implementation_name == "cpython" (from sanic)
  Using cached https://files.pythonhosted.org/packages/53/71/154f98e003df68cbd95704c98cec1f2d09e271651f6232bafa1b2c2dc02f/uvloop-0.11.3-cp36-cp36m-manylinux1_x86_64.whl
Collecting aiofiles>=0.3.0 (from sanic)
  Using cached https://files.pythonhosted.org/packages/cf/f2/a67a23bc0bb61d88f82aa7fb84a2fb5f278becfbdc038c5cbb36c31feaf1/aiofiles-0.4.0-py3-none-any.whl
Collecting ujson>=1.35; sys_platform != "win32" and implementation_name == "cpython" (from sanic)
  Using cached https://files.pythonhosted.org/packages/16/c4/79f3409bc710559015464e5f49b9879430d8f87498ecdc335899732e5377/ujson-1.35.tar.gz
Collecting httptools>=0.0.9 (from sanic)
  Using cached https://files.pythonhosted.org/packages/a3/75/40cdb732e8ef547d9f34ceb83c43ea7188c0ffb719ddc6a1ad160464292d/httptools-0.0.11.tar.gz
Collecting multidict<5.0,>=4.0 (from sanic)
  Using cached https://files.pythonhosted.org/packages/71/cc/ceb5b8c76e7a23212b9e0353053cc35a9d86c763d852a76d9b941fe81fbc/multidict-4.5.2-cp36-cp36m-manylinux1_x86_64.whl
Collecting websockets<6.0,>=5.0 (from sanic)
  Using cached https://files.pythonhosted.org/packages/44/09/c48fd04e293b999aaa1f78c32376d241aa042fce09475f9107ae2e811554/websockets-5.0.1-cp36-cp36m-manylinux1_x86_64.whl
Building wheels for collected packages: ujson, httptools
  Running setup.py bdist_wheel for ujson ... error
  Complete output from command /home/devansh/.virtualenvs/sas-sanic/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-vkxh9k7e/ujson/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/pip-wheel-7y5x9693 --python-tag cp36:
  running bdist_wheel
  running build
  running build_ext
  building 'ujson' extension
  creating build
  creating build/temp.linux-x86_64-3.6
  creating build/temp.linux-x86_64-3.6/python
  creating build/temp.linux-x86_64-3.6/lib
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I./python -I./lib -I/usr/include/python3.6m -I/home/devansh/.virtualenvs/sas-sanic/include/python3.6m -c ./python/ujson.c -o build/temp.linux-x86_64-3.6/./python/ujson.o -D_GNU_SOURCE
  In file included from ./python/ujson.c:39:0:
  ./python/py_defines.h:39:20: fatal error: Python.h: No such file or directory
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for ujson
  Running setup.py clean for ujson
  Running setup.py bdist_wheel for httptools ... error
  Complete output from command /home/devansh/.virtualenvs/sas-sanic/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-vkxh9k7e/httptools/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/pip-wheel-grddb447 --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/httptools
  copying httptools/__init__.py -> build/lib.linux-x86_64-3.6/httptools
  creating build/lib.linux-x86_64-3.6/httptools/parser
  copying httptools/parser/__init__.py -> build/lib.linux-x86_64-3.6/httptools/parser
  copying httptools/parser/errors.py -> build/lib.linux-x86_64-3.6/httptools/parser
  running egg_info
  writing httptools.egg-info/PKG-INFO
  writing dependency_links to httptools.egg-info/dependency_links.txt
  writing top-level names to httptools.egg-info/top_level.txt
  reading manifest file 'httptools.egg-info/SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  writing manifest file 'httptools.egg-info/SOURCES.txt'
  copying httptools/parser/parser.c -> build/lib.linux-x86_64-3.6/httptools/parser
  running build_ext
  building 'httptools.parser.parser' extension
  creating build/temp.linux-x86_64-3.6
  creating build/temp.linux-x86_64-3.6/httptools
  creating build/temp.linux-x86_64-3.6/httptools/parser
  creating build/temp.linux-x86_64-3.6/vendor
  creating build/temp.linux-x86_64-3.6/vendor/http-parser
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.6m -I/home/devansh/.virtualenvs/sas-sanic/include/python3.6m -c httptools/parser/parser.c -o build/temp.linux-x86_64-3.6/httptools/parser/parser.o -O2
  httptools/parser/parser.c:4:20: fatal error: Python.h: No such file or directory
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for httptools
  Running setup.py clean for httptools
Failed to build ujson httptools
Installing collected packages: uvloop, aiofiles, ujson, httptools, multidict, websockets, sanic
  Running setup.py install for ujson ... error
    Complete output from command /home/devansh/.virtualenvs/sas-sanic/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-vkxh9k7e/ujson/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-record-m0ymdv4r/install-record.txt --single-version-externally-managed --compile --install-headers /home/devansh/.virtualenvs/sas-sanic/include/site/python3.6/ujson:
    running install
    running build
    running build_ext
    building 'ujson' extension
    creating build
    creating build/temp.linux-x86_64-3.6
    creating build/temp.linux-x86_64-3.6/python
    creating build/temp.linux-x86_64-3.6/lib
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I./python -I./lib -I/usr/include/python3.6m -I/home/devansh/.virtualenvs/sas-sanic/include/python3.6m -c ./python/ujson.c -o build/temp.linux-x86_64-3.6/./python/ujson.o -D_GNU_SOURCE
    In file included from ./python/ujson.c:39:0:
    ./python/py_defines.h:39:20: fatal error: Python.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/home/devansh/.virtualenvs/sas-sanic/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-vkxh9k7e/ujson/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-record-m0ymdv4r/install-record.txt --single-version-externally-managed --compile --install-headers /home/devansh/.virtualenvs/sas-sanic/include/site/python3.6/ujson" failed with error code 1 in /tmp/pip-install-vkxh9k7e/ujson/

Follwed the #1259 but it doesn't work for me.

Environment:

  • OS: [ubuntu 16.04]
  • Python Version: 3.6
  • Pip Vesion:18.1

Most helpful comment

@Devansh3790 follow your original install process where you insta soles it from ppa and after that install the python Dev package using apt-get install python3.6-dev.. This will add all the necessary headers.

All 9 comments

Hello, @Devansh3790 ! I think you need to install the python-dev (or python-devel, python-headers, I don't remember) package on your system (or something like that, I do not use Debian based systems for a long time now), because Cython can't find the Python headers to compile some of the dependencies (in the error you got, ujson to be more specific). Let me know if this works for you :wink:

Oh, I just saw that you tried to install the headers already (from #1259). Did you installed your Python 3.6 version using another method - pyenv, etc?

@vltr I followed steps to install python3.6.

Oh, ok, from a PPA. From what I could see in the repository, you can try to install the python3.6-dev package:

[sudo] apt-get install python3.6-dev

And, after that, repeat the installation process for Sanic and see if it works. Maybe you'll need to recreate your virtual environment, but this is just a hunch.

Tried to install with using Python3.6 but didn't work. With python 3.5 &3.7 installed.

Please review the issue.

@Devansh3790 thanks for the feedback! As I told you, the error you got is based on the fact that your Python environment does not have the respective Python source code / headers, so third party modules written in C can't compile against, hence the line ./python/py_defines.h:39:20: fatal error: Python.h: No such file or directory within the output from your installation attempt. You were able to install Sanic in other environments because you actually had the headers - you can search in our filesystem for the Python.h file and you'll certainly find for versions 3.5 and 3.7 (that you claim to be working), but not for Python 3.6 (you can try that by running find /usr -type f | grep "Python.h").

One other option you can consider (to workaround this issue in your environment) is to install Sanic without uvloop:

SANIC_NO_UVLOOP=true pip install sanic

And see if that helps, at least to get started with Sanic :wink:

I'm going to go ahead and close this since the correct solution - installing the python headers from the appropriate dev package - has been given.

I removed python3.6 from my system and installed it from python.org's Python-3.6.7.tar.xz.

But still facing the same issue installed python3.7 in the same way.

@Devansh3790 follow your original install process where you insta soles it from ppa and after that install the python Dev package using apt-get install python3.6-dev.. This will add all the necessary headers.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mobdim picture mobdim  路  4Comments

graingert picture graingert  路  3Comments

vlad0337187 picture vlad0337187  路  3Comments

Souldat picture Souldat  路  3Comments

jasonab picture jasonab  路  3Comments