Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing Sanic on Windows for PyCharm? #1192

Closed
SuperSajuuk opened this issue Apr 14, 2018 · 11 comments
Closed

Installing Sanic on Windows for PyCharm? #1192

SuperSajuuk opened this issue Apr 14, 2018 · 11 comments

Comments

@SuperSajuuk
Copy link

Hi there. I'm trying to install Sanic on my Python 3.6.1 installation for usage in PyCharm. But it seems that the module won't install via PyCharm natively because of uvloop/ujson not being supported on Windows.

I checked the issue tracker and saw this has been fixed, but I still keep running into the issue no matter what and it's preventing me using Sanic to develop a dashboard for my Discord Moderator Bot (it uses Flask, but that's inherently slow/not async).

Hopefully you can give some tips on how to install Sanic for PyCharm :D

@georgejdanforth
Copy link

Hi @SuperSajuuk, PyCharm will run whichever python interpreter you specify for your project, defaulting to whichever version is in your PATH. To install Sanic (and for numerous other reasons), I would recommend that you create a python 3.6 virtualenv for your project and install Sanic in it using pip with the flags specified in this project's README to disable uvloop and ujson. After you've installed sanic and all your other dependencies in the virtualenv, you should be able to select the virtualenv as your project interpreter in your PyCharm settings under Project>Project Interpreter. Hope this helps!

P.S. I'm surprised that you haven't found Flask to be performant enough for your use case. Out of curiosity, could you elaborate a bit on where you're experiencing bottlenecks or performance shortcomings?

@SuperSajuuk
Copy link
Author

SuperSajuuk commented Apr 14, 2018

Hi there @georgejdanforth thanks for responding!

I'm using a Py 3.6.1 virtualenv, I'll have a look at the readme more closely to see what i missed.

As for flask, I suspect it is due to the way I'm using it, but whenever one user access the Flask component, nobody else can use it. This is problematic because I'm expecting multiple users to be using the dashboard all at once, or at least multiple requests going to the dashboard from several sources.

I'm hoping that using Sanic will make it more easier for me to deploy the dashboard. The documentation appears to suggest that I can use app.run() and spin up a proper production server with no issues like Flask seems to have (it only spawns a development server that serves one request at a time, and thus becomes useless if multiple people are going to it).

The benefits of Sanic are that it's really just an Async (and better supported) version of Flask and I want to replace the Apache web server with just Sanic serving all aspects of the site this will be used on.

EDIT: I tried again, but it still refuses to install. You can see in this image it says that sanic is installed in pycharm, but I suspect PyCharm is just returning that because it has no "failure" response for the fact uvloop/ujson are failing the installer: https://cdn.discordapp.com/attachments/315957062360236033/434748656554344478/unknown.png

@georgejdanforth
Copy link

Hi @SuperSajuuk, I can't really speak to why the installation via PyCharm is not working as I've never really used PyCharm as a dependency management tool. Sorry if I wasn't being clear, but I would recommend that you install Sanic using:

SANIC_NO_UVLOOP=true SANIC_NO_UJSON=true pip install sanic

via the command line as specified in the docs, after you've activated your virtualenv in a shell session. Docs on how to activate your virtualenv on windows can be found here if you're not already familiar.

As a final note, your performance woes with Flask are almost certainly due to your configuration and attempting to use the development server to serve production traffic. I can't say for sure without knowing all the details, but my guess would be that this problem would be solved by deploying behind a proper WSGI server such as Gunicorn.

@SuperSajuuk
Copy link
Author

SuperSajuuk commented Apr 14, 2018

Hi there. I've looked through the documentation and managed to get Powershell to activate the virtual environment, but that command you are suggesting will not run, as it returns this error:

SANIC_NO_UVLOOP=true : The term 'SANIC_NO_UVLOOP=true' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At line:1 char:1
+ SANIC_NO_UVLOOP=true SANIC_NO_UJSON=true pip install sanic
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (SANIC_NO_UVLOOP=true:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Even if I go and use the set function and install, it will continue to try installing uvloop and ujson anyway and just ignores what I told it to. Any help would be appreciated, since I'm pretty unsure as to what I should do next ^_^ (This is a Windows 10 Pro pc, on the Fall CU update, for the record).

PS: I tried gunicorn before for Flask but it didnt' seem to work, and because the web server uses Apache, Flask's documentation suggested deploying with mod_wsgi (which was a nightmare to install in the first place, and by that point, getting the file created and only receiving errors made me stop wanting to care for deploying it properly, easier if I just rewrite it all to be async using a solution that doesn't require deployment with WSGI web server modules lol)

@SuperSajuuk
Copy link
Author

SuperSajuuk commented Apr 14, 2018

A few hours later, I eventually found one solution (install from source seems to work per another thread), but I get stuck on the httptools, which fails for missing Visual C++ 14.0. I installed this, but it just complained that it wasn't there anyway, despite blatantly being installed. I'll keep trying to make this work, I guess I'm on the right track, but I really hope Sanic can provide a simple installer or script that installs Sanic into Windows directly without all this hassle.

EDIT: Just re-ran through the installation and it's working properly now, I just needed to update setuptools which allowed httptools to install and allow for Sanic's install.

@dujinyu
Copy link

dujinyu commented Apr 13, 2019

@SuperSajuuk the same problem happened to me, i don't want to use linux since i need to develop frontend code. To my extreme curiosity, have you solved the issue? if you have, please tell me how to do it and thanks.

@SuperSajuuk
Copy link
Author

@dujinyu Hi, I never resolved the problem and just gave up trying to use Sanic as a result. You're better off just sticking with Flask and using a web server proxy (like Apache or Nginx) to handle multiple requests.

@harshanarayana
Copy link
Contributor

@SuperSajuuk @dujinyu

$ export SANIC_NO_UVLOOP=true
$ export SANIC_NO_UJSON=true
$ pip3 install --no-binary :all: sanic

This should install sanic without uvloop/ujson. Can you try this out once ?

@jangjichang
Copy link

jangjichang commented May 9, 2019

@SuperSajuuk @dujinyu

$ export SANIC_NO_UVLOOP=true
$ export SANIC_NO_UJSON=true
$ pip3 install --no-binary :all: sanic

This should install sanic without uvloop/ujson. Can you try this out once ?

@harshanarayana
First of all, thank you for this answer.

But I tried to install it as you explained, but it failed.

The error message is as follows.

Command "c: \ users \ jcjang \ appdata \ local \ programs \ python \ python37-32 \ python.exe -u -c" import setuptools, tokenize; __ file __ = 'C: \ Users \ jcjang \ AppData \ Replace ('\ r \ n'); f = getattr (tokenize, 'open', open) install -record C: \ Users \ jcjang \ AppData \ Local \ Temp \ pip-record (code, file, 'exec' -cdd1cntz \ install-record.txt --single-version-externally-managed --compile "failed with error code 1 in C: \ Users \ jcjang \ AppData \ Local \ Temp \ pip-install-53zn3k2e \ httptools \

How can I fix this error when I get this error message?

@wissemnano
Copy link

the problem is relied to httptools, so first try to install it. in my case i tried : pip3 install httptools
the i have a problem : "error: Microsoft Visual C++ 14.0 is required"
so download it and you can install httptools and sanic

@mojimi
Copy link

mojimi commented Jul 17, 2019

Yup the issue is with Visual C, which is annoying so I just decided it was better to install ubuntu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants