Califlower
Califlower

Reputation: 487

Installing same packages in pip3 as in pip

I am using both python 2.7 now added python 3.4.

How I could easy migrate packages installed via pip to pip3?

A followup for the future: is there a way to install packages to both 2.7 and 3.4 version of python?

Edit 1: combining answers. Edit 2: moved solution to an answer.

Upvotes: 3

Views: 4661

Answers (2)

Califlower
Califlower

Reputation: 487

Moved to the answer as suggested by Two-Bit Alchemist.

first updated all the packages

pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs pip install -U

Then I "reinstalled"to python 3

brew install pip3
cd /usr/local/bin
ln -sfnv ../Cellar/python3/3.4.2_1/bin/python3 python
unset PYTHONPATH
eval 'export PYTHONPATH=/usr/local/lib/python3.4/site-packages'

and then reinstall to python 3

pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs pip3 install

I packed it all in a bash function and now it's all automated for simple future use! Thank you guys!

Upvotes: 4

Terry Jan Reedy
Terry Jan Reedy

Reputation: 19144

pip is a program that installs the appropriate version of a python package (using its metadata) to pythonx.y/lib/site-packages for some values of x and y. On *nix, the default x.y is the latest version of python2. pip3 is an alias that changes the default to the latest version of python3.

pip -h 

lists the pip commands and general options.

pip command -h

lists the options for command, such as install.

Taken literally, migrating 'to pip3' is not meaningful. Getting the same packages installed for 3.4 that you have installed for 2.7 is, of course. The method given by Two-Bit Alchemist should work for every package that is compatible with 3.x, though I believe requirement files are meant for copying a pythonx.y installation to another pythonx.y installation (possibly in a virtual environment). It will install the same x.y.z version of the package that you already have, even if outdated, so you might want to update your 2.7 collections first with

pip install -U <package>

for each package.

Upvotes: 2

Related Questions