简体   繁体   English

如何在Mac上的bash脚本中激活Python虚拟环境并启动python脚本?

[英]How can I activate a Python virtual environment and launch a python script, in a bash script on Mac?

I am trying to create a bash script that will simply 我正在尝试创建一个bash脚本,它将简单地

  1. Activate my venv 激活我的venv
  2. Launch a python script 启动python脚本

that can be double clicked and executed on Mac. 可以双击并在Mac上执行。

My script is as follows: 我的脚本如下:

#!/usr/bin/env bash
./macVenv/bin/activate
python main.py

I can run from command line just fine. 我可以从命令行运行就好了。 When I double click though it complains it cannot find the python file. 当我双击但它抱怨找不到python文件时。

Yes. 是。 The following script works on my machine. 以下脚本可在我的计算机上使用。

source activate $1
python $2

I run it by typing ./script_name py36 python_file_name 我通过输入./script_name py36 python_file_name来运行它

where script_name is the name of the script with these 2 lines. 其中script_name是这两行的脚本名称。 py36 is the name of the virtual environment and python_file_name is the python script you want to run. py36是虚拟环境的名称,而python_file_name是要运行的python脚本。

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

相关问题 从 python 脚本激活虚拟环境 - Activate virtual environment from a python script 如何激活Python虚拟环境并同时执行脚本? - How to activate a Python virtual environment and execute a script at the same time? 如何从bash脚本中临时绕过python虚拟环境? - How can I temporary bypass python virtual environment from inside a bash script? 如何获取在 python 中启动脚本时定义的环境变量? - How can I get environment variables defined at script launch in python? 如何在 Mac 上使用 anaconda 虚拟环境运行 python 脚本 - How to run a python script using an anaconda virtual environment on mac 如何在python shell中激活虚拟环境 - how can I activate virtual environment in python shell 如何通过 python 脚本在 linux 上激活 conda 环境? - How do I activate a conda environment on linux through a python script? 如何在 Python 脚本中激活 Conda 环境? - How to activate a Conda environment within a Python script? 当没有activate.bat并且我是凡人时,如何在虚拟环境中的任务调度程序中运行 python 脚本 - How do I run a python script in task scheduler in a virtual environment when there is no activate.bat and I'm mortal Python 脚本可以激活虚拟环境,然后在其中触发交互式 pdb 会话吗? - Can a Python script activate a virtual environment and then trigger an interactive pdb session within it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM