简体   繁体   中英

Activating a Virtual Environment when running .bat file using Windows Scheduler

Using pycharm, I finished my first python program. I am attempting to run a bat file with Windows Scheduler. The python script has lots of dependencies. They are available in the virtual environment I am using.

  1. I tried activating my virtual environment using the activate.bat file in the directory of the venv. The code of the scheduled bat file looked like this:

     C:\Users\PavelWorkXPS\Anaconda3\envs\TestEnv\Lib\venv\scripts\nt\activate.bat "D:\Dropbox\Toolkit\Python\Unusual_Options_Activity-ToS\main.py" pause

When running this, Pycharm would launch because it is my default.py extension handler.

  1. I modified the bat file to use the interpreter python.exe from within the virtual environment folder, hoping it would have access to the dependencies.

     C:\Users\PavelWorkXPS\Anaconda3\envs\TestEnv\python.exe "D:\Dropbox\Toolkit\Python\Unusual_Options_Activity-ToS\main.py" pause

Output would tell me it still can't see the dependencies. 在此处输入图像描述

I used this earlier stackoverflow post for help, but it only explained the reason why pycharm was opening by itself.

Conda was the reason for the problem. When I switched to doing it with a plain virtual environment, it stored all the downloaded repos in a folder inside of the folder with the script. Then I setup the bat file and all worked fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM