Python: select one of multiple installed module versions

后端 未结 4 1399
旧巷少年郎
旧巷少年郎 2020-12-05 04:41

On my system, I have several modules installed multiple times. To give an example, numpy 1.6.1 is installed in the standard path at /usr/lib/python2.7/dis

4条回答
  •  半阙折子戏
    2020-12-05 05:07

    Besides the suggestions already given in the comment section, have you thought about using virtualenv? This would give you fine-grained control over every module that you want to use. If you're not familiar with virtualenv you'll want to read the documentation to get a feel for how it works.

    Purely for example, you could install and set it up, like so (virtualenv-1.11.6 looks to be the most recent version currently):

    $ curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.11.6.tar.gz
    $ tar xvfz virtualenv-1.11.6.tar.gz
    $ cd virtualenv-1.11.6
    $ python virtualenv.py ../numpyvenv
    $ cd ../numpyvenv
    $ source ./bin/activate
    (numpyvenv) $ pip install numpy
    # downloads, compiles, and installs numpy into the virtual environemnt
    (numpyvenv) $ python
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import numpy
    >>> numpy.version.version
    '1.9.1'
    >>> quit()
    (numpyvenv) $ deactivate
    $ # the virtual environment has been deactivated
    

    Above, we created a virtual environment named "numpyvenv", activated the environment, installed numpy, printed the numpy version (to show it works), quit python, and deactivated the environment. Next time you activate the environment, numpy will be there along with whatever other modules you install. You may run into hiccups while trying this, but it should get you started.

提交回复
热议问题