3

Let me preface this by stating that I have read pip installing in global site-packages instead of virtualenv and it did not solve my problem.

When creating a virtual environment using python -m venv venv (or any other name) and then activating said venv using source venv/bin/activate, running pip install [package] actually installs the package to the (user) global python site packages, located in ~/.local/lib/python3.7/site-packages/.

Interestingly, it always tries to install the packages and does not recognize that they are installed globally, meaning it is looking for packages initially in the correct location.

I am running Manjaro Linux, and running the latest updates.

I created this virtual environment in ~/Stuff/tests/venv. Running which pip and which python returns:

(venv) angelin@asgard:~/Stuff/tests/venv $ which pip
/home/angelin/Stuff/tests/venv/bin/pip
(venv) angelin@asgard:~/Stuff/tests/venv $ which python
/home/angelin/Stuff/tests/venv/bin/python

Checking said pip executable shows the correct shebang:

(venv) angelin@asgard:~/Stuff/tests/venv $ cat bin/pip
#!/home/angelin/Stuff/tests/venv/bin/python
# -*- coding: utf-8 -*-
...

My path, when inside the virtualenv, points to the virtual environment first, too:

(venv) angelin@asgard:~/Stuff/tests/venv $ echo $PATH
/home/angelin/Stuff/tests/venv/bin:/home/angelin/.local/bin:...

Manually running python -m pip or venv/bin/python venv/bin/pip produces the same results.
The PYTHONPATH variable is not set.
I have tried reinstalling python and pip using pacman -S python python-pip, but I believe that only reinstalls the global package (located in /usr/bin and I didn't want to mess with the .local install in case I broke something even more than it is.

Any advice is appreciated.

Angelin01
  • 33
  • 5
  • Use the `--prefix` option? – Stop harming Monica Sep 06 '19 at 13:06
  • With which executable? Neither python, pip or the venv module have such option as far as I know (and the --help option shows) – Angelin01 Sep 06 '19 at 13:10
  • https://pip.pypa.io/en/stable/reference/pip_install/#cmdoption-prefix – Stop harming Monica Sep 06 '19 at 13:13
  • @Goyo Using the prefix option gives me an error stating that I can't use it with `--user`, even though I am not passing said argument: ``` (venv) angelin@asgard:~/Stuff/tests $ pip install --prefix=/home/angelin/Stuff/tests/venv/lib/python3.7/ requests ERROR: Can not combine '--user' and '--prefix' as they imply different installation locations ``` Any idea where it could be setting the `--user` option? – Angelin01 Sep 06 '19 at 13:16
  • Try [`pip config [--user|--global|--site] list`](https://pip.pypa.io/en/stable/reference/pip_config/) – phd Sep 06 '19 at 13:19
  • @phd Using it without any optionals returns nothing, using anything else returns an error similar to: `Need exactly one file to operate upon (--user, --venv, --global) to perform.`. Interestingly, it complains that the `--site` option does not exist. – Angelin01 Sep 06 '19 at 13:23

1 Answers1

0

I have a temporary workaround in place.

/etc/pip.conf contained:

[global]
user = true

There was no local pip config file, this was causing it to always pass the --user option. I am not sure how to configure my local file correctly, but I created it and set user = false and will just manually pass the --user option outside of venvs.

This doesn't feel like a proper fix, as it was working normally 2 days ago and the global file hasn't been changed in more than a month. Maybe an update broke something, who knows. If anyone else has a better solution, feel free to share.

Angelin01
  • 33
  • 5