如何使用Anaconda的Python版本执行Python脚本? [英] How can I execute Python scripts using Anaconda's version of Python?

查看:1074
本文介绍了如何使用Anaconda的Python版本执行Python脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近下载了Python的Anaconda发行版.我注意到,如果我编写并执行Python脚本(通过双击其图标),则我的计算机(在Windows 8上运行)将使用旧版本的Python(而不是Anaconda的版本)执行该脚本.因此,例如,如果我的脚本包含import matplotlib,我将收到一个错误.有没有办法让我的脚本改用Anaconda的Python版本?

I recently downloaded the Anaconda distribution for Python. I noticed that if I write and execute a Python script (by double-clicking on its icon), my computer (running on Windows 8) will execute it using my old version of Python rather than Anaconda's version. So for example, if my script contains import matplotlib, I will receive an error. Is there a way to get my scripts to use Anaconda's version of Python instead?

我知道我可以在命令提示符下打开Anaconda的Python版本并手动将其导入,但是我想对我们进行设置,以便我可以双击.py文件和Anaconda的Python版本.是自动使用的.

I know that I can just open Anaconda's version of Python in the command prompt and manually import it, but I'd like to set things us so that I can just double-click on a .py file and Anaconda's version of Python is automatically used.

推荐答案

我知道这很旧,但是如果您希望能够双击Python文件并具有正确的解释器,那么这里的答案都不是真正的解决方案.每次要使用其他解释器时,都无需修改PYTHONPATHPATH即可使用.当然,在命令行中,activate my-environment是有效的,但是OP专门询问了有关双击的问题.

I know this is old, but none of the answers here is a real solution if you want to be able to double-click Python files and have the correct interpreter used without modifying your PYTHONPATH or PATH every time you want to use a different interpreter. Sure, from the command line, activate my-environment works, but OP specifically asked about double-clicking.

在这种情况下,正确的做法是使用适用于Windows的Python启动器.然后,您要做的就是将#! path\to\interpreter\python.exe添加到脚本的顶部.不幸的是,尽管启动器是Python 3.3+的标准配置,但Anaconda并未随附该启动器(请参见此处.

In this case, the correct thing to do is use the Python launcher for Windows. Then, all you have to do is add #! path\to\interpreter\python.exe to the top of your script. Unfortunately, although the launcher comes standard with Python 3.3+, it is not included with Anaconda (see Python & Windows: Where is the python launcher?), and the simplest thing to do is to install it separately from here.

这篇关于如何使用Anaconda的Python版本执行Python脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆