Python 2, pip and TLS

Begonnen von Mte90, 2017/07/03, 17:07:34

Vorheriges Thema - Nächstes Thema

Mte90

I have a problem with running commands with pip.root@siduction:/home/mte90# pip install --upgrade pyopenssl                 
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 10, in <module>
    from pip import main
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 21, in <module>
    from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
  File "/usr/lib/python2.7/dist-packages/pip/_vendor/__init__.py", line 68, in <module>
    vendored("html5lib")
  File "/usr/lib/python2.7/dist-packages/pip/_vendor/__init__.py", line 36, in vendored
    __import__(modulename, globals(), locals(), level=0)
  File "/usr/lib/python2.7/dist-packages/html5lib/__init__.py", line 16, in <module>
    from .html5parser import HTMLParser, parse, parseFragment
  File "/usr/lib/python2.7/dist-packages/html5lib/html5parser.py", line 11, in <module>
    from . import _inputstream
  File "/usr/lib/python2.7/dist-packages/html5lib/_inputstream.py", line 4, in <module>
    from six.moves import http_client, urllib
  File "/usr/lib/python2.7/dist-packages/six.py", line 203, in load_module
    mod = mod._resolve()
  File "/usr/lib/python2.7/dist-packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/usr/lib/python2.7/dist-packages/six.py", line 82, in _import_module
    __import__(name)
  File "/usr/lib/python2.7/httplib.py", line 1230, in <module>
    import ssl
  File "/usr/lib/python2.7/ssl.py", line 133, in <module>
    PROTOCOL_SSLv23 = PROTOCOL_TLS
NameError: name 'PROTOCOL_TLS' is not defined[code]
I looked on internet and seems the problem based on openssl that is not updated in the system, the debian package as un updated on november 2016 https://packages.debian.org/sid/python-openssl and everything is updated in my machine.So actually for me is impossible to use pip on python 2.x.Anyone has suggestions or a workround for it?

melmarker

and where is the problem? In other words - why do you expect pip to work outside a virtual environment?
Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety. (Benjamin Franklin, November 11, 1755)
Never attribute to malice that which can be adequately explained by stupidity. (Hanlons razor)

Mte90

I am trying to use pip packages on my local machine but everytime I try to install a package I gto this error.I always used pip in my local machine for my scripts and never used ina virtual machine, so I am not sure of this error is based on a missing update on my machine of something.

melmarker

pythons virtual environment isn't a virtual machine, only an environment that is maintained via pip and have all needed things in the right version in it. One will never win against apt in that regard - so pip in a normal system environment can and will break without warning sometimes - only one thing is sure, it will break somewhen.


http://python-guide-pt-br.readthedocs.io/en/latest/dev/virtualenvs/
Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety. (Benjamin Franklin, November 11, 1755)
Never attribute to malice that which can be adequately explained by stupidity. (Hanlons razor)

Mte90

Ok but in any case this is a bug that I don't find a solution.I use it only to download package that not are available on debian like for marionette.

melmarker

#5
the virtenv is the solution - create a virtenv, activate the environment, install your things with pip
next app - next environment


apt install python-virtenv
virtualenv foo
source ~/foo/bin/activate
pip install bar
deactivate
Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety. (Benjamin Franklin, November 11, 1755)
Never attribute to malice that which can be adequately explained by stupidity. (Hanlons razor)

Mte90

Uhm this can be very uncomfortable especially with application desktop done with qt as example.I can check if the errore doesn't happen on virtualenv

Mte90

I got the same error also on vend so is not a problem where to use but a problem of python:
mte90:/tmp  $  virtualenv foo                                                                                                                                                   
Running virtualenv with interpreter /usr/local/bin/python2                                                                                                                                                         
Using real prefix '/usr'                                                                                                                                                                                           
New python executable in /tmp/foo/bin/python2                                                                                                                                                                       
Also creating executable in /tmp/foo/bin/python                                                                                                                                                                     
Installing setuptools, pkg_resources, pip, wheel...                                                                                                                                                                 
  Complete output from command /tmp/foo/bin/python2 - setuptools pkg_resources pip wheel:
  Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 21, in <module>
    from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
  File "/usr/lib/python2.7/dist-packages/pip/_vendor/__init__.py", line 64, in <module>
    vendored("cachecontrol")
  File "/usr/lib/python2.7/dist-packages/pip/_vendor/__init__.py", line 36, in vendored
    __import__(modulename, globals(), locals(), level=0)
  File "/tmp/foo/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/__init__.py", line 9, in <module>
  File "/tmp/foo/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/wrapper.py", line 1, in <module>
  File "/tmp/foo/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/adapter.py", line 4, in <module>
  File "/tmp/foo/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/__init__.py", line 52, in <module>
  File "/tmp/foo/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/packages/__init__.py", line 53, in <module>
  File "/tmp/foo/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/packages/__init__.py", line 35, in vendored
  File "/tmp/foo/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/__init__.py", line 8, in <module>
  File "/tmp/foo/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 11, in <module>
  File "/tmp/foo/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/exceptions.py", line 2, in <module>
  File "/tmp/foo/share/python-wheels/six-1.10.0-py2.py3-none-any.whl/six.py", line 203, in load_module
    mod = mod._resolve()
  File "/tmp/foo/share/python-wheels/six-1.10.0-py2.py3-none-any.whl/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/tmp/foo/share/python-wheels/six-1.10.0-py2.py3-none-any.whl/six.py", line 82, in _import_module
    __import__(name)
  File "/usr/lib/python2.7/httplib.py", line 1230, in <module>
    import ssl
  File "/usr/lib/python2.7/ssl.py", line 133, in <module>
    PROTOCOL_SSLv23 = PROTOCOL_TLS
NameError: name 'PROTOCOL_TLS' is not defined
----------------------------------------
...Installing setuptools, pkg_resources, pip, wheel...done.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 2375, in <module>
    main()
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 724, in main
    symlink=options.symlink)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 992, in create_environment
    download=download,
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 922, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 817, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /tmp/foo/bin/python2 - setuptools pkg_resources pip wheel failed with error code 1

melmarker

hit me for it - but it seems you want a python3 environment
Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety. (Benjamin Franklin, November 11, 1755)
Never attribute to malice that which can be adequately explained by stupidity. (Hanlons razor)

Mte90

Uhm indeed seems a mix between 2 and 3 but on sid I used https://packages.debian.org/it/sid/python-virtualenvSo I am trying to use on python 2...