简体   繁体   English

如何通过在Windows中选择anaconda或Python从命令提示符运行Python文件?

[英]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环境变量中。

For further reading: here 进一步阅读: 这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Windows 命令提示符下运行 python 文件? - How to run a python file in the windows command prompt? 如何从 windows 命令提示符中杀死 python? - how to kill python from windows command prompt? Python 模块请求在 anaconda 提示符下工作但不在 Windows 10 命令行中工作 - Python module requests working in anaconda prompt but not in windows 10 command line 如何从 Windows 10 命令提示符以“python filename.py funcname”格式运行 python 函数? - How to run a python function from Windows 10 command prompt in 'python filename.py funcname' format? 是否可以从 Windows 命令提示符在 shell 中运行 python 程序? - Is it possible to run a python program in the shell from the windows command prompt? 如何在 Windows 10 命令提示符下运行 python 程序 - How to run a python program in Windows 10 command prompt 如何使Python 3.9运行命令提示符windows 10? - How to make Python 3.9 run command prompt windows 10? 如何将文件.py转换为.exe,从Anaconda Navigator获取Python? (我应该在哪个命令提示符下编写安装代码?) - How to convert file .py to .exe, having Python from Anaconda Navigator? (in which command prompt should I write installation codes?) 如何从Windows命令提示符运行.py文件? - How to Run .py file from Windows Command Prompt? Python:从python脚本的Windows命令提示符中执行windows命令 - Python: Executing the windows command in windows command prompt from python script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM