installing python modules that require gcc on shar

2019-06-28 08:54发布

问题:

I'm using Hostgator shared as a production environment and I had a problem installing some python modules, after using:

pip install MySQL-python

pip install pillow

results in:

unable to execute gcc: Permission denied error: command 'gcc' failed with exit status 1

server limitations

  • no root access
  • sudo doesnt work (sudo: effective uid is not 0, is sudo installed setuid root?)
  • no gcc

questions

  1. is there an alternative package for pillow. I want this to use django ImageField. (just like pymysql is an equally capable alternative for mysql-python)

  2. i have modules like mysql-python and pil installed in root, i.e. pip freeze without any virtualenv lists these modules. but i cannot install my other required modules in this root environment and in my virtualenv i cannot install mysql-python and pil. can something be done? can we import/use packages installed in root somehow in a virtualenv?

  3. is hostgator shared only good for PHP and not for python/django webapps. we have limited traffic so we are using hostgator shared. should we avoid hostgator or shared hosting? aren't they good enough for python/django (i had no problems in hosting static/PHP sites ever). are they too many problems and limitations or performance issues (FCGI)? if yes, what are the alternatives?

回答1:

You can try building wheels on some similar host where gcc is available, copy them to your server and install. But I do not know how much similar hosts should be.

  1. on "similar" host with gcc:

    mkdir /tmp/wheels mkdir /tmp/pip-cache pip wheel --download-cache /tmp/pip-cache -w /tmp/wheels -r requirements.pip

  2. copy wheels to your hosting (I assume that you copy to /tmp/wheels)

  3. install from wheels ignoring index and using wheels dir:

    pip install --download-cache /tmp/pip-cache --find-links=/tmp/wheels --no-index -r requirements-dev.pip

P.S. Maybe you should also copy download-cache to your hosting. I do not remember if this is needed. If this is not needed then you can skip option --download-cache /tmp/pip-cache



回答2:

  1. you can try to use PIL instead of Pillow (try it but I'm guessing you will probably run into the same compile problem)

  2. when you setup your virtualenv, you can pass it a --system-site-packages flag. See here

  3. there are definitely a lot of alternative services out there- heroku, digital ocean, webfaction etc. Quick plug for PythonAnywhere (I work here)-- we are a PAAS specifically geared towards python frameworks such as Django and come with PIL, mysql-python, and many other python packages preinstalled.



回答3:

You need root access to install the necessary packages to run your python application.

PAAS like Heroku are another option but the free package at Heroku is only good for developing your application and it is not intended for hosting it once you get traffic and users.

I strongly suggest you get a VPS at DigitalOcean.com. For 5$ per month you will get root access and more power. You will also control your full stack. I use Nginx+Gunicorn to host about 10 Django projects on DigitalOcean right now.