Pip broken after installing requests[security] - python

After running
pip install requests[security]
Running any pip command outputs the error below. I've tried apt-get removing and reinstalling python-pip as well as python-pyopenssl. Wondering if anyone has advice or has ran into this problem? I can't upgrade python or Debian and would like to get pip working again.
Debian 6.0.10
Python 2.6.6
python-pip 1.5.6
$ pip --version
Traceback (most recent call last):
File "/usr/local/bin/pip", line 9, in <module>
load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 305, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 2244, in load_entry_point
return ep.load()
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 1954, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/local/lib/python2.6/dist-packages/pip-1.5.6-py2.6.egg/pip/__init__.py", line 11, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/lib/python2.6/dist-packages/pip-1.5.6-py2.6.egg/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/usr/local/lib/python2.6/dist-packages/pip-1.5.6-py2.6.egg/pip/download.py", line 22, in <module>
from pip._vendor import requests, six
File "/usr/local/lib/python2.6/dist-packages/pip-1.5.6-py2.6.egg/pip/_vendor/requests/__init__.py", line 53, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/usr/local/lib/python2.6/dist-packages/pip-1.5.6-py2.6.egg/pip/_vendor/requests/packages/urllib3/contrib/pyopenssl.py", line 49, in <module>
from ndg.httpsclient.ssl_peer_verification import SUBJ_ALT_NAME_SUPPORT
File "/usr/local/lib/python2.6/dist-packages/ndg/httpsclient/ssl_peer_verification.py", line 14, in <module>
from ndg.httpsclient.subj_alt_name import SubjectAltName
File "/usr/local/lib/python2.6/dist-packages/ndg/httpsclient/subj_alt_name.py", line 102, in <module>
class AnotherName(univ.Sequence):
File "/usr/local/lib/python2.6/dist-packages/ndg/httpsclient/subj_alt_name.py", line 105, in AnotherName
namedtype.NamedType('value', univ.Any().subtype(
AttributeError: 'module' object has no attribute 'Any'

Unfortunately the removal didn't magically happen with sudo apt-get autoremove. Of course I also tried the standard pip uninstall ndg-httpsclient with no luck first.
In the end, I had to go into the python program directory and forcibly removing it.
$ cd usr/local/lib/python2.7/dist-packages
$ sudo rm -rf ndg_httpsclient-0.3.3-py2.7.egg-info
$ sudo rm -rf ndg_httpsclient-0.3.3-py2.7-nspkg.pth
$ sudo rm -rf ndg

Was able to fix this by simply doing: sudo apt-get autoremove

Please reference this bug here: https://github.com/cedadev/ndg_httpsclient/issues/5
I suspect the problem is that pip on Ubuntu is using ndg_httpsclient, and the current ndg_httpsclient conflicts with the
old pyasn1, so pip breaks during installation.
Anyway, valid versions of pyasn1 to choose from are : 0.0.9a0,
0.0.10a0, 0.0.11a0, 0.0.12a0, 0.0.13a0, 0.0.13b0, 0.0.13, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.1.5, 0.1.6, 0.1.7, 0.1.8, 0.1.9
And I have found a semi-reasonable workaround to the problem.
However 0.0.13 doesnt install on Python 3, so I think the minimum
should be at least 0.1.1.
However I see that cryptography requires pyasn1>=0.1.8 , so it is
likely most people will be using that soon.

Related

how do install python packages using python3.11 -m pip

I am trying to install a python application (elastalert2) which requires the latest version of python on an Ubuntu 20.04 machine.
I have managed to install python3.11 and my searching suggested strongly that to install packages in this environment I should use python3.11 -m pip install but when I try I get:
elastalert#secmgrtst02:~$ /usr/bin/python3.11 -m pip install elastalert2==2.9.0
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/usr/lib/python3/dist-packages/pip/__main__.py", line 16, in <module>
from pip._internal.cli.main import main as _main # isort:skip # noqa
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 19, in <module>
from distutils.util import strtobool
ModuleNotFoundError: No module named 'distutils.util'
I have very limited experience with python and do not know what the problem is.
I actually want the app installed in the current directory and initially (before I realised I need 3.11 I used pip3 install -t . elastalert3 which worked fine but would not run...
It is not recommended to install Python packages directly at the system level. It is recommended to install packages (libraries, dependencies) in a so-called "virtual environment".
So I would recommend you do the following:
python3.11 -m venv ~/my-python-environment
~/my-python-environment/bin/python -m pip install elastalert2==2.9.0
And from then on you call the python binary in that environment, to work with the library you just installed:
~/my-python-environment/bin/python -m elastalert.elastalert
You can create as many such environments as you need or want. You can place them wherever you want on your file system, but you can not move them after creation.
You can read more:
https://realpython.com/python-virtual-environments-a-primer/
https://docs.python.org/3/library/venv.html

how to fix "ImportError: cannot import name 'FormatControl'" for pip?

For some reason I can't install anything with pip/pip3 lately. For example, when I try to install mendeley using the command "pip install mendeley", the following error message appears:
Traceback (most recent call last):
File "/Users/u1790509/anaconda3/bin/pip", line 11, in <module>
load_entry_point('pip==10.0.1', 'console_scripts', 'pip')()
File "/Users/u1790509/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 480, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/Users/u1790509/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2691, in load_entry_point
return ep.load()
File "/Users/u1790509/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2322, in load
return self.resolve()
File "/Users/u1790509/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2328, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/Users/u1790509/anaconda3/lib/python3.6/site-packages/pip/_internal/__init__.py", line 42, in <module>
from pip._internal import cmdoptions
File "/Users/u1790509/anaconda3/lib/python3.6/site-packages/pip/_internal/cmdoptions.py", line 16, in <module>
from pip._internal.index import (
ImportError: cannot import name 'FormatControl'
The same error appears whenever I attempt to install packages using pip. Does anyone have any suggestion for fixing it?
thanks,
Stephen
I was having this issue on systems running older versions of Anaconda and Python. Downgrading pip as per this answer and then upgrading it worked for me.
I ran:
conda install pip==9.0.3
pip install --upgrade pip
Then I was able to install the package I wanted to via pip install ....
I'm not sure what's going on behind the scenes since after downgrading from 10.x to 9.0.3, I still got:
Successfully uninstalled pip-20.0.2
Successfully installed pip-20.3.4
Probably a result of mixing Anaconda and pip for package management, but works for now for legacy purposes.

Python3.7 'No module named apt_pkg' error on Linux Mint 19

When I attempt to run some test code my professor gave me using Python3.7 on Linux Mint 19 I get the following error
RuntimeError: Bad code object in .pyc file
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
RuntimeError: Bad code object in .pyc file
At first, I only installed Python3.7 minimal and this error didn't occur, but I needed to install the full version of Python3.7 to use some modules that come with it, and that started this error. I already tried installing Python3.7 dev and it did nothing. I also tried
sudo apt-get remove --purge python3.7-apt
and it said it couldn't even find apt. So I tried
sudo apt-get install python3.7-apt
and it couldn't even find the package. I also tried installing python3-apt and it did nothing. I would uninstall python3-apt first but apparently that could harm the OS because Mint uses Python3.6 internally. Any help resolving this would be much appreciated!
I had the same issue with python3.7
I literally just reinstalled python3-apt and the error disappeard
sudo apt remove python3-apt
then
sudo apt install python3-apt

Python "pip install " is failing with AttributeError: 'module' object has no attribute 'SSL_ST_INIT'

$ sudo pip install --upgrade pyOpenSSL
Traceback (most recent call last):
File "/usr/local/bin/pip", line 9, in <module>
load_entry_point('pip==8.1.1', 'console_scripts', 'pip')()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 558,
in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line
2682, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line
2355, in load
return self.resolve()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line
2361, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python2.7/dist-packages/pip-8.1.1-
py2.7.egg/pip/__init__.py", line 16, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/lib/python2.7/dist-packages/pip-8.1.1-
py2.7.egg/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/usr/local/lib/python2.7/dist-packages/pip-8.1.1-
py2.7.egg/pip/download.py", line 39, in <module>
from pip._vendor import requests, six
File "/usr/local/lib/python2.7/dist-packages/pip-8.1.1-
py2.7.egg/pip/_vendor/requests/__init__.py", line 53, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/usr/local/lib/python2.7/dist-packages/pip-8.1.1-
py2.7.egg/pip/_vendor/requests/packages/urllib3/contrib/pyopenssl.py",
line
54, in <module>
import OpenSSL.SSL
File "/usr/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in
<module>
from OpenSSL import rand, crypto, SSL
File "/usr/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 118, in
<module>
SSL_ST_INIT = _lib.SSL_ST_INIT
AttributeError: 'module' object has no attribute 'SSL_ST_INIT'
I am unable to Uninstall " pip uninstall pyopenssl "
Using pip gets me this error.
Thanks in advance.
Additional Details:
I am using
Distributor ID: Ubuntu
Description: Ubuntu 15.10
Release: 15.10
Codename: wily
I ran into this issue as well. The solution proposed to run pip doesn't work because pip is broken too! I found this solved it for me:
sudo python -m easy_install --upgrade pyOpenSSL
This installed version 17.3.0 which was an upgrade to the (stock python-openssl on xenial) version ?0.15.1?. Note the massive change in version it could be they dropped the leading 0. in later versions.
Anyway, after that, pip and ansible started to work again.
I did the following which seemed to fix the error, not sure if it's the correct way, but it did fix the error on my machine:
I first backed up the directories below, recommend you do same.
rm -rf /usr/lib/python2.7/dist-packages/OpenSSL
rm -rf /usr/lib/python2.7/dist-packages/pyOpenSSL-0.15.1.egg-info
sudo pip install pyopenssl
I couldn't uninstall it because every time I ran pip I got the same error you did: 'module' object has no attribute 'SSL_ST_INIT'.
After the above my pip now works and more importantly my ansible now works (which was broken by my previous updates).
Not sure if it will work on your system, and removing things out of band, like I did, is risky at best, so as a warning, I would say, your mileage may vary with my kludgy fix, use caution!
Below method worked for me, I am using Ubuntu 20.04 and wanted to install Objection for Runtime manipulation and dynamic analysis of iOS apps.
Short Background:
I noticed that when I fired pip3 install objection in terminal it gave me same error as you but the directory path was little bit different.
In my case it was related to python3.8, so I did following things
Solution:
rm -rf /home/smshrimant/.local/lib/python3.8/site-packages/OpenSSL/
sudo rm -rf /usr/local/lib/python3.8/dist-packages/OpenSSL/
Upgrading pyOpenSSL to 16.2.0 fixes it.
pip uninstall pyOpenSSL
pip install pyOpenSSL==16.2.0
There is an issue with version compatibility.

Error after installing EB CLI 3.x

I am trying to install the elastic beanstalk CLI on an EC2 instance (running AMI) using these instructions:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-getting-started.html
I have python 2.7.9 installed, pip and eb. However, when I try to run eb I get the error below. It looks like it is still using python 2.6. How do you fix that?
Thanks!
Traceback (most recent call last):
File "/usr/bin/eb", line 9, in <module>
load_entry_point('awsebcli==3.0.10', 'console_scripts', 'eb')()
File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 473, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2568, in load_entry_point
return ep.load()
File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2259, in load
['__name__'])
File "/usr/lib/python2.6/site-packages/ebcli/core/ebcore.py", line 23, in <module>
from ..controllers.initialize import InitController
File "/usr/lib/python2.6/site-packages/ebcli/controllers/initialize.py", line 16, in <module>
from ..core.abstractcontroller import AbstractBaseController
File "/usr/lib/python2.6/site-packages/ebcli/core/abstractcontroller.py", line 21, in <module>
from ..core import io, fileoperations, operations
File "/usr/lib/python2.6/site-packages/ebcli/core/operations.py", line 762
vars = {n['OptionName']: n['Value'] for n in settings
^
SyntaxError: invalid syntax
Pip is probably set up with Python 2.6 instead of python 2.7.
pip --version
You can reinstall pip with Python 2.7, then reinstall 2.6
pip uninstall awsebcli
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
pip install awsebcli
I had the same problem, the fix for me was actually to upgrade to latest Beanstalk stack ( eb upgrade ). Note there are downtime etc. So investigate if you can run the latest stack before upgrading.
The "smartest" solution for me was to install python-dev tools
sudo apt install python-dev
found here:
http://ericbenson.azurewebsites.net/deployment-on-aws-elastic-beanstalk-for-ubuntu/

Categories

Resources