[英]How to run Python file from command prompt by selecting anaconda or Python in windows?
I have installed Anaconda with Python version 3.x and I have already installed native python 3.6.4. 我用Python 3.x安装了Anaconda,我已经安装了原生的python 3.6.4。 I wanted to run my python script from the command prompt either using anaconda or native python according to my need. 我想根据我的需要使用anaconda或native python从命令提示符运行我的python脚本。
I tried to run Python script from command prompt but it is actually using anaconda's python instead of the native one. 我试图从命令提示符运行Python脚本,但实际上它使用的是anaconda的python而不是本机的。
My native python is installed in C:/users/user_name/Appdata/local/programs/python/python36 我的本机python安装在C:/ users / user_name / Appdata / local / programs / python / python36中
How should I installed anaconda or what steps can I take. 我应该如何安装anaconda或我可以采取什么步骤。
I didn't set any environment variables. 我没有设置任何环境变量。 I don't prefer that also. 我也不喜欢这样。
First of all, you should update Python to at least 3.7. 首先,您应该将Python更新到至少3.7。
On the first line of your script put this shebang: 在你的脚本的第一行放这个shebang:
#!/usr/bin/env python3
This is for Unix but I understand it works for Windows also. 这是针对Unix的,但我知道它也适用于Windows。 For more detail on shebangs, check here . 有关shebangs的更多详细信息,请点击此处 。
On Windows, the standard Python installer already associates the .py extension with a file type (Python.File) and gives that file type an open command that runs the interpreter (D:\\Program Files\\Python\\python.exe "%1" %*). 在Windows上,标准Python安装程序已将.py扩展名与文件类型(Python.File)相关联,并为该文件类型提供运行解释程序的打开命令(D:\\ Program Files \\ Python \\ python.exe“%1” %*)。 This is enough to make scripts executable from the command prompt as foo.py. 这足以使命令提示符中的脚本可执行为foo.py. If you'd rather be able to execute the script by simple typing foo with no extension you need to add .py to the PATHEXT environment variable. 如果您希望通过简单地键入foo而无需扩展来执行脚本,则需要将.py添加到PATHEXT环境变量中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.