#πŸ”’ VENV IN VSC

130 messages Β· Page 1 of 1 (latest)

supple topazBOT
#

@sacred talon

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.

sacred talon
scarlet blade
# sacred talon

You are on Windows so source wouldn't work here.
You want venv\Scripts\activate.ps1 since you're in Powershell.

sacred talon
#

@scarlet blade that one is in VSC

#

\venv\Scripts\Activate.ps1 cannot be loaded because running
scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1

  • venv\Scripts\activate.ps1
  •   + CategoryInfo          : SecurityError: (:) [], PSSecurityException
      + FullyQualifiedErrorId : UnauthorizedAccess
scarlet blade
sacred talon
#

what about now

scarlet blade
#

I think VSCode might activate the venv for you when you do that but you can always run it just in case.

scarlet blade
# sacred talon

Also, just a word of caution, but you probably don't want to be developing your code within OneDrive, I've seen it cause problems in the past.

scarlet blade
sacred talon
#

same if i do the one you sent me

scarlet blade
sacred talon
#

oye hablo espanol

#

no tengo la N en el teclado jaja

scarlet blade
#

!rule 4 hablo espaΓ±ol pero tenemos que hablar en ingles

supple topazBOT
#

4. Use English to the best of your ability. Be polite if someone speaks English imperfectly.

sacred talon
#

okay

scarlet blade
#

bit odd that it doesn't exist

sacred talon
scarlet blade
sacred talon
#

why ?

scarlet blade
sacred talon
#

whats the cmd to delete that one

#

rm -rf venv ?

scarlet blade
#

the powershell equivalent would be rm -Recurse -Force venv

scarlet blade
#

and then the activate script

sacred talon
scarlet blade
#

you probably don't want it to be in the users folder though, so you should cd into the directory you want to build your project in, and make the venv there

sacred talon
#

what means the command cd?

#

oh yeah

#

that was i was gonna ask lol

#

how to

#

check this lol

#

weird

scarlet blade
# sacred talon

that's because it doesn't exist there.
the C:\Users\...> part at the left is the directory where you're currently in
you can use cd to navigate to directories within it
you can use ls to see the files and directories there

sacred talon
scarlet blade
#

though again I'd probably recommend that you don't develop inside of onedrive and instead make some folder inside your users folder so that you can develop and use projects there

sacred talon
#

i copy and pasted the project into a new folder

#

but seem to show still at onedrive

scarlet blade
#

the thing about OneDrive is that it likes to hide itself by basically moving folders like documents into being part of onedrive

#

so a folder that you would think is in your user folder is actually inside of onedrive

#

in your explorer window, go to %USERPROFILE% and make a new folder there (you could call it anything here but preferably something like projects or anything that's descriptive)

#

then go inside of your new folder, right click, and select the "open in terminal" option (or you could also get into the habit of making folders for each project you're developing and opening the terminal from there)

sacred talon
#

got the terminal, what should i do now?

scarlet blade
#

!venv we went over that earlier. below are those same steps and it also serves as a general overview of venvs

supple topazBOT
#
Virtual environments

Virtual environments are isolated Python environments, which make it easier to keep your system clean and manage dependencies. By default, when activated, only libraries and scripts installed in the virtual environment are accessible, preventing cross-project dependency conflicts, and allowing easy isolation of requirements.

To create a new virtual environment, you can use the standard library venv module: python3 -m venv .venv (replace python3 with python or py on Windows)

Then, to activate the new virtual environment:

Windows (PowerShell): .venv\Scripts\Activate.ps1
or (Command Prompt): .venv\Scripts\activate.bat
MacOS / Linux (Bash): source .venv/bin/activate

Packages can then be installed to the virtual environment using pip, as normal.

For more information, take a read of the documentation. If you run code through your editor, check its documentation on how to make it use your virtual environment. For example, see the VSCode or PyCharm docs.

Tools such as poetry and pipenv can manage the creation of virtual environments as well as project dependencies, making packaging and installing your project easier.

Note: When using PowerShell in Windows, you may need to change the execution policy first. This is only required once per user:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
sacred talon
#

nd now this one?

#

ahh

#

wait

scarlet blade
# sacred talon

you seem to be in cmd now so instead of Activate.ps1 you want activate.bat (i'll assume that you already made the venv).

sacred talon
scarlet blade
# supple topaz

refer to the overview here for the correct activate command, you're in the command prompt so things like ls won't work there

sleek iris
#

in CMD you would use dir instead of ls to list files in a directory

#

and to active your new venv in the .venv directory that you just made, run

.venv\Scripts\activate
sacred talon
#

is it active now?

scarlet blade
#

yep, you can tell by the (.venv) at the start

sacred talon
#

ill try to wait 1s

sacred talon
#

got this one

sleek iris
# sacred talon got this one

it's not something critical, just kind of a warning that you are not running the latest version of pip and some instructions for how you can upgrade to the latest version if you want to, but you don't really have to

sacred talon
sleek iris
# sacred talon i have it but i cant see how to run it its weird

i think i see why now, you probably got the warning when you were running pip outside of your venv (when it wasn't activated)

when you start a new shell you need to activate the venv each time for each shell you launch where you want to be using that venv

#

you can see if you have your vemv active by looking at the start of the prompt, the name of the venv should appear within parenthesis at the very start of the prompt if it's currently activated in that shell

sleek iris
sacred talon
#

but the thing is the error is in a jupyter notebook, so how can i fix that to turn it into the jupyter

sleek iris
sacred talon
#

i got you with all

sleek iris
# sacred talon

sorry, i don't use jupyter a lot, and the little i have used it was within vscode rather then through the web browser and there is didn't have that problem

sleek iris
# sacred talon

but from this screenshot it doesn't look like you are executing jupyter from within the project directly where your venv directly lives, i don't know if that could have something to do with it

sleek iris
# sacred talon

i'm also not used to windows, and especially not powershell, so i'm not sure how things work there with finding the right binary/executable

sacred talon
#

ohh u use linux

#

a lot of people been telling me to switch. i think i have to Lmao

#

but yeah if someone can help me out with the error i would appreciate it

sleek iris
sacred talon
#

still seem that is a little bit harder using python in windows

sleek iris
sleek iris
#

in a new cell in the notebook, run

!where pip
```and see what it responds with
#

it's probably not the path that you are expecting if the venv would be activated 😞

#

@sacred talon πŸ‘†

sleek iris
drifting vale
#

@sleek iris on the topic of venv...

When creating virtual environments, is there any reason I should pip install virtualenv instead of just doing python -m venv myenv ? What would u recommend and why?

Thanks!

sleek iris
#

and when i don't use uv i just use the venv module directly

sacred talon
#

im back

#

@sleek iris u here?

sleek iris
sacred talon
#

where do i make the cell?

sleek iris
sleek iris
sacred talon
#

i do another cell

#

in which order

#

1,2,3?

sleek iris
# sacred talon

make a new cell that above the top cell, the new cell should contain

!python -m ensurepip
```then create yet another new cell just under the last new cell and put
```jupyter
!python -m pip list
```and check that you get a very long list of modules back
then change the beginning of the cell you had on-top so that it starts with
```jupyter
!python -m pip install 
```followed by the modules you want to install
sacred talon
#

seems to work lmao. but does nothing @sleek iris

#

seems to be working nowww !!!

sleek iris
sacred talon
#

well i have one but maybe is off topic lmao

#

do you know any statistics soccer API?

#

my project is based on that

#

if not theres not any problem lmao

sleek iris
sacred talon
#

thank you tho for the help it was really helpful and i could learn

sleek iris
sacred talon
#

love it bro thanks

#

upgrade these 2 guys to moderators lmao @sleek iris @scarlet blade

#

!close

supple topazBOT
#
Python help channel closed with !close

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.