简体   繁体   中英

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

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

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

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.

Use pkg_resources to force the version:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM