jf328
jf328

Reputation: 7351

python: install two versions of same module

To be more precise, I need to install two versions of Pandas. On one hand, I'm writing codes to be run on a server with pandas 0.13. All other part of my work, I want up-to-date pandas and other modules (0.16.1 for now).

The two projects are not connected and I won't need two versions in one program.

Is there a way to do that?

Edit: I'm using Python 2.7.8 with Anaconda under Windows

Upvotes: 2

Views: 4175

Answers (3)

farhawa
farhawa

Reputation: 10417

Use pkg_resourcesto force the version:

import pkg_resources
pkg_resources.require("YOUR_PACKAGE==VERSION")
import YOUR_PACKAGE

Upvotes: 1

Alexander
Alexander

Reputation: 109686

I would highly recommended miniconda, which is the smaller version of Anaconda. Conda is a package manager which makes installing scientific libraries such as Scipy and Numpy easy. To get it, just install the Miniconda installer.

“Miniconda” only contains Python and conda, and is much smaller than a full Anaconda installer. There are two variants of the installer: Miniconda is based on Python 2, while Miniconda3 is based on Python 3. Once Miniconda is installed, you can use the conda command to install any other packages and create environments (still containing any version of Python you want). If you have a slow internet connection or limited disk space, Miniconda is the way to go.

It is fast to install packagaes such as Pandas and Numpy because many have been precompiled.

On OS X, the latest Python 2 version can be found here and is installed as follows:

$ bashMiniconda-latest-MacOSX-x86_64.sh -p /usr/local/miniconda -b
$ export PATH=/usr/local/miniconda/bin:$PATH
$ which conda
/usr/local/miniconda/bin/conda
$ conda --version
conda 3.7.0

Once Miniconda is installed, you can use the conda command to install any other packages and versions, and create environments, etc. For example:

$ conda install pandas=0.16.0
...
$ conda create -n py3k anaconda python=3
...

Two versions of the same package cannot run simultaneously, so I would recommend setting up a copy of your existing environment and then installing the desired version.

conda list will show all of your installed packages.

Upvotes: 2

merenptah
merenptah

Reputation: 476

The best method is virtualenv. Virtualenv is a tool to create isolated Python environments.

http://virtualenv.readthedocs.org/en/latest/

Upvotes: 3

Related Questions