#πŸ”’ Trouble with venv.

95 messages Β· Page 1 of 1 (latest)

lyric slate
#

So i'm trying to create this bot but i'm can't pass the venv wall. i'm super newbie and i'm trying my best to understand all the knowlegde i skiped. I think i was able to create a venv inside the folder programing/testing. And i placed a .env file in the token in the programing folder. the bot.py is also inside the programing folder. I don't know if i'm using the wrong interpreter or if i'm running in the wrong place but for some reason i can't make it work.

fleet flameBOT
#

@lyric slate

Python help channel opened

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.

lyric slate
#

Trouble with venv.

dapper chasm
#

okay. and what happens when you do python bot.py from the ~/Programming directory?

lyric slate
#

i'm not sure if you asking me this

dapper chasm
#

yes, that

#

now try python -m pip install discord-py
perhaps you had it installed outside the venv

lyric slate
exotic lava
dapper chasm
#

ugh, right. VS Code doesn't activate the venv in its terminal automatically

#

yeah, you're gonna need to do that

lyric slate
exotic lava
#

What's testing?

lyric slate
exotic lava
#

Oh it's the name of the venv

lyric slate
#

oh i'm sorry guys it's just a mess

exotic lava
#

Like go back to dir Programming then type

source testing/bin/activate
lyric slate
#

how can I @exotic lava . in the terminal i seem to be stuck on the (venv). i tried by using cd.. or cd Programing but i'm stuck.

#

i'm trying to do it in the VScode terminal btw

exotic lava
#

Show the console window

#
cd ~/Programming
``` should work
lyric slate
#

and it did!

exotic lava
#

Anyway it looks like the venv is already activated so run python3 list to see if discord.py was correctly installed

lyric slate
#

should i run it inside of ~/Programing?

exotic lava
#

Oh my bad run pip3 list

lyric slate
#

seems to be

exotic lava
lyric slate
exotic lava
#

Oh right you seem to use another package which you evidently didn't install

lyric slate
#

am i trolling or something? i know there's a file called .env with the token inside.

exotic lava
#

Yes but from dotenv import load_env only works of you installed the dotenv package

lyric slate
#

oh damn... the youtuber must already had installed

exotic lava
#

Go ahead and install it then

lethal oracle
#

stupid question why are you using python3/pip3 inside a venv

exotic lava
#

Also last time I checked discord.py YouTube tutorials are horribly outdated

lethal oracle
#

aren't python3/pip3 usually the systemwide installations in cases where systems still ran python 2 and python 3 alongside each other

lyric slate
lethal oracle
#

if you have a venv you should be able to just use python

exotic lava
#

Noted

lethal oracle
#

and i'm actually suspicious now that you're not doing anything in the venv and doing everything in the user installation

lyric slate
#

oh do you think so?

lethal oracle
#

can you show me the output of pip list (not pip3)

exotic lava
#

I am also not doing anything in Linux, I use Windows
Linux environment things are still foreign to me

exotic lava
#

Oh cool so from now on you can do python bot.py and pip ... whenever you activate your venv

#

Still haven't installed dotenv

lethal oracle
exotic lava
#

You're right πŸ’€

lyric slate
#

it's there but i installed using pip3 no problem right? it1s theere anyway

lethal oracle
#

well python venvs are confusing but it's better to keep project specific dependencies to the venv rather than the system installation, that's why I want to be careful

#

last thing to check, run deactivate, then do pip list again

lyric slate
#

ok

lethal oracle
#

ok seems everything is fine

#

reactivate your venv now

#

by the way usually the venv directory is called .venv so it's easy to tell where it is without guessing what "testing" is

lyric slate
lethal oracle
#

i don't remember if it's ok to just rename it, you might have to recreate the venv for it to work

lyric slate
lethal oracle
#

well hold on then

exotic lava
#

Some scripts are installed with a shebang line with an absolute path so best recreate if you want to rename

lethal oracle
#

the correct process is to have your main dependencies written down somewhere so you could recreate a venv very easily

#

specifically, create a requirements.txt file first where you can write discord.py and whatever else you use with their versions

#

specifically you can run pip freeze and copy the lines of the stuff you use directly

lyric slate
#

so with a pip freezei would have the main dependencies writed down for me? i'm leaning the words still

exotic lava
#

It creates a requirements.txt file with all the packages installed in the environment

lethal oracle
#

no, pip freeze will give you the list of all packages installed and their versions, not all of these are main dependencies, some of them are installed because your dependencies depend on them, you don't need to save them

#

so you have to pick out the stuff you're using directly to copy to the requirements.txt

exotic lava
#

Which I believe are just discord.py and python-dotenv in your case so far

lyric slate
#

yeah yeah i just saw it

#

yo guys thank you very much once again. for your time and care. thank you so much

exotic lava
#

You're welcome

lethal oracle
#

@lyric slate did you create the file?

lyric slate
#

yes i think i did just like u said. i created a requirements.txt file and added the things i installed

#

like this

lethal oracle
#

now if you delete your old venv and create a new one (called .venv), you'll be able to install all the same stuff by running pip install -r requirements.txt

lyric slate
#

oh really? that's awesome!!

#

thank you officer. you guys are just great

lethal oracle
#

that's why these days we hold that venvs should be cattle, not pets - you should be able to delete them and recreate them easily

#

that's why we expect them to be in .venv

lyric slate
#

dude i'm getting beaten down by linux and python bro. but it's just awesome to see how things works.

#

god bless the community for real

fleet flameBOT
#
Python help channel closed for inactivity

This help channel has been closed. 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.