Python2 Packages not recoganised by Python3 - python

I have installed both python2.7 and python3.5 in my Ubuntu. I mostly use Python3.5 only. I was trying to import some libraries and use them in my program
try:
import Image
except ImportError:
from PIL import Image
import pytesseract
n = input()
print(n)
print(pytesseract.image_to_string(Image.open(str(n))))
When I run this code with Python3 filename.py I am getting a package not found error.Then I tried running it with Python filename.py then I am getting the desired output. Then I added the input() line and tried to run it and it started throwing an error because input() was introduced only in Python3
Then I tried to locate the pacakages that I have installed namely "PIL(python3-imaging), tesseract, pytesseract" and their location goes something like usr/local/lib/Python/. Since I am new to this packages and stuff my guess is that the erroris caused because they are installed in Python2.7 related files and not in Python3 files.
How can I solve this problem? Any help would be appreciated.

try this line to install the package you want to use
python3 -m pip install PIL tesseract pytesseract

Related

darkflow calls wrong version of python

When trying to use yolo for python I followed https://github.com/thtrieu/darkflow I got flow installed using
pip3 install .
but then, when running
flow --h
I get
File "/home/computername/.local/lib/python3.5/site-packages/darkflow/net/help.py", line 9, in <module>
import cv2
ImportError: No module named 'cv2'
When I call python I get into python 3.6 and if the import cv2 it does not give any problem, i.e., cv2 is imported.
When calling
which python
I get
/home/computername/anaconda3/bin/python
So flow does call the wrong version python. I thought, maybe I should delete the python 3.5 version on my computer, but looking for how to do that I only find warnings that I should not do that.
So my question is: what to do such that it will work?
maybe other relevant information:
which pip3
/usr/bin/pip3
and (I tried to install flow with pip first, but that did not work)
which pip
/home/bombus/anaconda3/bin/pip
I am working on Ubuntu 16.04.3 LTS

After a clean install of OpenCV via pip it throws an ImportError: DLL load failed

After installing OpenCV via pip on Windows 10 with:
pip install opencv-python
I can not import the module. When executing the command:
import cv2
I get the error:
File "C:\ProgramData\Anaconda3\lib\site-packages\cv2__init__.py",
line 7, in
from . import cv2
ImportError: DLL load failed:...
If I look into the file throwing the code, it looks like the following:
import sys
import os
# FFMPEG dll is not found on Windows without this
os.environ["PATH"] += os.pathsep + os.path.dirname(os.path.realpath(__file__))
from . import cv2
sys.modules['cv2'] = cv2
So I guess it is ffmpeg which is missing. Thus I installed ffmpeg like described here: http://www.wikihow.com/Install-FFmpeg-on-Windows
Thus, ffmpeg is in my path. However, the error message still occurs. I also tried to install the ffmpeg via pip with
pip install ffmpeg-normalize
But this did not help either.
The opencv-python Windows packages ship with FFmpeg by default. You can have a look at C:\ProgramData\Anaconda3\lib\site-packages\cv2 and you should find FFmpeg DLL there. You don't have to install it separately.
The real problem lies most probably in Anaconda because they are not shipping python3.dll with their distribution. This is required by PEP 384. Related Anaconda issue is here: https://github.com/ContinuumIO/anaconda-issues/issues/1394
To fix this, you will have to copy python3.dll from a CPython installer package and place it to PATH. The CPython version must match your Anaconda version. Easiest way is to copy the file to some place which is already in PATH. This could be for example C:\Anaconda3 if that's where your Anaconda installation is located.
If the above does not work, make sure that you have Visual C++ redistributable 2015 installed: https://www.microsoft.com/en-us/download/details.aspx?id=48145

ImportError: No module named bs4 in Windows

I am trying to create a script to download the captcha from my website.
I think the code works except from that error, when I run it in cmd (I am using windows not Linux) I receive the following:
from bs4 import BeautifulSoup
ImportError: No module named bs4
I tried using pip install BeautifulSoup4
but then I receive a syntax error at install.
Here is the script:
from bs4 import BeautifulSoup
import urllib2
import urllib
url = "https://example.com"
content = urllib2.urlopen(url)
soup = BeautifulSoup(content)
img = soup.find('img',id ='imgCaptcha')
print img
urllib.urlretrieve(urlparse.urljoin(url, img['src']), 'captcha.bmp')
The problem according to this answer must be due to the fact I have not activated the virtualenv, and THEN install BeautifulSoup4.
I don't think this information will be of any help but I saved my python text in a notepad.py and the run it using cmd.
I had the same problem until a moment ago. Thanks for the post and comments! According to #Martin Vseticka 's suggestion I checked if I have the pip.exe file in my python folders. I run python 2.7 and 3.7 simultaneously. I didn't have it in the python 2.7 folder but in the 3.7.
So in the command line I changed the directory to where the pip.exe file was located. Then I ran "pip install BeautifulSoup4" and it worked. See enclosed screen shot.
I did a fresh install of Python 3.5 on my Windows 8.1 (64b) machine and then run:
C:\Users\Me\AppData\Local\Programs\Python\Python35-32\Scripts>pip install b
eautifulsoup4
Collecting beautifulsoup4
Downloading beautifulsoup4-4.4.1-py3-none-any.whl (81kB)
100% |################################| 81kB 890kB/s
Installing collected packages: beautifulsoup4
Successfully installed beautifulsoup4-4.4.1
and then run:
C:\Users\Me\AppData\Local\Programs\Python\Python35-32>python test.py
test.py contains only:
from bs4 import BeautifulSoup
I received no error.
I could install bs4, but still got an error message like yours. My operation system is 64 bit, and I only had this issue after I installed the latest Python in "32 bit" version. So I removed the 32 bit one, then I can import the bs4 again, and it still works after I install the latest Python in 64 version. Hope it helps.
I have python3.7 32bit and python3.7 64 bit installed on Windows 10.
For this app, I am using the 32 bit version.
I was getting the following error:
ImportError: No module named bs4
when I was trying to 'import bs4' from my app.py. Someone said: "Make sure your pip and your python are both 32 bits", but omitted to explicitly say how, so here it is:
Delete your virtual environment if it exists.
Create a new venv using python -m venv venv, but explicitly call it from your 32bit python directory like this:
C:\Users\me\AppData\Local\Programs\Python\Python37-32\python -m venv my_venv
install the requirements by explicitly calling the 32bit version like this:
C:\Users\me\AppData\Local\Programs\Python\Python37-32\Scripts\pip install -r requirements.txt
That's it. I hope it works.

Pillow import error from _imaging.so / libjpeg.8.dylib on OSX

I've used Pillow in the past on OSX without problems, however I now get the following error.
File "/Library/Python/2.7/site-packages/PIL/Image.py", line 61, in <module>
from PIL import _imaging as core
ImportError: dlopen(/Library/Python/2.7/site-packages/PIL/_imaging.so, 2): Library not loaded: /usr/local/lib/libjpeg.8.dylib
Referenced from: /Library/Python/2.7/site-packages/PIL/_imaging.so
Reason: image not found
I've seen this question which appears to be a similar problem but I don't think I installed Pillow with brew.
I've also tried the solution from this question but the command
pip install PIL --allow-external PIL --allow-unverified PIL
dosent seem to work and I get an error (no such option: --allow-unverified)
Lastly, I've tried to recreate the symbolic link to libjpeg.8.dylib but that also did not make any difference.
Would anyone know how to fix this error? Do I need to do something to relink _image.so aswell as libjpeg?
Python PIL was deprecated eons ago and you should not attempt to use it anymore.
What you want is python[23] -m pip install Pillow
PS. Using pip command will be deprecated soon because of confusions regarding python interpreters, instead of calling pip ... everyone should use only python -m pip ... which assures that is calling the right interpreter.

No module named Image

Sorry for my grammar, I don't speak English.
After I set filebrowser, tinymce, and grappelli, I get this error: No module named Image
try:
from PIL import Image
except ImportError:
import Image
I set it to PIL but it didn't solve the problem.
my platform windows
If i want: pip install PIL
`c:\Users\Kim\BitNami DjangoStack projects\homex8>pip install PIL
Downloading/unpacking PIL
Running setup.py egg_info for package PIL
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
Installing collected packages: PIL
Running setup.py install for PIL
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
building '_imaging' extension
error: Unable to find vcvarsall.bat`
I do not understand what that means
Solved problem.
reinstall PIL with easy_install, and more movements, here are the details.
You are missing PIL (Python Image Library and Imaging package). To install PIL I used
pip install pillow
For my machine running Mac OSX 10.6.8, I downloaded Imaging package and installed it from source.
http://effbot.org/downloads/Imaging-1.1.6.tar.gz and cd into Download directory. Then run these:
$ gunzip Imaging-1.1.6.tar.gz
$ tar xvf Imaging-1.1.6.tar
$ cd Imaging-1.1.6
$ python setup.py install
Or if you have PIP installed in your Mac
pip install http://effbot.org/downloads/Imaging-1.1.6.tar.gz
then you can use:
from PIL import Image
in your python code.
Did you setup PIL module? Link
You can try to reinstall it on your computer.
It is changed to : from PIL.Image import core as image
for new versions.
You can this query:
pip install image
I had pillow installed, and still, I got the error that you mentioned. But after I executed the above command, the error vanished. And My program worked perfectly.
Problem:
~$ simple-image-reducer
Traceback (most recent call last):
File "/usr/bin/simple-image-reducer", line 28, in <module>
import Image
**ImportError: No module named Image**
Reason:
Image != image
Solution:
1) make sure it is available
python -m pip install Image
2) where is it available?
sudo find ~ -name image -type d
-->> directory /home/MyHomeDir/.local/lib/python2.7/site-packages/image
->> OK
3) make simple-image-reducer understand via link:
ln -s ~/.local/lib/python2.7/site-packages/image
~/.local/lib/python2.7/site-packages/Image
4)
invoke simple-image-reducer again.
Works:-)
If you are trying to just show the image on your notebook, below simply does the job
from IPython.display import Image
Image(url= "Link to the image ending with file format such as, .jpg or .png")

Categories

Resources