Pythonanywhere Pillow install not working - django

I have loaded my django app onto Pythonanywhere and when running through my functions, I learned I cannot upload images through the Admin since I moved into production. I am getting this error:
Neither Pillow nor PIL could be imported: No module named 'Image'
Which from prior experience means Pillow isn't installed. So I opened a bash console and ran
pip3 install --user Pillow
and it said it installed correctly, and I did reload my app but it still doesn't work
(same error). What went wrong?
Thanks in advance, Conner
Also, I did see this question on their forums: https://www.pythonanywhere.com/forums/topic/1247/
UPDATE:
Tried uninstalling Pillow and re-installing, then restarting web server. Still not working.

Related

Conda dependent packages(rdkit) will not install properly for use in web servers(importError:DLL load failed). Is there an alternative install method?

UPDATE 1: PIL and RDKIT produced import errors because the .dll files were not placed in /venv//Lib/site-packages
I removed both packages from environment and commented out their code from my project.
Next I updated the base base environment:
conda update conda #from base env
Then I upgraded pip and setuptools and reinstalled pillow:
python -m pip install pip --upgrade
pip install setuptools --upgrade
pip install pillow
I can now add my PIL content back to the project and it will work just fine on the production server, without rdkit installed.
RDKIT is only available as a conda install, it still does not install properly and breaks PIL in the process(rdkit depends on pillow). I have reinstalled from both the rdkit and conda-forge channels. Neither work.
What is the proper way to fix this problem? I feel like the hack around of moving .dll files is risky and not a good solution.
UPDATE 0: RDKIT will not load into any server
I created a basic django project similar to what you would find in the tutorial with no static files. The project successfully published to the Apache server describe below in the original post and in Windows 10 IIS. Next modified the models.py to import rdkit and both servers gave the import error and the site would not display.
Original post:
RDKIT is the only package not loading into our production server.
We successfully set up a Wampserver to run Apache and host our Django project . . .but have to comment out all the code associated with rdkit for it to work. This inhibits many required features.
There were no issues using rdkit in Django's test server.
Primary wsgi error:
from .rdBase import rdkitVersion as __version__\r, referer: http://localhost/APP/
ImportError: DLL load failed: The specified module could not be found.\r, referer: http://localhost/APP/
Relevant packages and version details:
Windows 10
Django 2.2
Python 3.7
conda 4.8.2
rdkit 2019.09.3 conda-forge
Wampserver 3.2
Apache 2.4.41
mod-wsgi 4.7.1
postgresql 10
The methods in this blog describe how we setup the production server. With one minor change, we did not alter the httpd_vhosts.conf file and only setup the standard localhost.
The error is reproducible by trying to import rdkit(or one of its methods) into any file needed to host a web application in the described environment.
We found this 2016 thread on the rdkit sourceforge and it sounds like someone else was having a similar problem on a Linux system. This is our first time setting up a server and we have not been successful at translating the recommended fix from linux to windows. There was no follow up to know if the recommendation was attempted let alone successful.
These 2012 slides lend us to believe someone was trying to overcome a similar issue in linux (slide 9)
How would a package need to be altered to allow it to load into a webserver?
Thank you, we greatly appreciate your time and assistance.

Pil or Pillow on Heroku dosen't work

I tried to migrate my django app to heroku, but Pil library can't work on heroku.
My requirements.txt below works fine on other container based platform, but not on heroku.
Django==1.4.6
Pil
django-mptt==0.5.2
...
I've checked some QAs on stackoverflow and added some changes and reinstall Pil, Pillow or these some forks below
-e hg+https://bitbucket.org/etienned/pil-2009-raclette/#egg=PIL
-e git://github.com/errkk/gitpil.git#egg=PIL
Pillow==1.7.8
but doen't work fine with these errors.
'decorder zip not available' 'decoder jpeg not available'.
Do you have any ideas to fix this?
Thanks,

Pillow installation not recognized in Django through Apache

When deploying my project through Apache wsgi, using a virtualenv on Ubuntu Server VM, I get the following on error on /var/log/apache2/error.log:
ImportError: Photologue was unable to import Python Imaging Library. Please confirm it's installed and available on your current Python path.
Setup:
Django==1.6.6
django-photologue==2.3
Pillow==2.5.1
However, I have been able to run the project with the same configuration in Ubuntu Desktop VM (for development). For Ubuntu Server VM I followed the same procedure:
Installed dependent image libraries (libjpeg8-dev, etc) through apt-get
pip install pillow, in virtualenv, it showed --- JPEG support available
Ran this with no problems:
manage.py shell
from PIL import Image
im = Image.open("file.jpg")
im.show()
Used django's server with no problem, it showed the login screen:
manage.py runserver
For sanity's sake, I uninstalled pillow, running manage.py runserver showed the same import error. I reinstalled pillow and the error went away in the django server
Now, the issues arise when I try to access the website on the browser through apache. I go to the servername to get the actual django website and keep getting a 500 Internal Server Error on the browser and the import error on apache log.
The only thing I can think of is that in manage.py shell I can't do "import Image". However, photologue has a try/except import in which it will do "from PIL import Image" in case of an exception with "import Image", which covers that case.
I found the answer, posting it here since it was not entirely obvious.
This is a more subtle case of PIL not being able to link against the directories in apt-get. The answer from the ubuntu forums solves this issue.
sudo ln -s /lib/x86_64-linux-gnu/libz.so.1 /lib/
sudo ln - /usr/lib/x86_64-linux-gnu/libfreetype.so.6 /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so.62 /usr/lib/
However, I was not able to run the django proyect with pillow. I had to use PIL, which is annoying:
pip uninstall pillow
pip install PIL --allow-external PIL --allow-unverified PIL

Heroku not picking up updated django-bouncer package

I had an old version of django-bouncer that required hashcompat, which is now deprecated. Since I was getting errors telling me this, I did pip uninstall django-bouncer, then installed the version upgraded for Django 1.6 (it uses hashlib instead of hashcompat) using pip install https://github.com/shelfworthy/django-bouncer/archive/master.tar.gz (I also re-added it to my requirements.txt file).
Locally, this is working fine. However, when I push to Heroku, I'm still getting the error "No module named hashcompat."
I tried doing a git push heroku master --force, but that didn't resolve the problem. Then I reset the app by doing heroku repo:reset -a <myappname>, followed by did a new git push heroku master. Unfortunately, I'm still getting the error on my Heroku app.
How can I make Heroku get the upgrade of django-bouncer?
What you should do is this:
Firstly, install django-bouncer's latest release locally on your laptop (you can do this by running pip install -U django-bouncer.
Next, figure out what the latest version is on your laptop, by running: pip freeze | grep django-bouncer. You should see something like: django-bouncer==x.x.x.
Lastly, edit your project's requirements.txt file and add django-bouncer=x.x.x, then push this change to Heroku. This will force Heroku to detect what specific version of django-bouncer is required, and install it for you.
Hope that helps!
It's possible you are running afoul of Heroku's package cache; it sees django-bouncer is already installed and doesn't bother to install it again. But, you can't uninstall it either.
I recall there's a bit of a hack to get around this: Heroku will wipe out its package cache if you change the version of Python you are using. So if you are using, say, 2.7.6, edit your runtime.txt to change it to python-3.4.0. If you are already using a 3.x branch, do the opposite. It's not important that your application actually works on the version you're changing it to -- deploy once, and change it back. That should wipe out your package cache entirely, at which point you'll be good to go.

Installing django-avatar onto heroku

I'm trying to install Django-Avatar onto heroku.
I tried django-avatar==2.0a9 in my requirements.txt
but got the error:
"No distributions matching the version for django-avatar==2.0a9"
I then tried django-avatar==github.com/jezdez/django-avatar/archive/master.zip and got the error:
"No such file or directory:
'/app/django-avatar==https:/github.com/jezdez/django-avatar/archive/master.zip"
Any thoughts on how I can get django-avatar installed?
I appreciate the time and expertise.
you cannot directly install some thing on heroku.
create a virtual env and
install django-avatarin local machine,
update the requirements file using pip freeze > requirements.txt
then push the changes.
Refer this document https://devcenter.heroku.com/articles/django