How to use multiple versions of Python without uninstallation

前端 未结 15 1522
醉梦人生
醉梦人生 2021-02-05 14:11

I am faced with a unique situation, slightly trivial but painful.

I need to use Python 2.6.6 because NLTK is not ported to Python 3 (that\'s what I could gather).

相关标签:
15条回答
  • 2021-02-05 14:54

    The OP request is a little outdated, especially now that NLTK does have a py3.x port. see Install nltk 3.0 on Ubuntu 13.10 using tar.gz download

    Here's how you can get python3 to work with NLTK.

    $ sudo apt-get install python3-pip
    $ sudo pip3 install pyyaml
    $ wget http://www.nltk.org/nltk3-alpha/nltk-3.0a3.tar.gz
    $ tar -xzvf nltk-3.0a3.tar.gz
    $ cd nltk-3.0a3/
    $ sudo python3 setup.py install
    $ python3
    >>> import nltk
    >>> from nltk.corpus import brown
    >>> print(brown.sents()[0])
    ['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', 'Friday', 'an', 'investigation', 'of', "Atlanta's", 'recent', 'primary', 'election', 'produced', '``', 'no', 'evidence', "''", 'that', 'any', 'irregularities', 'took', 'place', '.']
    
    0 讨论(0)
  • 2021-02-05 14:54

    If you're talking about shell, as in linux, if you install python 3, you can invoke it separately with the python3 command. Python 2 is just invoked using python.

    At least this is my experience with Ubuntu-like systems, I haven't used other Linux environments.

    I realize this question is almost a year old, but NLTK has been ported to Python 3 (or at least that was true as of writing this).

    0 讨论(0)
  • 2021-02-05 14:55

    This page has an implementation of collections.Counter that works for Python 2.6:

    • http://code.activestate.com/recipes/576611/
    0 讨论(0)
  • 2021-02-05 14:55

    You can specify the version you want in the shebang line. I just ran into this when a VM my Ops guy set up had Python 2.6 in /usr/bin/python2.6, and I needed 2.7 for a few features. He installed it for me at /usr/bin/python2.7.

    My old shebang:

    #!/usr/bin/env python
    

    stopped working, because /usr/bin/python was a link to /usr/bin/python2.6. What wound up fixing the problem, and working across Windows, Linux, and OSX, was changing the shebang to:

    #!/usr/bin/env python2.7
    

    It should work for any version, I believe.

    0 讨论(0)
  • 2021-02-05 14:57

    not sure this is what you want, but I used to live with this for a long time http://www.portablepython.com/

    0 讨论(0)
  • 2021-02-05 14:58

    Simplest solution : Rename the file in where your path is locations e.g:

    0 讨论(0)
提交回复
热议问题