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

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

Related

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.

pip2: ImportError: cannot import name RequirementParseError

I can't get pip2 to work.
I need pip2, because I need to use an older tensorflow version which is not supported by python3 pip. When trying to run pip2 install I get this:
Traceback (most recent call last):
File "/usr/bin/pip2", line 11, in <module>
load_entry_point('pip==20.1.1', 'console_scripts', 'pip')()
File "/usr/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/usr/lib/python2.7/site-packages/pip/_internal/commands/__init__.py", line 104, in create_command
module = importlib.import_module(module_path)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/lib/python2.7/site-packages/pip/_internal/commands/install.py", line 24, in <module>
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
File "/usr/lib/python2.7/site-packages/pip/_internal/cli/req_command.py", line 21, in <module>
from pip._internal.req.constructors import (
File "/usr/lib/python2.7/site-packages/pip/_internal/req/constructors.py", line 21, in <module>
from pip._vendor.pkg_resources import RequirementParseError, parse_requirements
ImportError: cannot import name RequirementParseError
I uninstalled pip2 and reinstalled it. Also did the same for pip(3). But this didn't change a thing. I could not find anything useful on this error message and feel a bit helpless. Any ideas?
update forgot to mention, that I use archlinux. I installed it with pacman -S python2-pip
Did you try installing packages using virtualenv ? pacman ? or using only pip ?
Which version of tensorflow are you trying to install ?
You can try install libraries using a recent pip2 version + virtualenv using the following commands:
pacman -S python2 python2-pip python-virtualenv
virtualenv -p python2 py2
. py2/bin/activate
pip install -U pip setuptools wheel
pip install tensorflow ipython
You may also try uninstall python2 first and reinstall it from scratch:
pacman -Rs python2 python2-pip
This link suggests that the problem might be due to a version of setuptools installed in ~/.local . Maybe you can check that.
Nevermind, setuptools was installed in my ~/.local directory for some
reason, superceding the system install, I removed that and pip2 runs
fine now.
Please see this link:
https://askubuntu.com/questions/984868/error-in-installing-sudo-pip-install-v-protobuf-3-0-0a2
The library is different but the error is the same.

Python3.7 on Windows Ubuntu Bash shell ImportError: cannot import name 'HTTPSHandler' from 'urllib.request' (/usr/lib/python3.7/urllib/request.py)

I've recently updated Python to version 3.7 from version 3.5, and made it the default in my bash shell. I've also updated pip and made sure it uses Python3.7.
Now, whenever I try to install any module using pip I get this error"
$pip3 install google
Traceback (most recent call last): File "/home/AnnaK/.local/bin/pip3", line 7, in <module>
from pip._internal.cli.main import main File "/usr/lib/python3/dist-packages/pip/__init__.py", line 16, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa File "/usr/lib/python3/dist-packages/pip/vcs/subversion.py", line 9, in <module>
from pip.index import Link File "/usr/lib/python3/dist-packages/pip/index.py", line 30, in <module>
from pip.wheel import Wheel, wheel_ext File "/usr/lib/python3/dist-packages/pip/wheel.py", line 39, in <module>
from pip._vendor.distlib.scripts import ScriptMaker File "/usr/share/python-wheels/distlib-0.2.2-py2.py3-none-any.whl/distlib/scripts.py", line 14, in <module> File "/usr/share/python-wheels/distlib-0.2.2-py2.py3-none-any.whl/distlib/compat.py", line 66, in <module> ImportError: cannot import name 'HTTPSHandler' from 'urllib.request' (/usr/lib/python3.7/urllib/request.py)
I get the same error if I try to simply run pip. This didn't happen when I was using python3.5. I did have this problem when briefly using python2.7, but I fixed it using https://askubuntu.com/questions/581999/pip-raises-importerror-cannot-import-name-httpshandler. That solution doesn't seem to work for python3.7.
I've tried to reinstall pip, reinstall python3, update my Windows Ubuntu subsystem, and reinstall libssl-dev. I'm stumped. Any help is appreciated!
You must have inadvertently upgraded your system pip (probably through something like sudo pip install pip --upgrade)
pip x.x adjusts where its internals are situated. The pip3 command you're seeing is one provided by your package maintainer and is not a file managed by pip.
You can read more about this on pip's issue tracker
You'll probably want to not upgrade your system pip and instead use a virtualenv.
To recover the pip3 binary you'll need to sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall.
It should work fine if you use the first approach python3 -m pip ... instead of pip3 ....

Pip broken after installing requests[security]

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.

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