1

I'm trying to find a simple one-line instruction to create a new project and environment using uv so that I can work up python scripts using VS Code's interactive window. This is in Mac OS.

uv init project_name && cd project_name && uv venv

I then activate the environment using:

source .venv/bin/activate

I then create a simple test file in VS Code, say test.py:

# %%
#The code above is to start up interactive window
import pandas as pd

print("Pandas version:", pd.__version__)

I'm expecting an error because I think I've created a new clean environment. But before that I get an error to say I've not installed ipykernel. Fine. I expect that.

uv add ipykernel

And that works.

But no matter whether I change the interpreter I still get that message:

enter image description here

More puzzling is the fact that I was expecting the one-liner to only be able to access a couple of modules in the new environment.

Yet if I try:

pip list

I see modules outside of that environment scope. What have I got wrong with uv?

0

2 Answers 2

1

As you're using uv, I think you would want to run uv pip list instead, to list all the packages in the environment. pip list is likely listing all globally installed packages.

Also, uv init already creates a venv, so I don't think running uv venv is required in your one-liner. Activating the environment is also likely unnecessary, as uv takes care of that.

It seems like you want to use Jupyter Notebook. In VSCode, when running your notebook, make sure to select the venv created by uv.

The uv docs have some explanation on how to work with Jupyter Notebook and uv, I think that will help a lot.

Finally, I think your one-liner will be something like

uv init project_name && cd project_name && uv add --dev ipykernel && code .
Sign up to request clarification or add additional context in comments.

1 Comment

Since there is a mention of Jupyter Notebook, I'll add along the lines of uv pip list being what is wanted and not just pip list, you'd ideally use explicitly in a Jupyter notebook cell %pip list to see what the active kernel can see for pip. The magic version is important because it ensures you see what is the scope of the kernel. See more about the modern %pip install command added in 2019 here.
0

Virtual environments created by uv does not have pip installed by default.

Use uv venv --seed to create an environment with pip, setuptools and wheel (note that they may be uninstalled on synchronization). To add pip as a dependency, use uv add pip or uv add --dev pip.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.