Forums

cannot import name '_imaging' from 'PIL' (/home/.../lib/python3.8/site-packages/PIL/__init__.py)

Dear pythonanywhere support team,

When I entry the data with image on django admin page, it gave this error message ImportError at /admin/newsapp/post/add/ cannot import name '_imaging' from 'PIL' (/home/... /venv_file/lib/python3.8/site-packages/PIL/init.py)

It might be the problem of PIL or Pillow, but still confusing.

Thank you in advance

That looks like you may have a broken PIL installation. Try deleting your virtualenv and rebuilding it.

Thank you. I ll try it.

Dear pythonanywhere suupport team,

Yes, it actually is. My intended Python version is 3.8.5, but when I checked it in the pythonanywhere's virual env the version is 2.7.12.

So I deleted and rebuilt the virtaulenv. However, the Python version 3.8.5 doesn't exist, so I typed Python version 3.8 which I know will be conflicting with my project codes.

And after rebuilding virtaulenv and reloading the web, it came out something went wrong on my site. Is there any more fix to this python version rather than rebuilding my project with python version 3.8 and commit it to GitHub and rehost it to pythonanywhere again?

Thank you in advance

I'm confused, first you say you want to use Python 3.8, then you say that it will conflict with your code. Which is it?

You need to specify the version of Python that you want to use in a virtualenv (3.6, 3.7, 3.8 etc): https://help.pythonanywhere.com/pages/RebuildingVirtualenvs/

Also, it sounds like you're building your virtualenv and then commiting it to git to use on PythonAnywhere. That will not work. Virtualenvs cannot, in general, be copied from machine to machine. Create the virtualenv on PythonAnywhere if you want to use it on PythonAnywhere.

Oh I see. Thank you. I did build virtualenv from my mac and commit to git and on to Pythonanywhere. And later I followed your guides to delete and rebuild it which I did on pythonanywhere. So I have messed it up.

The version of Python within virtualenv from my machine is 3.8.5; but in pythonanywhere's bash console in which I tried to rebuild the virtualenv, there is no Python 3.8.5, there is only 3.8 or 3.8.0.

So what should I do? rebuild the whole project; then, commit it to git and onto pythonanywhere again?

I'd recommend removing the virtualenv from your git repository entirely, as it's not something that really belongs there -- it's specific to your own machine. Then you can just git pull the repository onto PythonAnywhere.

For the virtualenv on PythonAnywhere, I'd recommend using the "mkvirtualenv" command to create it -- that will put it in a place separate to the directory that contains your code (specifically in the ".virtualenvs" directory inside your home directory), and then you can pip install the modules you need into it.

If you've written your code for Python 3.8.5, it should work without problems with 3.8.0, so you don't need to worry about that.

Thank you giles for your help. I ll try it.

Dear giles:

Because there are more than one virtualenv in the project folder and I m not sure what to do. I deleted all the directories and files in my pythonanywhere account to start again. I created another repo in the GitHub within which there is no virtualenv in the project. I tried to clone it to pythonanywhere with the command git clone https://github.com/ReksmeyOk/khmerkitAnywhere.git

But after I gave username and personal access token, it could not find the repo. It showed

remote: Repository not found. fatal: repository 'https://github.com/ReksmeyOk/khmerkitAnywhere.git/' not found

I deleted the GitHub login password from my Mac Access Key Chain. I tried to regenerate SSH keys and pasted it to GitHub account. But the console still couldn't find my repo.

What should I do? Could you help please.

are you sure that's the right url to git clone from?

yes sure. the old repo is https://github.com/ReksmeyOk/khmerkitDjango.git/ and the new one without virualenv is https://github.com/ReksmeyOk/khmerkitAnywhere.git/. It tried to clone both of them several times each. and both are valid in my GitHub account. But it didn't work.

07:55 ~ $ git clone https://github.com/ReksmeyOk/khmerkitAnywhere.git Cloning into 'khmerkitAnywhere'... Username for 'https://github.com': ReksmeyOk Password for 'https://ReksmeyOk@github.com': remote: Repository not found. fatal: repository 'https://github.com/ReksmeyOk/khmerkitAnywhere.git/' not found 07:56 ~ $

So I might go back to learn Git commands more.

Oh my God. I fearfully had turned my repo to private. Now change it to be public and so git clone is working.

Hello giles,

I made it. How exciting! My page loaded back and the admin page can upload image and video.

Thank you again for your recommending and for pythonanywhere 's support team for your great resourceful helps which are hardly found within other famous hosting sites. I would recommend people and my friends to host their python and django projects on pythonanywhere.

Hi @ReksmeyOk, glad you got that working! And thanks for all kind words :)