Python Forum

Full Version: I want to eliminate git bash from the setup process
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Complete noob here following tutorials and frankenstaining something together.
I am creating a gemini AI chat bot and every time I want to open the script in VS code again I have to go to the folder where it's located and open git bash first, and run these commands:

Output:
python -m venv (folder name) cd (folder name)/ . Scripts/activate pip install google-generativeai
As per this tutorial at 5:17: https://www.youtube.com/watch?v=w73nrTquxm0&t=331s
Otherwise my code doesn't recognise google module (The error is: "import google.generativeai as genai
ModuleNotFoundError: No module named 'google'")


This is my code:
import google.generativeai as genai

API_KEY = ''

genai.configure(api_key=API_KEY)

model = genai.GenerativeModel("gemini-pro")
chat = model.start_chat()

while True:
    message = "My custom prompt" + input("You: ")
    if message.lower() == 'PanicMode80085':
        print('Chatbot: Goodbye!')
        break
    response = chat.send_message(message)
    print('Chatbot', response.text)
How do I modify this code so that I don't have to re-install google-generativeai every time I want to open the script again?
(I have concealed the API key and the prompt)
Once you have created the virtual environment and installed dependencies, you just need to activate it before running your code. i.e. it is not about modifying your code.
Also, note - you activate it once, then you can run your code as many times as you want as long using the interpreter from the virtual environment

https://realpython.com/python-virtual-en...-a-primer/
https://stackoverflow.com/q/41972261/4046632
(Dec-02-2024, 08:56 AM)buran Wrote: [ -> ]Once you have created the virtual environment and installed dependencies, you just need to activate it before running your code. i.e. it is not about modifying your code.
Also, note - you activate it once, then you can run your code as many times as you want as long using the interpreter from the virtual environment

https://realpython.com/python-virtual-en...-a-primer/
https://stackoverflow.com/q/41972261/4046632

Can I in any way automate this process so that I don't have to open gitbash and type commands every time I close the programs? Will opening the virtual environment/activating it, work if done in the python script itself instead of having to do it externally with git bash?
I think you just need to add a shebang at the top of your script. The shebang tells your system what python.exe you want to use when running the script.

Read about the shebang here:

https://realpython.com/python-shebang/