opencv for python installation - python

I have followed the instructions in here [http://www.pyimagesearch.com/2015/07/20/install-opencv-3-0-and-python-3-4-on-ubuntu/] , in order to install python3. I am using Ubtuno 12.04. Upon checking my python version, I have:
$ python --version
Python 2.7.3
$ python3 --version
Python 3.2.3
In Step 2, I use:
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python3 get-pip.py
but I receive the following error after running the second line:
/tmp/tmp4ijset/pip.zip/pip/_vendor/pkg_resources/__init__.py:80: UserWarning: Support for Python 3.0-3.2 has been dropped. Future versions will fail here.
Traceback (most recent call last):
File "get-pip.py", line 19177, in <module>
main()
File "get-pip.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip
File "/tmp/tmp4ijset/pip.zip/pip/__init__.py", line 16, in <module>
File "/tmp/tmp4ijset/pip.zip/pip/vcs/mercurial.py", line 9, in <module>
File "/tmp/tmp4ijset/pip.zip/pip/download.py", line 36, in <module>
File "/tmp/tmp4ijset/pip.zip/pip/utils/ui.py", line 15, in <module>
File "/tmp/tmp4ijset/pip.zip/pip/_vendor/progress/bar.py", line 48
empty_fill = u'∙'
^
SyntaxError: invalid syntax
Q1: What is the source of this error please and how can I solve it to have pip3 installed on my machine?
Q2: How can I install openCV under python 3?

Related

zipimport.ZipImportError: can't decompress data; zlib not available in Linux

I have two python versions, two different places 2.6 and 2.7, as shown below
#python --version
Python 2.6.6
#/usr/local/python27/bin/python2.7 --version
Python 2.7.15
I need to install paramiko module, which doesn't exists, So trying to install through pip, pip its self prompting below error
# pip --version
Traceback (most recent call last):
File "/usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 959, in <module>
class Environment:
File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 963, in Environment
self, search_path=None, platform=get_supported_platform(),
File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 190, in get_supported_platform
plat = get_build_platform()
File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 393, in get_build_platform
from sysconfig import get_platform
ImportError: No module named sysconfig
So I install get-pip.py and trying to configure as below , though I have installed zlib
# ./python2.7 get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 21401, in <module>
main()
File "get-pip.py", line 197, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip._internal
zipimport.ZipImportError: can't decompress data; zlib not available
Since my python2.7 custom installation, again I tried on configure with LDFLAGS="-Wl,--rpath=/usr/include/" where the zlib library located at /usr/include/ though still I am getting the "zipimport.ZipImportError:" error, your help much appreciated.
./configure --enable-shared \
--prefix=/usr/local/python27 \
LDFLAGS="-Wl,--rpath=/usr/include/"

Installing enum34 on Python 3.x breaks pip for Python3.x

I used PythonAnywhere to host some Python scripts that required the fbchat module. I installed the module on Python 3.6 (with user scheme) without using virtualenv, and the module installed enum34 as a dependency.
I know enum34 is incompatible with Python versions greater than 3.4. However I can't uninstall it now either because calling pip3.x gives this error:
Traceback (most recent call last):
File "/usr/local/bin/pip3.6", line 4, in <module>
import re
File "/usr/lib/python3.6/re.py", line 142, in <module>
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'
and the command $ python3.6 -m pip gives:
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/lib/python3.6/runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "/usr/local/lib/python3.6/dist-packages/pip/__init__.py", line 4, in <module>
import locale
File "/usr/lib/python3.6/locale.py", line 16, in <module>
import re
File "/usr/lib/python3.6/re.py", line 142, in <module>
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'
These are the exact steps to reproduce, and the only commands used to get here:
$ pip3.6 install --user fbchat
Just delete the package from your site-packages folder manually.
Locate it first:
python3.6 -c 'import enum; print(enum.__file__)'
then delete the whole enum directory that file lives in, it'll be in a site-packages directory. Delete the enum34-<version>.dist-info file next to it too.
Because you used --user, the package was installed in your user-site directory. You can get the location with the site module too:
python3.6 -m site --user-site
so you can remove the offending package with:
rm -rf `python3.6 -m site --user-site`/enum
rm `python3.6 -m site --user-site`/enum-*.dist-info

Strange error when trying to install PIP

Trying install PIP.
I have python 2.7 installed on Windows 7 (32-bit)
I created a file called get-pip.py as instructed here: https://pip.pypa.io/en/stable/installing/
When I run that file with python, I get the following error. The user account has admin rights.
Does anyone know what is going on?
C:\Python27>python get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 20061, in <module>
main()
File "get-pip.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip
File "c:\users\sek~1.sek\appdata\local\temp\tmpvkex0l\pip.zip\pip\__init__.py", line 21, in <module>
File "c:\users\sek~1.sek\appdata\local\temp\tmpvkex0l\pip.zip\pip\_vendor\requests\__init__.py", line 62, in <module>
File "c:\users\sek~1.sek\appdata\local\temp\tmpvkex0l\pip.zip\pip\_vendor\requests\packages\__init__.py", line 27, in <module>
File "c:\users\sek~1.sek\appdata\local\temp\tmpvkex0l\pip.zip\pip\_vendor\requests\packages\urllib3\__init__.py", line 8, in <module>
File "c:\users\sek~1.sek\appdata\local\temp\tmpvkex0l\pip.zip\pip\_vendor\requests\packages\urllib3\connectionpool.py", line 41, in <module>
File "c:\users\sek~1.sek\appdata\local\temp\tmpvkex0l\pip.zip\pip\_vendor\requests\packages\urllib3\request.py", line 7, in <module>
File "c:\users\sek~1.sek\appdata\local\temp\tmpvkex0l\pip.zip\pip\_vendor\requests\packages\urllib3\filepost.py", line 9, in <module>
File "c:\users\sek~1.sek\appdata\local\temp\tmpvkex0l\pip.zip\pip\_vendor\requests\packages\urllib3\fields.py", line 2, in <module>
File "C:\Python27\lib\email\utils.py", line 313
fallback charset='us-ascii'):
^
SyntaxError: invalid syntax
C:\Python27>
Do I need to install pip?
pip is already installed if you're using Python 2 >=2.7.9 or Python 3 >=3.4 binaries downloaded from python.org, but you'll need to upgrade pip.
Just add pip to your environment path:
<python install dir>/Scripts/
Which can be easily done using an elevated command-prompt:
setx path "%path%;<python install dir>/Scripts/"
Then, upgrade it:
python -m pip install -U pip

Using Python 3 when Python 2.7 is default, pip install error

I originally had both python 2.7 and python 3 installed with python 2.7 as my default in PATH. I needed to run a script using python 3 but could not set it as my default python in PATH for some reason. After just uninstalling python 2.7 I opened 3 and ran the command python get-pip.py install which gave me this error
C:\Python30>python get-pip.py install
Traceback (most recent call last):
File "c:\users\jacob\appdata\local\temp\tmplqxvtx\pip.zip\pip\compat\__init__.py", line 16, in <module>
ImportError: cannot import name OrderedDict
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "get-pip.py", line 19177, in <module>
main()
File "get-pip.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip
File "c:\users\jacob\appdata\local\temp\tmplqxvtx\pip.zip\pip\__init__.py", line 14, in <module>
File "c:\users\jacob\appdata\local\temp\tmplqxvtx\pip.zip\pip\utils\__init__.py", line 22, in <module>
File "c:\users\jacob\appdata\local\temp\tmplqxvtx\pip.zip\pip\compat\__init__.py", line 18, in <module>
File "c:\users\jacob\appdata\local\temp\tmplqxvtx\pip.zip\pip\compat\ordereddict.py", line 25, in <module>
ImportError: No module named UserDict
I already tried python -m pip install (module name) but it returns No module named pip
I assume you use windows, so here is an answer how to install pip on windows:
how-do-i-install-pip-on-windows
On Linux you could just type:
sudo apt install python-pip

python3 in a virtualenv still uses library in /usr/lib/python2.7/dist-packages

I have successfully created a virtual environment with virtualenvwrapper using python3 at /usr/local/bin/python3 as default interpreter. My system python is python2.7
I can't use pip3 in this virtual environment because it keeps looking inside the default /usr/lib/python2.7/dist-packages
(python3.3.3)╭ ➜ xxx#xxx:~VIRTUAL_ENV/bin
╰ ➤ pip3.3
Traceback (most recent call last):
File "/home/xxx/virtualenv/python3.3.3/bin/pip3.3", line 7, in <module>
from pip import main
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 11, in <module>
from pip.basecommand import command_dict, load_command, load_all_commands, command_names
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 11, in <module>
from pip.baseparser import parser, ConfigOptionParser, UpdatingDefaultsHelpFormatter
File "/usr/lib/python2.7/dist-packages/pip/baseparser.py", line 5, in <module>
import pkg_resources
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 45
def _bypass_ensure_directory(name, mode=0777):
^
SyntaxError: invalid token
Am I forgetting something?
I've also tried to install python3 into a custom directory inside /opt but that doesn't help.
Got it. My system $PYTHONPATH contains /usr/lib/python2.7/dist-packages so I simply removed it from the path and everything is now working properly.

Categories

Resources