Python Forum
I want to eliminate git bash from the setup process
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I want to eliminate git bash from the setup process
#1
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)
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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?
Reply
#4
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/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Eliminate entering QR - Whatsapp web automated by selenium akanowhere 1 4,018 Jan-21-2024, 01:12 PM
Last Post: owalahtole
  How to eliminate unwanted spaces Mohan 5 4,274 Jun-04-2020, 08:34 AM
Last Post: buran
  How to sharing object between multiple process from main process using Pipe Subrata 1 4,470 Sep-03-2019, 09:49 PM
Last Post: woooee
  How to eliminate magic squares formed by the same numbers, but permuted frame 7 4,837 May-09-2019, 11:28 AM
Last Post: frame

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020