empty __init__.py file with error " ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' " when importing torchvision on M1 - python-imaging-library

I have a functioning PyTorch installation with a conda environment with MPS backend working fine on a M1 mac.
However, after installing torchvision, when I try to import torchvision, I get this error (also shown in screenshot):
ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' (/opt/anaconda3/lib/python3.9/site-packages/PIL/__init__.py)
In the screenshot below, I run python in my terminal and then try to import torchvision and get the error.
I have navigated to and opened the file in question __init__.pyin the PIL folder, and the file itself is empty.
If relevant:
torch version is 1.13.0.dev20220911
Python is 3.9.13
Conda is 22.9.0
I have tried installing and reinstalling with conda and pip multiple times but with the same result when importing torchvision.
I found this stackoverflow question about PILLOW_version, which got me to try to rename the __init__.py file that turned out to be empty, which I did not expect, since that made it impossible to rename the pillow versioning.
Thanks in advance.

Related

Cannot import name 'rank_zero_only' from 'pytorch_lightning.utilities.distributed'

I am using VQGAN+CLIP_(Zooming)_(z+quantize_method_with_addons).ipynb Google Repository and when I click the cell "Loading of libraries and definitions"
It sent an error :
ImportError Traceback (most recent call last)
<ipython-input-6-fe8fafeed45d> in <module>
24 from omegaconf import OmegaConf
25 from PIL import Image
---> 26 from taming.models import cond_transformer, vqgan
27 import torch
28 from torch import nn, optim
1 frames
/content/taming-transformers/main.py in <module>
10 from pytorch_lightning.trainer import Trainer
11 from pytorch_lightning.callbacks import ModelCheckpoint, Callback, LearningRateMonitor
---> 12 from pytorch_lightning.utilities.distributed import rank_zero_only
13
14 from taming.data.utils import custom_collate
ImportError: cannot import name 'rank_zero_only' from 'pytorch_lightning.utilities.distributed' (/usr/local/lib/python3.7/dist-packages/pytorch_lightning/utilities/distributed.py)
I don't know how to solde this problem. I don't know how to manually install Pytorch as it said "NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below."
Thank you in advance if you have the solution.
Inès
I triad !pip install but I may not really know where to put this cell/line of code
pytorch_lightning has recently released a new version which will throw this error (version 1.8.0.post1 released on November 2nd 2022).
https://pypi.org/project/pytorch-lightning/#history
Just install an older version of pytorch_lightning and it will work.
In my system, I ran "pip install pytorch-lightning==1.6.5", higher versions may work as well, you can check them out by clicking on the link provided above and then clicking on release history.
Finally, after long research, I found the solution for it, try to run it, you will face an issue with CLIP module, once you resolve python issue as well, so for that follow the second code.
conda install pytorch-lightning -c conda-forge
Once you clone it, try to follow below command
Step:1 cd CLIP
Step2: python setup.py
after that,
type: cd..
Once you do that, you will be redirected to previous directory named "VQGAN-CLIP"
and finally, run the following command:
python generate.py -p "A painting of an apple in a fruit bowl"
Once it is done, then run your generate python file, It will work fine.
use #vishisht-rao solution to downgrade the package version of pytorch-lightning to 1.7.7; this step by itself did not solve the problem for me.
pip install pytorch-lightning==1.6.5
run pip list|grep lightning to find the installed version of lightning-utilities. Mine was lightning-utilities==0.4.2
Downgrade the package version of lightning-utilities to 0.4.0
pip install lightning-utilities==0.4.0
Downgrading the package versions of both pytorch-lightning and lightning-utilities solved the problem for me.

Python Cannot Find Module Located in Sub-Directory when Importing QAxContainer from PyQt5

Python appears to be unable to locate the module QAxContainer in PyQt5. The package was installed using Conda and is present in a sub-directory of PyQt5 but cannot be located. Additional testing with pip resulted in the same error.
Ubuntu 20.04
Python 3.8.5
conda list
pyqt5 5.15.2 pypi_0 pypi
from PyQt5 import QAxContainer
ImportError: cannot import name 'QAxContainer' from 'PyQt5' (/home/brian/anaconda3/lib/python3.8/site-packages/PyQt5/init.py)
However, qaxcontainer.py is present in /home/brian/anaconda3/lib/python3.8/site-packages/PyQt5/uic/widget-plugins
There should be QAxContainer.pyd and QAxContainer.pyi at /home/brian/anaconda3/lib/python3.8/site-packages/PyQt5/. If you dont have them maybe there's a problem with the package, try reinstalling PyQt5.
According to antonio2924, QAxContainer.pyd and QAxContainer.pyi should be located at /home/brian/anaconda3/lib/python3.8/site-packages/PyQt5/. The .pyd file extension is specific to Windows. Furthermore:
The QAxContainer module is a Windows-only extension for accessing
ActiveX controls and COM objects. See, https://doc.qt.io/qt-5/qaxcontainer-module.html
I am running Ubuntu 20.04, which explains why QAxContainer is not being installed.

ImportError: No module named pytesseract on Jupiter lab and VSCode but not my local

I have tried running a ProcessImage.py file in which I import the package pytesseract in Jupiter Lab and VSCode.
This is the error that pops out :
import pytesseract
ImportError: No module named pytesseract
I already know that pytesseract is installed in my environment because with conda list:
pytesseract 0.3.2 py_0 conda-forge
pytest 5.3.5 py38_0 coda-forge
However, if I run my ProcessImage.py file on my local no error is prompted.
I know the error is related to paths in Jupiter Lab and VsCode but I can't seem to find a solution.
Have you tried to launch your python file using Ctrl+F5 command for run?
I had this same ImportError when trying to launch my python program using the .run extension. It persistently started python 2.7 while my environment was using Python3. I first thought that it was a VS code error but it wasn't.

Import Error on conda even directory exists

Environment info: Anaconda, windows7x64, py3.5
I setup a virtual env named as menpo to run menpoproject. For a long time I was using load_dlib_frontal_face_detector smoothly. After tinkering with a pip-install dlib command accidentally on virtualenv (I mean via Anaconda Prompt menpo) , I couldn't get my code working due to an "ImportError" ImportError: cannot import name' load_dlib_frontal_face_detector'. Code is like below:
import cv2
import menpo.io as mio
import menpodetect
Throws error at line 3.
There is this guy seems to had a similar issue.
https://github.com/menpo/menpodetect/issues/15
I did all the
conda remove dlib -y
pip uninstall dlib
conda install -c conda-forge dlib
stuff but still got the same error. Besides that;
Uninstalled Anaconda completely
Removed all Python folders wherever I found.
Installed Anaconda and setup a new menpo virtual env and still no luck. It seems like this dlib installation I made causing some issues. BTW, conda list produces dlib 18.18 py35_2 menpo and there is no pip line as mentioned in the link given above.
Wrong alarm. Seems that I've named my py file as menpodetect which I shouldn't do. Problem solved.

Python Cryptography Error ImportError: cannot import name certificate_transparency

In cryptography which was included using pip install PyCrpto giving an error after including it in a flask application where we are running it using virtual environment have named it venv and have this dependency correctly installed in venv > lib > python2.7 > site-packages.
Below is the exact error which I am getting here.
from cryptography.x509 import certificate_transparency
ImportError: cannot import name certificate_transparency
But as can be seen in screenshot file cryptography.x509.certificate_transparency.py is there in file structure and even on trying python -c "from cryptography.x509 import certificate_transparency" doesn't show any warnings but here it shows error which is also marked in red.
What can be possibly wrong here ?
I came across this problem when I was building an updated Python Crypto module for shipping with Solaris (see https://www.jmcpdotcom.com/blog/2018-02-21-im-embarrassed-to-admit-it/).
The root cause in your case appears to be that you haven't installed it in the right place. While you claim above that it's "correctly installed" in venv > lib > python2.7 > site-packages the screenshot shows that it is in fact in venv/lib/cryptography. If you move the cryptography dir down a level I would expect that your import would work.