简体   繁体   English

如何获取要在 Windows 中使用 anaconda 环境运行的 Python 脚本的可执行文件?

[英]How to get an executable for a Python script to be run using anaconda environment in Windows?

I don't want to convert my .py file to .exe file.我不想将我的 .py 文件转换为 .exe 文件。 Rather I want a simple .exe file which can activate my anaconda virtual environment and run the script kept at a particular directory path.相反,我想要一个简单的 .exe 文件,它可以激活我的 anaconda 虚拟环境并运行保存在特定目录路径中的脚本。 Any idea how to do it!知道怎么做!

Suppose you have an Anaconda environment with name saputara with which you want to run hello_world.py kept at the directory *E:\\vaibhav\\work*.假设您有一个名为saputara的 Anaconda 环境,您想用它运行hello_world.py保存在目录 *E:\\vaibhav\\work* 中。 Copy following peace of code to the notepad将以下代码复制到记事本

E:
cd vaibhav\work\
call C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3
call activate saputara
python hello_world.py
pause

Now save this file with extension .bat .现在用扩展名.bat保存这个文件。 Double clicking on this file will automatically execute hello_world.py双击这个文件会自动执行hello_world.py

use the bat scripting to get your task done.使用 bat 脚本来完成您的任务。

@echo off
conda activate env_name
python file_name.py

copy this to a notepad and save it as a .exe file.将其复制到记事本并将其另存为 .exe 文件。 This will activate a conda environment there and run the python script.这将在那里激活 conda 环境并运行 python 脚本。

OR或者

@echo off
cd %1
conda activate env_name
python %2.py

run this using cmd cause it takes two parameters.使用 cmd 运行它,因为它需要两个参数。 first the directory path and second the file name you can google if you wanna know more about bat scripting.首先是目录路径,其次是文件名,如果您想了解有关 bat 脚本的更多信息,可以在 google 上搜索。 You can add it to path as well to use it from anywhere.您也可以将其添加到路径以从任何地方使用它。

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

相关问题 如何在 Mac 上使用 anaconda 虚拟环境运行 python 脚本 - How to run a python script using an anaconda virtual environment on mac 如何从 Anaconda 环境中获取可执行文件 Python 路径? - How to get an executable Python path out of an Anaconda environment? 如何在 crontab 中使用 Anaconda 环境运行我的 Python 脚本? - How to run my Python script with Anaconda environment in crontab? 如何从 Windows 中的 Python 脚本创建可在 Mac 上运行的可执行文件? - How to create an executable from a Python script in Windows that can run on a Mac? 使用我的 anaconda 环境运行 windows 批处理文件以调用 python 脚本 - Run windows batch file to call on python scripts with my anaconda environment 如何安排从anaconda运行的python脚本? - How to schedule python script run from anaconda? 使用 python 子进程在不同的 anaconda 环境中启动 python 脚本 - Using python subprocess to launch a python script in a different anaconda environment 无法获得Unicode可执行文件以运行Python脚本 - Cannot get Unicode Executable to Run Python Script 如何在 Snakemake 中引用 anaconda 环境中的可执行文件 - How to refer to executable inside anaconda environment in Snakemake Python/Anaconda - 运行环境 python 可执行文件与激活环境不同吗? - Python/Anaconda - Is running the environment python executable different than activating the environment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM