windows に uswgi を インストール
はじめに
windowsにuswgiをインストールしようとしたとき四苦八苦したので、メモ。
やりたいことはflaskのwebアプリを外部公開。
そのために考えられる方法は、以下。
- nginx + uswgi
- docker + nginx + uswgi
- apach + mod_wsgi
一番オーソドックスな1でやろうと思ったけど、
OSがcentOSでやってる例が多いし、uswgiがインストールできなくて、
2の方が楽かと思ってdockerと格闘してたら、
uswgiの公式に「windowsでもcywin使ってコンパイルすればできる」
と書いてあったので結局1にしました。
導入したい人は一番下の導入方法まで読み進めてください。
エラーTips
普通にpipでインストール
C:\Users\hoge\Documents\nginx>pip install uwsgi Collecting uwsgi Using cached uwsgi-2.0.15.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\hoge\AppData\Local\Temp\pip-build-omtv90kd\uwsgi\setup.py", line 3, in <module> import uwsgiconfig as uc File "C:\Users\hoge\AppData\Local\Temp\pip-build-omtv90kd\uwsgi\uwsgiconfig.py", line 8, in <module> uwsgi_os = os.uname()[0] AttributeError: module 'os' has no attribute 'uname' ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in C:\Users\hoge\AppData\Local\Temp\pip-build-omtv90kd\uwsgi\
windowsでosのアトリビュートは扱えないと怒られる。
→cywinでインストールしましょう。
cywinを使ってpipでインストール
hoge@DESKTOP-23IK6DO ~ $ pip3 install uswgi Collecting uswgi Exception: Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/usr/lib/python3.6/site-packages/pip/commands/install.py", line 335, in run wb.build(autobuilding=True) File "/usr/lib/python3.6/site-packages/pip/wheel.py", line 749, in build self.requirement_set.prepare_files(self.finder) File "/usr/lib/python3.6/site-packages/pip/req/req_set.py", line 380, in prepare_files ignore_dependencies=self.ignore_dependencies)) File "/usr/lib/python3.6/site-packages/pip/req/req_set.py", line 554, in _prepare_file require_hashes File "/usr/lib/python3.6/site-packages/pip/req/req_install.py", line 278, in populate_link self.link = finder.find_requirement(self, upgrade) File "/usr/lib/python3.6/site-packages/pip/index.py", line 465, in find_requirement all_candidates = self.find_all_candidates(req.name) File "/usr/lib/python3.6/site-packages/pip/index.py", line 423, in find_all_candidates for page in self._get_pages(url_locations, project_name): File "/usr/lib/python3.6/site-packages/pip/index.py", line 568, in _get_pages page = self._get_page(location) File "/usr/lib/python3.6/site-packages/pip/index.py", line 683, in _get_page return HTMLPage.get_page(link, session=self.session) File "/usr/lib/python3.6/site-packages/pip/index.py", line 795, in get_page resp.raise_for_status() File "/usr/lib/python3.6/site-packages/requests/models.py", line 909, in raise_for_status raise HTTPError(http_error_msg, response=self) pip._vendor.requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://pypi.python.org/simple/uswgi/
何故かサーバーにつながらない
→gitからuswgiをダウンロードしてインストールしましょう。
ダウンロードしたフォルダをcywinのフォルダに入れて「setup.py」のある場所でpython3 setup.py install
・ソースを落として直接インストール
hoge@DESKTOP-23IK6DO /uwsgi-master/uwsgi-master $ python3 setup.py install using profile: buildconf/default.ini detected include path: ['/usr/include', '/usr/local/include'] Traceback (most recent call last): File "/uwsgi-master/uwsgi-master/uwsgiconfig.py", line 739, in __init__ gcc_version_components = gcc_version.split('.') AttributeError: 'NoneType' object has no attribute 'split' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "setup.py", line 140, in <module> install_requires=get_extra_require() File "setup.py", line 118, in get_extra_require conf = uc.uConf(get_profile()) File "/uwsgi-master/uwsgi-master/uwsgiconfig.py", line 747, in __init__ raise Exception("you need a C compiler to build uWSGI") Exception: you need a C compiler to build uWSGI
C compilerがないと怒られる。 →cywinのインストーラ「setup-x86_64.exe」からコンパイラのパッケージを導入しましょう。 パッケージ名は「gcc-core: GNU Compiler Collection(C,OpenMP)」です。
C compilerを入れてインストール
$ python3 setup.py install using profile: buildconf/default.ini detected include path: ['/usr/include', '/usr/local/include'] /usr/lib/python3.6/site-packages/setuptools/dist.py:333: UserWarning: Normalizing '2.1-dev' to '2.1.dev0' normalized_version, running install using profile: buildconf/default.ini detected include path: ['/usr/include', '/usr/local/include'] Patching "bin_name" to properly install_scripts dir detected CPU cores: 1 configured CFLAGS: -O2 -I. -Wall -Werror -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -DUWSGI_HAS_IFADDRS -DUWSGI_LOCK_USE_WINDOWS_MUTEX -DUWSGI_EVENT_USE_POLL -DUWSGI_EVENT_TIMER_USE_NONE -DUWSGI_EVENT_FILEMONITOR_USE_NONE -DUWSGI_UUID -DUWSGI_VERSION="\"2.1-dev\"" -DUWSGI_VERSION_BASE="2" -DUWSGI_VERSION_MAJOR="1" -DUWSGI_VERSION_MINOR="0" -DUWSGI_VERSION_REVISION="0" -DUWSGI_VERSION_CUSTOM="\"dev\"" -DUWSGI_YAML -DUWSGI_PLUGIN_DIR="\".\"" -DUWSGI_DECLARE_EMBEDDED_PLUGINS="UDEP(python);UDEP(gevent);UDEP(ping);UDEP(cache);UDEP(nagios);UDEP(rrdtool);UDEP(carbon);UDEP(rpc);UDEP(corerouter);UDEP(fastrouter);UDEP(http);UDEP(signal);UDEP(syslog);UDEP(rsyslog);UDEP(logsocket);UDEP(router_uwsgi);UDEP(router_redirect);UDEP(router_basicauth);UDEP(zergpool);UDEP(redislog);UDEP(mongodblog);UDEP(router_rewrite);UDEP(router_http);UDEP(logfile);UDEP(router_cache);UDEP(rawrouter);UDEP(router_static);UDEP(sslrouter);UDEP(spooler);UDEP(cheaper_busyness);UDEP(symcall);UDEP(transformation_tofile);UDEP(transformation_gzip);UDEP(transformation_chunked);UDEP(transformation_offload);UDEP(router_memcached);UDEP(router_redis);UDEP(router_hash);UDEP(router_expires);UDEP(router_metrics);UDEP(transformation_template);UDEP(stats_pusher_socket);UDEP(router_fcgi);" -DUWSGI_LOAD_EMBEDDED_PLUGINS="ULEP(python);ULEP(gevent);ULEP(ping);ULEP(cache);ULEP(nagios);ULEP(rrdtool);ULEP(carbon);ULEP(rpc);ULEP(corerouter);ULEP(fastrouter);ULEP(http);ULEP(signal);ULEP(syslog);ULEP(rsyslog);ULEP(logsocket);ULEP(router_uwsgi);ULEP(router_redirect);ULEP(router_basicauth);ULEP(zergpool);ULEP(redislog);ULEP(mongodblog);ULEP(router_rewrite);ULEP(router_http);ULEP(logfile);ULEP(router_cache);ULEP(rawrouter);ULEP(router_static);ULEP(sslrouter);ULEP(spooler);ULEP(cheaper_busyness);ULEP(symcall);ULEP(transformation_tofile);ULEP(transformation_gzip);ULEP(transformation_chunked);ULEP(transformation_offload);ULEP(router_memcached);ULEP(router_redis);ULEP(router_hash);ULEP(router_expires);ULEP(router_metrics);ULEP(transformation_template);ULEP(stats_pusher_socket);ULEP(router_fcgi);" *** uWSGI compiling server core *** [gcc] core/utils.o [gcc] core/protocol.o [gcc] core/socket.o [gcc] core/logging.o [gcc] core/master.o [gcc] core/master_utils.o [gcc] core/emperor.o [gcc] core/notify.o [gcc] core/mule.o [gcc] core/subscription.o [gcc] core/stats.o [gcc] core/sendfile.o [gcc] core/async.o [gcc] core/master_checks.o [gcc] core/fifo.o [gcc] core/offload.o [gcc] core/io.o [gcc] core/static.o [gcc] core/websockets.o [gcc] core/spooler.o [gcc] core/snmp.o [gcc] core/exceptions.o [gcc] core/config.o [gcc] core/setup_utils.o [gcc] core/clock.o [gcc] core/init.o [gcc] core/buffer.o [gcc] core/reader.o [gcc] core/writer.o [gcc] core/alarm.o [gcc] core/cron.o [gcc] core/hooks.o [gcc] core/plugins.o [gcc] core/lock.o [gcc] core/cache.o [gcc] core/daemons.o [gcc] core/errors.o [gcc] core/hash.o [gcc] core/master_events.o [gcc] core/chunked.o [gcc] core/queue.o [gcc] core/event.o [gcc] core/signal.o [gcc] core/strings.o [gcc] core/progress.o [gcc] core/timebomb.o [gcc] core/ini.o [gcc] core/fsmon.o [gcc] core/mount.o [gcc] core/metrics.o [gcc] core/plugins_builder.o [gcc] core/sharedarea.o [gcc] core/fork_server.o [gcc] core/webdav.o [gcc] core/zeus.o [gcc] core/rpc.o [gcc] core/gateway.o [gcc] core/loop.o [gcc] core/cookie.o [gcc] core/querystring.o [gcc] core/rb_timers.o [gcc] core/transformations.o [gcc] core/uwsgi.o [gcc] proto/base.o [gcc] proto/uwsgi.o [gcc] proto/http.o [gcc] proto/fastcgi.o [gcc] proto/scgi.o [gcc] proto/puwsgi.o [gcc] core/yaml.o [gcc] core/dot_h.o [gcc] core/config_py.o *** uWSGI compiling embedded plugins *** [gcc] plugins/python/python_plugin.o In file included from plugins/python/python_plugin.c:1:0: plugins/python/uwsgi_python.h:2:20: 致命的エラー: Python.h: No such file or directory コンパイルを停止しました。
Python.hがないと怒られる。
→apt-cyg install python3-devel
でpython3-develをインストールしましょう。
python_pluginがないと怒られる。 python3-develが入っていないのが原因。 インストールしよう。
python3-develを入れてインストール
$ python3 setup.py install using profile: buildconf/default.ini detected include path: ['/usr/include', '/usr/local/include'] /usr/lib/python3.6/site-packages/setuptools/dist.py:333: UserWarning: Normalizing '2.1-dev' to '2.1.dev0' normalized_version, running install using profile: buildconf/default.ini detected include path: ['/usr/include', '/usr/local/include'] Patching "bin_name" to properly install_scripts dir detected CPU cores: 1 configured CFLAGS: -O2 -I. -Wall -Werror -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -DUWSGI_HAS_IFADDRS -DUWSGI_LOCK_USE_WINDOWS_MUTEX -DUWSGI_EVENT_USE_POLL -DUWSGI_EVENT_TIMER_USE_NONE -DUWSGI_EVENT_FILEMONITOR_USE_NONE -DUWSGI_UUID -DUWSGI_VERSION="\"2.1-dev\"" -DUWSGI_VERSION_BASE="2" -DUWSGI_VERSION_MAJOR="1" -DUWSGI_VERSION_MINOR="0" -DUWSGI_VERSION_REVISION="0" -DUWSGI_VERSION_CUSTOM="\"dev\"" -DUWSGI_YAML -DUWSGI_PLUGIN_DIR="\".\"" -DUWSGI_DECLARE_EMBEDDED_PLUGINS="UDEP(python);UDEP(gevent);UDEP(ping);UDEP(cache);UDEP(nagios);UDEP(rrdtool);UDEP(carbon);UDEP(rpc);UDEP(corerouter);UDEP(fastrouter);UDEP(http);UDEP(signal);UDEP(syslog);UDEP(rsyslog);UDEP(logsocket);UDEP(router_uwsgi);UDEP(router_redirect);UDEP(router_basicauth);UDEP(zergpool);UDEP(redislog);UDEP(mongodblog);UDEP(router_rewrite);UDEP(router_http);UDEP(logfile);UDEP(router_cache);UDEP(rawrouter);UDEP(router_static);UDEP(sslrouter);UDEP(spooler);UDEP(cheaper_busyness);UDEP(symcall);UDEP(transformation_tofile);UDEP(transformation_gzip);UDEP(transformation_chunked);UDEP(transformation_offload);UDEP(router_memcached);UDEP(router_redis);UDEP(router_hash);UDEP(router_expires);UDEP(router_metrics);UDEP(transformation_template);UDEP(stats_pusher_socket);UDEP(router_fcgi);" -DUWSGI_LOAD_EMBEDDED_PLUGINS="ULEP(python);ULEP(gevent);ULEP(ping);ULEP(cache);ULEP(nagios);ULEP(rrdtool);ULEP(carbon);ULEP(rpc);ULEP(corerouter);ULEP(fastrouter);ULEP(http);ULEP(signal);ULEP(syslog);ULEP(rsyslog);ULEP(logsocket);ULEP(router_uwsgi);ULEP(router_redirect);ULEP(router_basicauth);ULEP(zergpool);ULEP(redislog);ULEP(mongodblog);ULEP(router_rewrite);ULEP(router_http);ULEP(logfile);ULEP(router_cache);ULEP(rawrouter);ULEP(router_static);ULEP(sslrouter);ULEP(spooler);ULEP(cheaper_busyness);ULEP(symcall);ULEP(transformation_tofile);ULEP(transformation_gzip);ULEP(transformation_chunked);ULEP(transformation_offload);ULEP(router_memcached);ULEP(router_redis);ULEP(router_hash);ULEP(router_expires);ULEP(router_metrics);ULEP(transformation_template);ULEP(stats_pusher_socket);ULEP(router_fcgi);" *** uWSGI compiling server core *** core/utils.o is up to date core/protocol.o is up to date core/socket.o is up to date core/logging.o is up to date core/master.o is up to date core/master_utils.o is up to date core/emperor.o is up to date core/notify.o is up to date core/mule.o is up to date core/subscription.o is up to date core/stats.o is up to date core/sendfile.o is up to date core/async.o is up to date core/master_checks.o is up to date core/fifo.o is up to date core/offload.o is up to date core/io.o is up to date core/static.o is up to date core/websockets.o is up to date core/spooler.o is up to date core/snmp.o is up to date core/exceptions.o is up to date core/config.o is up to date core/setup_utils.o is up to date core/clock.o is up to date core/init.o is up to date core/buffer.o is up to date core/reader.o is up to date core/writer.o is up to date core/alarm.o is up to date core/cron.o is up to date core/hooks.o is up to date core/plugins.o is up to date core/lock.o is up to date core/cache.o is up to date core/daemons.o is up to date core/errors.o is up to date core/hash.o is up to date core/master_events.o is up to date core/chunked.o is up to date core/queue.o is up to date core/event.o is up to date core/signal.o is up to date core/strings.o is up to date core/progress.o is up to date core/timebomb.o is up to date core/ini.o is up to date core/fsmon.o is up to date core/mount.o is up to date core/metrics.o is up to date core/plugins_builder.o is up to date core/sharedarea.o is up to date core/fork_server.o is up to date core/webdav.o is up to date core/zeus.o is up to date core/rpc.o is up to date core/gateway.o is up to date core/loop.o is up to date core/cookie.o is up to date core/querystring.o is up to date core/rb_timers.o is up to date core/transformations.o is up to date core/uwsgi.o is up to date proto/base.o is up to date proto/uwsgi.o is up to date proto/http.o is up to date proto/fastcgi.o is up to date proto/scgi.o is up to date proto/puwsgi.o is up to date core/yaml.o is up to date [gcc] core/dot_h.o [gcc] core/config_py.o *** uWSGI compiling embedded plugins *** [gcc] plugins/python/python_plugin.o [gcc] plugins/python/pyutils.o [gcc] plugins/python/pyloader.o [gcc] plugins/python/wsgi_handlers.o [gcc] plugins/python/wsgi_headers.o [gcc] plugins/python/wsgi_subhandler.o [gcc] plugins/python/web3_subhandler.o [gcc] plugins/python/pump_subhandler.o [gcc] plugins/python/gil.o [gcc] plugins/python/uwsgi_pymodule.o [gcc] plugins/python/profiler.o [gcc] plugins/python/symimporter.o [gcc] plugins/python/tracebacker.o [gcc] plugins/python/raw.o [gcc] plugins/gevent/gevent.o [gcc] plugins/gevent/hooks.o [gcc] plugins/ping/ping_plugin.o [gcc] plugins/cache/cache.o [gcc] plugins/nagios/nagios.o [gcc] plugins/rrdtool/rrdtool.o [gcc] plugins/carbon/carbon.o [gcc] plugins/rpc/rpc_plugin.o [gcc] plugins/corerouter/cr_common.o [gcc] plugins/corerouter/cr_map.o [gcc] plugins/corerouter/corerouter.o [gcc] plugins/fastrouter/fastrouter.o [gcc] plugins/http/http.o [gcc] plugins/http/keepalive.o [gcc] plugins/http/https.o [gcc] plugins/http/spdy3.o [gcc] plugins/signal/signal_plugin.o [gcc] plugins/syslog/syslog_plugin.o [gcc] plugins/rsyslog/rsyslog_plugin.o [gcc] plugins/logsocket/logsocket_plugin.o [gcc] plugins/router_uwsgi/router_uwsgi.o [gcc] plugins/router_redirect/router_redirect.o [gcc] plugins/router_basicauth/router_basicauth.o [gcc] plugins/zergpool/zergpool.o [gcc] plugins/redislog/redislog_plugin.o [gcc] plugins/mongodblog/mongodblog_plugin.o [gcc] plugins/router_rewrite/router_rewrite.o [gcc] plugins/router_http/router_http.o [gcc] plugins/logfile/logfile.o [gcc] plugins/router_cache/router_cache.o [gcc] plugins/rawrouter/rawrouter.o [gcc] plugins/router_static/router_static.o [gcc] plugins/sslrouter/sslrouter.o [gcc] plugins/spooler/spooler_plugin.o [gcc] plugins/cheaper_busyness/cheaper_busyness.o [gcc] plugins/symcall/symcall_plugin.o [gcc] plugins/transformation_tofile/tofile.o [gcc] plugins/transformation_gzip/gzip.o [gcc] plugins/transformation_chunked/chunked.o [gcc] plugins/transformation_offload/offload.o [gcc] plugins/router_memcached/router_memcached.o [gcc] plugins/router_redis/router_redis.o [gcc] plugins/router_hash/router_hash.o [gcc] plugins/router_expires/expires.o [gcc] plugins/router_metrics/plugin.o [gcc] plugins/transformation_template/tt.o [gcc] plugins/stats_pusher_socket/plugin.o [gcc] plugins/router_fcgi/router_fcgi.o *** uWSGI linking *** gcc -o /usr/bin/uwsgi -L/usr/lib -Wl,-rpath,/usr/lib core/utils.o core/protocol.o core/socket.o core/logging.o core/master.o core/master_utils.o core/emperor.o core/notify.o core/mule.o core/subscription.o core/stats.o core/sendfile.o core/async.o core/master_checks.o core/fifo.o core/offload.o core/io.o core/static.o core/websockets.o core/spooler.o core/snmp.o core/exceptions.o core/config.o core/setup_utils.o core/clock.o core/init.o core/buffer.o core/reader.o core/writer.o core/alarm.o core/cron.o core/hooks.o core/plugins.o core/lock.o core/cache.o core/daemons.o core/errors.o core/hash.o core/master_events.o core/chunked.o core/queue.o core/event.o core/signal.o core/strings.o core/progress.o core/timebomb.o core/ini.o core/fsmon.o core/mount.o core/metrics.o core/plugins_builder.o core/sharedarea.o core/fork_server.o core/webdav.o core/zeus.o core/rpc.o core/gateway.o core/loop.o core/cookie.o core/querystring.o core/rb_timers.o core/transformations.o core/uwsgi.o proto/base.o proto/uwsgi.o proto/http.o proto/fastcgi.o proto/scgi.o proto/puwsgi.o core/yaml.o core/dot_h.o core/config_py.o plugins/python/python_plugin.o plugins/python/pyutils.o plugins/python/pyloader.o plugins/python/wsgi_handlers.o plugins/python/wsgi_headers.o plugins/python/wsgi_subhandler.o plugins/python/web3_subhandler.o plugins/python/pump_subhandler.o plugins/python/gil.o plugins/python/uwsgi_pymodule.o plugins/python/profiler.o plugins/python/symimporter.o plugins/python/tracebacker.o plugins/python/raw.o plugins/gevent/gevent.o plugins/gevent/hooks.o plugins/ping/ping_plugin.o plugins/cache/cache.o plugins/nagios/nagios.o plugins/rrdtool/rrdtool.o plugins/carbon/carbon.o plugins/rpc/rpc_plugin.o plugins/corerouter/cr_common.o plugins/corerouter/cr_map.o plugins/corerouter/corerouter.o plugins/fastrouter/fastrouter.o plugins/http/http.o plugins/http/keepalive.o plugins/http/https.o plugins/http/spdy3.o plugins/signal/signal_plugin.o plugins/syslog/syslog_plugin.o plugins/rsyslog/rsyslog_plugin.o plugins/logsocket/logsocket_plugin.o plugins/router_uwsgi/router_uwsgi.o plugins/router_redirect/router_redirect.o plugins/router_basicauth/router_basicauth.o plugins/zergpool/zergpool.o plugins/redislog/redislog_plugin.o plugins/mongodblog/mongodblog_plugin.o plugins/router_rewrite/router_rewrite.o plugins/router_http/router_http.o plugins/logfile/logfile.o plugins/router_cache/router_cache.o plugins/rawrouter/rawrouter.o plugins/router_static/router_static.o plugins/sslrouter/sslrouter.o plugins/spooler/spooler_plugin.o plugins/cheaper_busyness/cheaper_busyness.o plugins/symcall/symcall_plugin.o plugins/transformation_tofile/tofile.o plugins/transformation_gzip/gzip.o plugins/transformation_chunked/chunked.o plugins/transformation_offload/offload.o plugins/router_memcached/router_memcached.o plugins/router_redis/router_redis.o plugins/router_hash/router_hash.o plugins/router_expires/expires.o plugins/router_metrics/plugin.o plugins/transformation_template/tt.o plugins/stats_pusher_socket/plugin.o plugins/router_fcgi/router_fcgi.o -lpthread -lm -luuid -lintl -ldl -lpython3.6m -lcrypt /usr/lib/gcc/x86_64-pc-cygwin/5.3.0/../../../../x86_64-pc-cygwin/bin/ld: -lcrypt が見つかりません collect2: エラー: ld はステータス 1 で終了しました *** error linking uWSGI ***
→lcryptがないと怒られる。 cywinのインストーラ「setup-x86_64.exe」からlibcrypt-develのパッケージを導入しましょう。 パッケージ名は「ibcrypt-deve: Encryption/Decryption utility and library」です。
導入方法
pythonがインストールされていない方はこちらを参考にインストールしましょう。
始めに、cywinをダウンロード。
インストールする際に、下記のパッケージをインストールする。
・python3-pip(python2の方は2をインストール) ・wget: Utility ・ibcrypt-deve: Encryption/Decryption utility and library ・gcc-core: GNU Compiler Collection(C,OpenMP)
インストールが済んだら、Cygwin64 Terminalを起動。
apt-cygを使えるようにします。
wget https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg chmod 755 apt-cyg mv apt-cyg /usr/local/bin/
uswgiを入れるために必要なものをapt-cygで入れます。
apt-cyg install python3-devel
gitからuswgiをダウンロードします。
ダウンロードしたフォルダをcywinのインストールフォルダに入れて
「setup.py」のある場所でpython3 setup.py install
以上です。