Archive

Posts Tagged ‘pip’

update all packages with pip in your virtual environment

January 5, 2017 Leave a comment

Problem
You want to update all installed packages in your virtual environment.

Solution

$ pip install pip-review
$ pip-review --local --interactive

Tip from here.

Categories: python Tags: ,

python setup.py uninstall

November 2, 2014 Leave a comment

Problem
Sometimes you need to install a software with “python setup.py install“. However, if you want to get rid of it, there is no “python setup.py uninstall” or “python setup.py remove”. Stupid, but true.

Solution
I found the solution here. In short:

# install:
$ (sudo) python setup.py install

# uninstall:
$ pip freeze | grep PATTERN_BASED_ON_PACKAGE_NAME
# then remove with pip:
$ (sudo) pip uninstall PACKAGE_NAME
Categories: python Tags: , ,

pip-tools

January 25, 2014 Leave a comment

“A set of two command line tools (pip-review + pip-dump) to help you keep your pip-based packages fresh, even when you’ve pinned them.

pip-review checks PyPI and reports available updates. It uses the list of currently installed packages to check for updates, it does not use any requirements.txt.

pip-dump dumps the exact versions of installed packages in your active environment to your requirements.txt file.”

I haven’t used it yet, so this post a reminder for me. I think I will need it soon.

Categories: python Tags: ,

PyPy is awesome

August 15, 2013 Leave a comment

PyPy is a fast, compliant alternative implementation of the Python language (2.7.3 and 3.2.3).

Installation
Visit the download page and get the 32-bit or 64-bit archive, depending on your architecture. I extracted it in the /opt directory and put a symbolic link on it:

jabba@jabba-uplink:/opt$ ls -al | grep pypy
lrwxrwxrwx  1 jabba jabba     8 Aug 15 12:32 pypy -> pypy-2.1
drwxr-xr-x  7 jabba jabba  4096 Jul 31 12:59 pypy-2.1

If you install a newer version, just update the symbolic link.

Put another symbolic link to /usr/bin called pypy that points to /opt/pypy/bin/pypy:

root@jabba-uplink:~# ls -al /usr/bin/pypy
lrwxrwxrwx 1 root root 18 Aug 15 16:39 /usr/bin/pypy -> /opt/pypy/bin/pypy

Try it:

jabba@jabba-uplink:~$ pypy
Python 2.7.3 (480845e6b1dd, Jul 31 2013, 09:57:07)
[PyPy 2.1.0 with GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>>

Install pip for pypy
We also want to use 3rd party libraries with pypy thus we need pip.

$ wget http://python-distribute.org/distribute_setup.py
$ wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ pypy distribute_setup.py
$ pypy get-pip.py

Add the following alias to your ~/.bashrc:

alias pip_pypy='/opt/pypy/bin/pip'

Open a new terminal and you are ready to install 3rd party libraries. Example:

$ pip_pypy install futures    # import concurrent.futures

Tip from here. Getting started here.

Categories: python Tags: ,

update all pip packages

Problem
You want to update all the pip-installed Python packages on your system.

Solution
At http://stackoverflow.com/questions/2720014/ there is a very nice little script for this task:

import pip
from subprocess import call

for dist in pip.get_installed_distributions():
    call("pip install --upgrade " + dist.project_name, shell=True)

I modified it a bit to update packages in ascending order by name in an ignore-case way:

#!/usr/bin/env python

import os
import pip

dists = []
for dist in pip.get_installed_distributions():
    dists.append(dist.project_name)

for dist_name in sorted(dists, key=lambda s: s.lower()):
    cmd = "sudo pip install {0} -U".format(dist_name)
    print '#', cmd
    #os.system(cmd)

I want to update the packages globally, that’s why the “sudo“. If you run it, it will just print the commands to the stdout (dry run). If everything is OK, uncomment the last line.

Update (20140121)
I made a github project of it: https://github.com/jabbalaci/update-pip-packages.

Categories: python Tags: , ,

Install a package with pip from a github repository

December 27, 2012 Leave a comment

Problem
You want to install a package from a GitHub repository via pip.

Solution
Let’s take an example. Say you want to install requests whose github address is https://github.com/kennethreitz/requests.

With pip you can istall it like this:

sudo pip install -U https://github.com/kennethreitz/requests/zipball/master
Categories: python Tags: ,

Install a package via pip even if PyPI is down

December 2, 2012 Leave a comment

Problem
PyPI is down but still, you want to install a package.

Solution
Use a mirror, e.g. Create.io:

sudo pip install -i http://simple.crate.io/ <package_name>
Categories: python Tags: , , , ,