Trying to install OpenCV with Matplotlab - python

I am attempting to install OpenCV on my linux computerI followed this installation guide:
Linux / Mac Users:
pip3 install numpy or apt-get install python3-numpy. You may need to apt-get install python3-pip.
pip3 install matplotlib or apt-get install python3-matplotlib.
apt-get install python-OpenCV.
...
everything installs, except the last one Python-OpenCV
error:
E: unable to locate package python-OpenCV
and then when I run python in the terminal and try to run:
import matplotlab
I get the error
Traceback (most recent call last):
file "stdin>", line 1, in <module>
Importerror: no module named 'matlabplot'
meanwhile
import cv2
&
import numpy
run without error and seem to work, this is also the case when I run a .py file that calls for importing those three.
Any information will be helpful, i am fairly new to python and linux :)

Use Anaconda, there are download for Windows, Linux and Mac. Installation is easy.
I would suggest you download Anaconda2.
Then install with command (on Linux) (more documentation on installation)
bash ~/Downloads/Anaconda2-4.4.0-Linux-x86_64.sh
There are cv2, mathplotlib pre-install
*NOTE: I trying to find mathplotlab or matlabplot with Python on Google but can't find any. Instead, Google suggests mathplotlib. Perhaps you mistake library name

The openCV 3 package is called opencv-python in pip3 (python3). For python2, replace pip3 with pip and python3-opencv with python-opencv
Mac OS (OS X) / Linux
$ pip3 install -U opencv-python
or as mentioned by #GregHNZ on linux
$ apt-get install python3-opencv
All versions are imported with import cv2 inside python scripts.
Probably you can import cv2and numpybecause it is installed for dependency reasons by other packages.
As in comments already mentioned probably you mean matplotlib

Related

Difficulty installing/importing pyqt5 on ubuntu 18.04

Goal: To import pyqt5 into python3 under Ubuntu 18.04
I know there are many answers to similar questions here and elsewhere. I have tried a lot of them, but I don't see anything that exactly matches my situation.
Starting with a clean installation of Ubuntu 18.04, I have tried many ways to be able to have the statement import pyqt5 succeed in Python 3.6.9, which is the default python3 on this distribution.
None of them have succeeded.
In several attempts, reinstalling Ubuntu anew several times, I have had pip3 either experience a 404 downloading https://pypi.org/simple/python3-pyqt5/ and confirmed the error by pasting the URL into Firefox and also getting a 404. (I also checked the Firefox was working fine accessing the Internet)
But usually I run through a process that seems to indicate that pyqt was loaded successfully but was still unable to import it in Python3.
Among the things I've tried from various web sites are:
pip3 install --upgrade pip
pip3 install pyqt5==5.14.0 vs pip3 install pyqt5 (defaulting to 5.14.1)
installing a simple pypi module and finding that I can import it into Python3 with no problem
running pip3 under sudo
upgrading python3 to Python 3.7.4
A more complete list of what I did starting with the reinstall is shown below.
Any suggestions for solutions or what to look at on my system?
I have a bootable memory stick of Ubuntu 18.04.4 that I created last week by downloading the executable from Ubuntu.com. Everything that's packaged with the release seems to work fine, including Python 3.6.9 in other situations. I do virtually nothing except the following steps.
sudo apt install python3-pip
pip3 install humanfriendly (just to ensure that pip3 works for a simply pypi module)
pip3 install --upgrade pip
pip3 install python3-pyqt5
sudo apt-get install pyqt5-dev-tools (no complaints from pip3 seems to work okay)
sudo apt-get install qttools5-dev-tools (seems to work)
in python3
>>>import pyqt5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyqt5'
pip3 uninstall pyqt5 (Successfully uninstalled PyQt5-5.14.0)
pip3 install pyqt5 --user (Successfully installed pyqt5-5.14.1
Try to import in python3 again, same result: "No module named 'pyqt5'"
cd ~/.local/bin
ls
humanfriendly pip pip3 pip3.6 pylupdate5 pyrcc5 pyuic5
(there seems not to be an entry for pyqt5 although there is for some of its stand-alone componentes)
pip3 uninstall pyqt5
ls
humanfriendly pip pip3 pip3.6
(what was there went away)
pip3 uninstall pyqt5 (Successfully uninstalled PyQt5-5.14.1)
pip3 install pyqt5 --user (seems to succeed)
try to import in python3 (same error)
pip3 uninstall pyqt5 (Successfully uninstalled PyQt5-5.14.1)
next I tried sudo pip3 uninstall pyqt5
seems to work; not importable in python3; sudo pip3 uninstall
next I created a virtual env, ~/.vents/tevs
activate the venv
pip3 install pyqt5==5.14.0
Installing collected packages: PyQt5-sip, pyqt5
attempt to import pyqt5 in python3: fails as before
pip3 uninstall pyqt5
(Successfully uninstalled PyQt5-5.14.0 after listing thousands of files
in .venvs/tevs/lib/python3.6/site-packages/PyQt5)
pip3 install python3-pyqt5
(fails with HTTP Error: 404 Client Error:
Not Found for url: https://pypi.org/simple/python3-pyqt5/)
Several problems should be noted in what the OP notes:
The name of the library does not necessarily match the name of how to import the libraries, on the other hand pip accepts names like pyqt5 and PyQt5 as equivalent, but when you import it you should use PyQt5, not pyqt5, so to test that you have installed you can do the following:
Run on the console:
$ python3 -c "from PyQt5.Qt import PYQT_VERSION_STR; print(PYQT_VERSION_STR)"
5.14.1
Run on python console:
Python 3.8.1 (default, Jan 22 2020, 06:38:00)
[GCC 9.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5.Qt import PYQT_VERSION_STR
>>> print(PYQT_VERSION_STR)
5.14.1
python3-pyqt5 is the name of the package that offers ubuntu repositories for the version of pyqt5 that your community compiles which is generally a non-current version. So to install pyqt5 there are several methods:
Using ubuntu repository: sudo apt-get install python3-pyqt5
Using pip: python3 -m pip pyqt5 (You must use sudo if required) or python3 -m pip install pyqt5 --user (This method also applies to virtualenv)
So I can conclude that the OP has successfully installed PyQt5 but has failed to verify if the installation has been correct so I recommend using what is indicated in (1)
I recently encountered this problem on Ubuntu 20.04 and here is what worked for me.
Firstly, after trying much of what you described I finally decided to run python --version from terminal and the output told me that python 2.7 was the default version on my system. This was the problem.
Secondly, after thinking "sheeeee-*t partner", I checked for any python2 dependencies using apt rdepends python --installed.
Lastly, after confirming that I had no python2 dependencies, I ran sudo apt-get install python-is-python3 in order to make python3 the default version.

Why is a package I have installed not getting recognised

I have installed a package named hypixel for my discord bot using pip install hypixel. It finished installing without any errors. At the top of my script I have import hypixel. But when I try and run it I get this error:
File "D:\Documents\Discord Bot\Addicts Discord Bot\bot.py", line 1, in <module>
import hypixel
ModuleNotFoundError: No module named 'hypixel'
I am not sure if this is too relevant but my pip isn't the latest version and I get an error when I try and update it.
Edit: I have now successfully updated my pip. But even when I try and reinstall the package it still won't work.
Instead of using pip install python, use pip install hypixel. Then try to import it in your code using import hypixel.
In your question you say you used pip install python, did you mean to say pip install hypixel?
Also if you use python3 but have python3 installed make sure you use pip3.
You can install this with sudo apt-get install python3-pip (assuming you use a debian based distro). Then use sudo pip3 install hypixel
Edit:
For windows installation follow this link

can't import libraries installed in python

I usually try to install libraries for python by :
sudo apt-get install python-lib name
and when the operation is complete I can't import the library I have tried this for pygame,tk and other libs. I also usually can't install any library with pip because it gives me a bunch of error and I have also tried installing packages with their source by :
python setup.py build
python setup.py install
and usually I get errors on the "build" part.
What should I do?
Are you using Ubuntu? Probably yes. Ubuntu have two versions of python preinstalled: python2.7 and python3.4. Your command is installing library for python2.7. If you are writing your script for python 3.4, then you fail with import libraries. Try using sudo apt-get install python3-packagename to install library for python3.
edit:
are you using your pip command with sudo? sudo pip instal ...?

Understanding twisted installation in Linux Mint

I wanted to install twisted on my Mint Linux 17 machine. I downloaded the source file (from here). I extracted the contents into a folder, changed to that folder and ran the following commands to install the library.
$ python setup.py build
$ sudo python setup.py install
I had to use sudo for the second command, because I could not get it to work without sudo.
Everything was installed without any problem, but when I try to run a sample code I got a import error.
$ python datagram.py
Traceback (most recent call last):
File "datagram.py", line 3, in <module>
from twisted.internet.protocol import DatagramProtocol
ImportError: No module named twisted.internet.protocol
But it works when I run the same with sudo.
$ sudo python datagram.py
Why is this happening? What do I need to fix to get twisted programs running without the need for sudo?
sudo setup.py install is one of the ways to screw up your installation of Python and its libraries. Other members of the club include sudo easy_install <package> and sudo pip install <package>.
If you want to do a system-wide installation of a Python library (or any piece of software, probably): use your system package manager.
If you want to install a version of a Python library different from the version available from your system package manager, use virtualenv and install the library into that.

ImportError: No module named Cython.Distutils

I'm having a strange problem while trying to install the Python library zenlib, using its setup.py file. When I run the setup.py file, I get an import error, saying
ImportError: No module named Cython.Distutils`
but I do have such a module, and I can import it on the python command line without any trouble. Why might I be getting this import error?
I think that the problem may have to do with the fact that I am using Enthought Python Distribution, which I installed right beforehand, rather than using the Python 2.7 that came with Ubuntu 12.04.
More background:
Here's exactly what I get when trying to run setup.py:
enwe101#enwe101-PCL:~/zenlib/src$ sudo python setup.py install
Traceback (most recent call last):
File "setup.py", line 4, in <module>
from Cython.Distutils import build_ext
ImportError: No module named Cython.Distutils
But it works from the command line:
>>> from Cython.Distutils import build_ext
>>>
>>> from fake.package import noexist
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named fake.package
Note the first import worked and the second throws an error. Compare this to the first few lines of setup.py:
#from distutils.core import setup
from setuptools import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import os.path
I made sure that the Enthought Python Distribution and not the python that came with Ubuntu is what is run by default by prepending my bash $PATH environment variable by editing ~/.bashrc, adding this as the last line:
export PATH=/usr/local/epd/bin:$PATH
and indeed which python spits out /usr/local/epd/bin/python... not knowing what else to try, I went into my site packages directory, (/usr/local/epd/lib/python2.7/site-packages) and give full permissions (r,w,x) to Cython, Distutils, build_ext.py, and the __init__.py files. Probably silly to try, and it changed nothing.
Can't think of what to try next!? Any ideas?
Install Cython:
pip install cython
Your sudo is not getting the right python. This is a known behaviour of sudo in Ubuntu. See this question for more info. You need to make sure that sudo calls the right python, either by using the full path:
sudo /usr/local/epd/bin/python setup.py install
or by doing the following (in bash):
alias sudo='sudo env PATH=$PATH'
sudo python setup.py install
For python3 use
sudo apt-get install cython3
For python2 use
sudo apt-get install cython
Details can be read at this
Run
which python
Thats the path to the python that your system has defaulted too
then go to #tiago's method of:
sudo <output of which python> setup.py install
I only got one advice for you : Create a virtualenv. This will ensure you have only one version of python and all your packages installed locally (and not on your entire system).
Should be one of the solutions.
In the CLI-python, import sys and look what's inside sys.path
Then try to use export PYTHONPATH=whatyougot
Running the following commands resolved the issue for me in ubuntu 14.04:
sudo apt-get install python-dev
sudo apt-get install libusb-1.0-0-dev
sudo apt-get install libsystemd-daemon-dev
sudo pip install cython
This link helped me: https://github.com/trezor/python-trezor/issues/40
Ran into this again in modern times. The solution was simple:
pip uninstall cython && pip install cython
Read like a thousand of these threads and finally got it for Python 3. (replace pip with pip3 if you have that kind of installation, and run pip uninstall cython if you have tried other solutions before running any of these)
Mac:
brew install cython
pip install --upgrade cython
Ubuntu
sudo apt-get install cython3 python-dev
pip install --upgrade cython
Windows (must have conda, and MinGW already in path)
conda install cython
conda install --upgrade cython
That is easy.
You could try install cython package first.
It will upgrade your easy_install built in python.
I had dependency from third party library on Cython, didn't manage to build the project on Travis due to the ImportError. In case someone needs it - before installing requirements.txt run this command:
pip install Cython --install-option="--no-cython-compile"
Installing GCC also might help.
Just install Cython from
http://cython.org/#download
and install it using this command
sudo python setup.py install
Then run the command
sudo python -c 'import Cython.Distutils'
and it will be installed and the error message will disappear.

Categories

Resources