简体   繁体   English

python:安装同一模块的两个版本

[英]python: install two versions of same module

To be more precise, I need to install two versions of Pandas. 更准确地说,我需要安装两个版本的Pandas。 On one hand, I'm writing codes to be run on a server with pandas 0.13. 一方面,我正在编写要在带有熊猫0.13的服务器上运行的代码。 All other part of my work, I want up-to-date pandas and other modules (0.16.1 for now). 在我工作的所有其他部分中,我需要最新的熊猫和其他模块(目前为0.16.1)。

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 编辑:我在Windows下将Python 2.7.8与Anaconda一起使用

The best method is virtualenv. 最好的方法是virtualenv。 Virtualenv is a tool to create isolated Python environments. Virtualenv是用于创建隔离的Python环境的工具。

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

I would highly recommended miniconda , which is the smaller version of Anaconda . 我强烈推荐miniconda ,这是Anaconda的较小版本。 Conda is a package manager which makes installing scientific libraries such as Scipy and Numpy easy. Conda是一个软件包管理器,可以轻松安装Scipy和Numpy等科学库。 To get it, just install the Miniconda installer. 要获取它,只需安装Miniconda安装程序。

“Miniconda” only contains Python and conda, and is much smaller than a full Anaconda installer. “ Miniconda”仅包含Python和conda,并且比完整的Anaconda安装程序小得多。 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). 安装程序有两种变体:Miniconda基于Python 2,而Miniconda3基于Python3。安装Miniconda后,您可以使用conda命令安装任何其他软件包并创建环境(仍然包含您所使用的任何Python版本)想)。 If you have a slow internet connection or limited disk space, Miniconda is the way to go. 如果您的互联网连接速度慢或磁盘空间有限,则可以使用Miniconda。

It is fast to install packagaes such as Pandas and Numpy because many have been precompiled. 安装Pagas(例如Pandas和Numpy)的速度很快,因为其中许多已经预编译。

On OS X, the latest Python 2 version can be found here and is installed as follows: 在OS X上,可以在此处找到最新的Python 2版本,并按以下方式安装:

$ 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: 一旦安装了Miniconda,就可以使用conda命令安装任何其他软件包和版本,并创建环境等。例如:

$ 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. conda list将显示所有已安装的软件包。

Use pkg_resources to force the version: 使用pkg_resources强制版本:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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