Anaconda installed for python 2 and 3. Cannot start 2

I installed both versions of Anaconda for Python 2 and 3.

I have added a path.

I am using the Anaconda prompt.

python program.py

It is assumed that I am using Python 3. For example, it cannot understand:

print "hello!"

I tried:

py program.py
py -2 program.py

But they did not work. How to run a Python 2 program?

If I print:

python

at the Acaconda prompt, then he says:

python 3.5.1. Anaconda 2.4.1

So the hint assumes I'm using Python 3.

But I have programs written in Python 2 AND programs written in Python 3.

I want to switch between the two smoothly. How can I do it?

+4
source share
1 answer

A simple solution is to create an environment for Python 2:

conda create -n py27 python=2.7 anaconda

, . enter .

.

Windows:

activate py27 

:

source activate py27 

(py27). Python 2.7.

:

deactivate 

Python 3. . Python:

conda create -n py34 python=3.4 anaconda
conda create -n py35 python=3.5 anaconda

Anaconda , :

conda create -n myenv python=3.5
source activate myenv

, . :

conda install numpy pytables sympy

bash .profile .bashrc:

py27() {
exec &>/dev/null
source activate py27
exec &>/dev/tty
python $*
exec &>/dev/null
source deactivate
exec &>/dev/tty
}

Python 27, , Python 2.7:

py27 myscript.py

create Python 2.6, 2,7, 3.3, 3.4 3.5:

pyxx() {
exec &>/dev/null
source activate $1
exec &>/dev/tty
python ${*:2}
exec &>/dev/null
source deactivate
exec &>/dev/tty
}


py26()
{
    pyxx py26 $*
}

py27()
{
    pyxx py27 $*
}

py33()
{
    pyxx py33 $*
}

py34()
{
    pyxx py34 $*
}

py35()
{
    pyxx py35 $*
}

, Python.

+4

Source: https://habr.com/ru/post/1621758/


All Articles