0

I'm trying to install any packages to venv, but the pip install command's target directory is always /opt/homebrew/lib/python3.12/site-packages/, but I'd expect it to be something under venv.

Here is how to replicate in my local machine:

  1. python3.12 -m venv venv to create venv
  2. source venv/bin/activate to load the environment
  3. My which python3.12 and which pip3.12 all points to the correct path, i.e., <repo_directory>/venv/bin/python3.12

Then, when I try pip3.12 install hello-world, it shows:

Collecting hello-world
  Using cached hello_world-0.2-py3-none-any.whl
Installing collected packages: hello-world
Successfully installed hello-world-0.2
WARNING: Target directory /opt/homebrew/lib/python3.12/site-packages/hello.py already exists. Specify --upgrade to force replacement.
WARNING: Target directory /opt/homebrew/lib/python3.12/site-packages/hello_world-0.2.dist-info already exists. Specify --upgrade to force replacement.
WARNING: Target directory /opt/homebrew/lib/python3.12/site-packages/bin already exists. Specify --upgrade to force replacement.

What can I try next?

3
  • 1
    I don't have an explanation for #3, but once the virtual environment is activated, python and pip should be sufficient. Commented Jan 24 at 19:33
  • 2
    Once the venv is active, I would do python -m pip install <package name>. In fact, I only ever use pip this way. Commented Jan 24 at 19:55
  • Anything strange in your environment perhaps? Did you check env | grep PYTHON? Commented Jan 24 at 22:19

1 Answer 1

1

Thanks the comments above for the help! I resolved this issue by asking Deepseek - It is my pip3.12's global config messing up the venv setup. After running

pip3.12 config unset global.target
pip3.12 config unset install.prefix

The installation worked!

Sign up to request clarification or add additional context in comments.

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.