Upgrade python packages with pip: use “sudo” or “–user”?

pip install -U PACKAGENAME --user

With --user they are installed in your $HOME directory in:

$HOME/.local/lib/python2.7/site-packages

Using sudo your package will be installed in:

/usr/local/lib/python2.7/dist-packages/

How to get pip to work behind a proxy server

On Ubuntu, you can set proxy by using

export http_proxy=http://username:password@proxy:port
export https_proxy=http://username:password@proxy:port

or if you are having SOCKS error use

export all_proxy=http://username:password@proxy:port

Then run pip

sudo -E pip3 install {packageName}

The pip’s proxy parameter is, according to pip --help, in the form scheme://[user:passwd@]proxy.server:port

You should use the following:

pip install --proxy http://user:password@proxyserver:port TwitterApi

Also, the HTTP_PROXY env var should be respected.

pip install – locale.Error: unsupported locale setting

Problem:

  ~ pip install virtualenv
Traceback (most recent call last):
  File "/usr/bin/pip", line 11, in <module>
    sys.exit(main())
  File "/usr/lib/python3.4/site-packages/pip/__init__.py", line 215, in main
    locale.setlocale(locale.LC_ALL, '')
  File "/usr/lib64/python3.4/locale.py", line 592, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

Solution:

Short answer-

just run the following command:

$ export LC_ALL=C

If you keep getting the error in new terminal windows, add it at the bottom of your .bashrc file.

Long answer-

Here is my locale settings:

$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=C

urllib and “SSL: CERTIFICATE_VERIFY_FAILED” Error

in Python 3.6.1 on MacOs Sierra

Entering this in the bash terminal solved the problem:

pip install certifi
/Applications/Python\ 3.6/Install\ Certificates.command

Unable to uninstall AWS CLI : Cannot uninstall requirement awscli, not installed

I was trying to install AWS CLI on mac but was facing some challenges as aws command was unable to parse the credential file. So I decided to re-install the whole stuff but facing some issues here again.

I am trying pip uninstall awscli which says

Cannot uninstall requirement awscli, not installed

So, i try pip3 install awscli --upgrade --user which gives me this:

    You are using pip version 6.0.8, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Requirement already up-to-date: awscli in ./Library/Python/3.5/lib/python/site-packages
Requirement already up-to-date: rsa<=3.5.0,>=3.1.2 in ./Library/Python/3.5/lib/python/site-packages (from awscli)
Requirement already up-to-date: docutils>=0.10 in ./Library/Python/3.5/lib/python/site-packages (from awscli)
Requirement already up-to-date: PyYAML<=3.12,>=3.10 in ./Library/Python/3.5/lib/python/site-packages (from awscli)
Requirement already up-to-date: colorama<=0.3.7,>=0.2.5 in ./Library/Python/3.5/lib/python/site-packages (from awscli)
Requirement already up-to-date: botocore==1.8.29 in ./Library/Python/3.5/lib/python/site-packages (from awscli)
Requirement already up-to-date: s3transfer<0.2.0,>=0.1.12 in ./Library/Python/3.5/lib/python/site-packages (from awscli)
Requirement already up-to-date: pyasn1>=0.1.3 in ./Library/Python/3.5/lib/python/site-packages (from rsa<=3.5.0,>=3.1.2->awscli)
Requirement already up-to-date: python-dateutil<3.0.0,>=2.1 in ./Library/Python/3.5/lib/python/site-packages (from botocore==1.8.29->awscli)
Requirement already up-to-date: jmespath<1.0.0,>=0.7.1 in ./Library/Python/3.5/lib/python/site-packages (from botocore==1.8.29->awscli)
Requirement already up-to-date: six>=1.5 in ./Library/Python/3.5/lib/python/site-packages (from python-dateutil<3.0.0,>=2.1->botocore==1.8.29->awscli)

Not sure what to do.

Solution:

You run pip3 install awscli but pip uninstall awscli. Shouldn’t it be pip3 uninstall awscli?

python: uninstall python 2.7 install via source

To completely remove python you can execute:

rm -f /usr/local/bin/python2.7
rm -f /usr/local/bin/pip2.7
rm -f /usr/local/bin/pydoc
rm -rf /usr/local/bin/include/python2.7
rm -f /usr/local/lib/libpython2.7.a
rm -rf /usr/local/lib/python2.7

You might also have to do

rm -f /usr/local/share/man/python2.7.1
rm -rf /usr/local/lib/pkgconfig
rm -f /usr/local/bin/idle
rm -f /usr/local/bin/easy_install-2.7

python pip broken on ubuntu: forcing reinstallation of alternative /usr/bin/pip2 because link group pip is broken

I got the same error. I did this and it worked!

sudo apt-get install --reinstall python2.7

This to reinstall python. Don’t ever try to uninstall python ,it will crash your OS as part of Ubuntu is dependent on python.Then,

sudo apt-get purge python-pip

This is to remove pip.

 wget https://bootstrap.pypa.io/get-pip.py

Installs pip..`

sudo python get-pip.py

Then,you can install packages using pip like

sudo pip install package-name

change python for pip

You can check which python is configured with pip with command:
pip –version
pip uses the following package name python$VERSION-pip
The python specific pip will be installed, then you can change the default pip as:
update-alternatives –install /usr/bin/pip pip /usr/bin/pip2 1

update-alternatives –config pip Then select the pip version you want.