#๐Ÿ”’ How to use venv with jupyter?

67 messages ยท Page 1 of 1 (latest)

errant hedge
#

As you can see on the left of the screen, i have a python venv, but i can't get the jupyter notebook to select that venv. What can I do? The kernel button on the top-right (where it says "Python 3.12.7") doesn't detect it either

shadow parrotBOT
#

@errant hedge

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.

west jasper
#

when you click on the button in the top-right, what happens?

errant hedge
west jasper
#

๐Ÿค”

#

I chose the top option (I forget what it was), then it gave me the chance to choose an existing virtualenv, and the relevant one was at the top

errant hedge
#

if it just allowed me to place a certain one, it would be doable

#

maybe it has to do with how i created the env? with the terminal command?

west jasper
#

why not choose the one that it shows as "Recommended"?

#

That's what I did, and it worked fine

errant hedge
#

id rather not use a global one, and instead have a venv for each project... At least that's what out teacher told us is best

west jasper
#

but

errant hedge
#

and the recommended one doesnt even exist lol

west jasper
#

if you choose the recommend one you will not be using "a global one"

#

what happens when you click that line anyway?

errant hedge
#

it selects the kernel, but when i try any cells it says that "it failed to start as the environment isn't available"

west jasper
#

๐Ÿค”

errant hedge
#

but thats okay

#

lemme jsut restart the notebook

#

now there isnt even a recommended one xD

west jasper
#

so, I've created an empty folder. I copied some random notebook into it. I "pointed" VSC at that notebook, and now I see this

#

which seems reasonable.

errant hedge
#

thsi is what appears for me

west jasper
#

Yeah "Create Python Environemnt" sounds like the right choice

errant hedge
#

so i must use the env it forces me to...

west jasper
#

๐ŸŽ‰

west jasper
#

when you choose "Create Python Environment", it ... creates a virtual environment, and then uses that.

#

which is a good thing.

errant hedge
#

yeah

#

but then i cant move that one around? I dont want it to stay where it did, although when i move it around it says it no longer exists

west jasper
#

yeah you shouldn't move virtualenvs around. But why do you want to? Just create it where you actually want it.

#

[I'm not sure that you can't move virtualenvs around; I've just never done it]

errant hedge
#

this does work:

#

but it didnt when i had the big folder opened

west jasper
#

big folder?

#

no idea what that means

#

when I did it, it created the virtualenv exactly where I'd expect: in the folder that I had open in vsc (which was the folder with the notebook in it)

errant hedge
#

sorry im not explaining myself that well. I mean the folder containing the folder that has the notebook

errant hedge
west jasper
#

I'm so confused

#

here's what you should do

  • figure out where you want the venv
  • get the notebook, and whatever else you want, into that folder
  • open vsc in that folder
  • have vsc create the venv there
errant hedge
#

yeah me too... Ignoring that, now with the .venv working somewhat properly, it says that i cant pip install cause "externally-managed-environment"

west jasper
errant hedge
west jasper
#

ok well that's normal

errant hedge
#

is that aproblem?

west jasper
#

that's a sign that you're not using a virtualenv

errant hedge
#

but... it says its using one?

west jasper
#

I didn't know VSC ran on ubuntu though

errant hedge
west jasper
#

your images aren't showing up ๐Ÿ˜

errant hedge
#

oh

west jasper
#

just piles of poo ๐Ÿ™‚

errant hedge
#

sorry

#

like that?

west jasper
#

I'd type type -a pip at that terminal

#

the presence of (.venv) in the prompt isn't a guarantee that everything is properly set up (although it'd have fooled me, too)

#
:-) 2025-02-13T12:29:39-0800 [x]$ source .venv/bin/activate
(.venv) :-) 2025-02-13T12:29:44-0800 [x]$ type -a pip
pip is /private/var/folders/b0/_p0c_57s5n90cy4njdgd8vhw0000gq/T/x/.venv/bin/pip
#

that output is correct

errant hedge
#

ill try it after dinner, thank you

shadow parrotBOT
#
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.