Python 2 and 3 from Powershell
I've decided to close this question with the following solution: use Cmd.exe
or use the PowerShell
with Bill Stewart's Invoke-CmdScript
(see comments). First, the simpler solution using the Command Prompt (Cmd.exe)
:
# to activateC:\Users\me\> activate py2# to deactivate and return to Python 3.5C:\Users\me\> deactivate
Which activates the Python 2.7 environment I created using conda
. Now, for the Powershell
version. First, go this site and download the Environment.ps1
script. For me, it downloaded as text file, so I opened the file, removed the .txt
extension and replaced it with .ps1
. So, let's say I saved Environment.ps1
in the following directory C:\Users\user_name\AppData\Local\invoke_cmdscript
. Take this path and add it to the PATH user variable within the Environment variables form. Now, the commands to type in your PowerShell
window:
# dot-source my file. Environment.ps1# activate 2.7 environment (if not in the directory of activate.bat, specify full path)Invoke-CmdScript .\activate.bat py2# deactivate 2.7 environment (same note about current directory and full paths)Invoke-CmdScript .\deactivate.bat
If you want python 3 to run every time you type python3, andpython 2 to run every time you type python2:
Depending on where your executables are, simply make some aliases using the following codes:
for python2:
Set-Alias python2 C:\Users\yourusername\python2location\python.exe
for python3:
Set-Alias python3 C:\Users\yourusername\python3location\python.exe
to learn how to make them permanent, check my response at the following page
From your PATH variable it appears you created the py27 env with the name "p27"Try 'activate p27'You can always double check the env names by looking in the "envs" directory in your conda installation folder.