已安装Anaconda 2和3,如何在命令提示符切换至Python 3.6?
Hey there! Let's sort out this Python version switch problem for you. Since you've got both Anaconda 2 (with Python 2.7) and Anaconda 3 (with Python 3.6) installed, here are a few straightforward ways to get Python 3.6 running in your command prompt:
Anaconda's built-in environment management is designed for exactly this kind of version switching. Here's how to use it:
- First, locate your Anaconda 3 installation path (on Windows, it's typically something like
C:\Users\YourUsername\anaconda3). - Open Command Prompt, then run the activation script for Anaconda 3:
Make sure to replace the path with your actual Anaconda 3 install location.C:\Users\YourUsername\anaconda3\Scripts\activate.bat - Once the environment is activated, run
python --versionagain—you should see Python 3.6. To switch back to Python 2.7 later, just rundeactivatein the prompt.
If you want Python 3.6 to be the default whenever you open Command Prompt, tweak your system's PATH variable:
- Right-click "This PC" → Properties → Advanced System Settings → Environment Variables.
- In the "System Variables" section, find the
PATHvariable and click Edit. - Look for the entries related to Anaconda 2 (they'll look like
C:\Users\YourUsername\anaconda2andC:\Users\YourUsername\anaconda2\Scripts). Move these entries below the Anaconda 3 entries (C:\Users\YourUsername\anaconda3andC:\Users\YourUsername\anaconda3\Scripts). - Save your changes, close and reopen Command Prompt. Now
python --versionshould show Python 3.6 by default.
If you just need to run a single script with Python 3.6 without changing defaults, call the executable directly:
- To check the version:
C:\Users\YourUsername\anaconda3\python.exe --version - To run a script:
C:\Users\YourUsername\anaconda3\python.exe your_script.py
Quick Note
If you've created a dedicated Python 3.6 environment with Conda (like conda create -n py36 python=3.6), you can also activate it directly with conda activate py36—this is great if you want isolated environments for different projects.
内容的提问来源于stack exchange,提问作者Emily Johnson

