Sorry if this is the wrong place to ask but I couldn't find a much better one... I have a Discord bot that I want to run on startup of my computer. I use PyCharm so it has a venv. I've tried task scheduler and shell:startup (both a shortcut and a batch file) but neither works. Does anyone know how I can do this? Any and all help appreciated ๐
#๐ How do I make a Python file using a virtual environment run on computer startup?
26 messages ยท Page 1 of 1 (latest)
@static talon
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
Please ping me when replying so I see it quicker!
Why doesn't the batch file work?
why? idk I run the batch file nothing happens
@echo off
call "C:\Users\JonS\PycharmProjects\csa-trainings\.venv\Scripts\activate.bat"
pythonw "C:\Users\JonS\PycharmProjects\csa-trainings\main.py"
Maybe get rid of the w so you can see the output
sure I'll try
you might need to cd into the venv directory as well
C:
cd "Users\JonS\PycharmProjects\csa-trainings\.venv"
call "Scripts\activate.bat"
python "C:\Users\JonS\PycharmProjects\csa-trainings\main.py"
``` like this?
do not cd into the venv itself, cd into the project root
oh hang on
might be a problem with the python file, I just barely managed to see the word "traceback" before the batch file closed itself
but that's very strange because running it from pycharm works fine
add pause to the end of the bat
in case you're restarting each time you test, remember that you can just run the bat directly for testing before you set it to run on startup
?
yeah definitely a working directory issue
the file is there... why does it not work?
python looks for files relative to your current working directory, not relative to the file you're running
aka you have to cd into the right folder before running it
oh yay, that worked
very sorry, I really thought it wasn't a problem with the file...
but thank you so so much for the help! ๐
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.