指定Windows使用Anaconda Python解释器

3
我已安装Python 2.7,并在Windows上安装了Anaconda(使用Python 3.6)。每当我尝试在Anaconda环境之外的Windows中运行我的.py脚本时,Windows默认使用Python 2.7解释器。我的脚本无法导入模块(我认为这是使用错误的解释器)。
我尝试根据此帖子How should I set the default Python version in Windows和此帖子Changing python interpreter windows更改路径变量。我还尝试直接从命令行将默认的.exe从2.7版本更改为Anaconda中的Python.exe。
我需要考虑Anaconda版本是否位于“C:\ Users \ william \ AppData \ Local \ Continuum \ anaconda3 \ python.exe”?所有其他帖子都将Python.exe称为类似“C:// python27 /”之类的内容。我期望能够将默认解释器设置为使用上述位置,并将其设置为.py文件的默认值。
当前Python版本:

enter image description here

假设这是来自:

enter image description here

我假设我想要使用这个版本:

enter image description here

我已经尝试将以下内容添加到用户和系统路径变量中:

enter image description here


有关这个问题,有人能提供帮助吗?我相信其他人也一定使用过Anaconda并遇到了类似的问题。 - WillD
卸载所有Python版本并重新安装仅需要的最新版本,根据此帖子解决了我的问题:https://dev59.com/Km445IYBdhLWcg3wAFm0?noredirect=1&lq=1 - WillD
解答我的问题的链接:https://dev59.com/UV8d5IYBdhLWcg3wRAiE#34867186 - WillD
2个回答

0

另一个对我有效的解决方案。

  • 打开命令提示符并输入where python。 对于我来说:
C:\Users\user\anaconda3\python.exe
C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe

我将使用第一条路径到Python解释器,因为它与Anaconda相关。

  • 按照这个教程的步骤,我将C:\Users\user\anaconda3\Scripts\C:\Users\user\anaconda3\添加到环境变量的系统变量部分中的Path变量中。

0

我遇到了同样的问题。我首先尝试从我的环境变量中删除“C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe”,然后我从“程序”应用中卸载了Python。接下来,我将以下内容添加到我的路径环境变量中。

C:\Users\user\anaconda3\Scripts\
C:\Users\user\anaconda3\

这样做后,我可以成功地通过命令提示符启动Python

python

我得到了

Python 3.9.12 (main, Apr  4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)] :: 
Anaconda, Inc. on win32                                                                                                                                              
Warning:                                                                                                                
This Python interpreter is in a conda environment, but the environment has                                              
not been activated.  Libraries may fail to load.  To activate this 
environment                                          please see 
https://conda.io/activation                                                                                                                                                                                                          
Type "help", "copyright", "credits" or "license" for more information. 

带有警告信息


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接