I would like to auto run a Python script.
First, I created a *.PY file and ran it in Anaconda Prompt within my Environment successfully.
Next, I created a .BAT file where the Python PATH was Python within the Environment I wish to run, and then the .PY file. I created the file in Notepad and saved it with extension .BAT:
C:\Users\fh\Anaconda3\envs\myenvo\python.exe "C:\Users\fh\Documents\Python Scripts\myautocode.py"
pause
Now, when I run the .BAT file from Windows Explorer via double click, I get the following error in a command prompt window:
File "C:\Users\fh\Anaconda3\envs\myenvo\lib\ssl.py", line 98, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: DLL load failed while importing _ssl: The specified module could not be found.
Press any key to continue . . .
Once I can get this to work, I plan to run it automatically using Windows Task Scheduler. I'm following the process as described here:
https://towardsdatascience.com/automate-your-python-scripts-with-task-scheduler-661d0a40b279
**I realized my issue was really I wasn't calling my environment correctly - so the real question was, how should you load the environment in your BAT file, I will answer the question below. This is how I should have had my BAT file **
call C:\Users\fh\Anaconda3\Scripts\activate.bat
call conda activate myenvo
python.exe "C:\Users\fh\Documents\Python Scripts\project\run_project_auto.py"
pause
Thank you