pyenv-virtualenv icon indicating copy to clipboard operation
pyenv-virtualenv copied to clipboard

Pyenv virtualenv does not shim pip - uses shimmed python, system pip

Open alrhalford opened this issue 6 years ago • 6 comments

I have been using (Homebrew) pyenv and pyenv-virtualenv for a long time, and my usual procedure for creating a virtual environment (with 3.7.4, for example) is:

pyenv install 3.7.4
pyenv virtualenv 3.7.4 foo
pyenv activate foo

This works fine, and running which python gives: /Users/bar/.pyenv/shims/python And python --version gives: Python 3.7.4 as expected.

However, doing the same for pip gives: /usr/local/bin/pip i.e., the system pip. This also means that pip installing anything installs it to the system python, not to the virtualenv (packages are not subsequently available in the virtualenv, e.g. pip install django, followed by running a python django app, complains that there is no django installed)

This suggests that there is no shim for pip, which is weird, because this has always worked for me in the past. I have tried uninstalling both pyenv and pyenv-virtualenv, deleting .pyenv, and reinstalling them, but it made no difference.

I have tried running pyenv rehash

alrhalford avatar Sep 04 '19 01:09 alrhalford

I'm having the same problem. Any updates on this issue?

Only thing I can add at this stage is that I have 3 computers, all running Arch Linux (Endeavour OS). I've installed pyenv on all 3 using the pyenv-installer project (https://github.com/pyenv/pyenv-installer). Everything works perfectly on 2 our of the 3, but this problem occurs on one of the machines. Makes me think it might be either a transient dependency or hardware issue..?

I've also noticed that the 'site-packages' folder ie. lib/python3.6/site-packages in the created virtual environment is empty for the broken instance, but populated for the working ones.

jameslombard avatar May 28 '20 06:05 jameslombard

Also, when I work straight from the installed version for the virtualenv, ie 3.6.0, the pyenv which pip command gives the expected output: /home/james/.pyenv/versions/3.6.0/bin/pip But when I try to inspect the dependencies ie. pip freeze, I get the following error:

  File "/home/james/.pyenv/versions/3.6.0/bin/pip", line 11, in <module>
    sys.exit(main())
  File "/home/james/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pip/__init__.py", line 233, in main
    return command.main(cmd_args)
  File "/home/james/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pip/basecommand.py", line 251, in main
    timeout=min(5, options.timeout)) as session:
  File "/home/james/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pip/basecommand.py", line 72, in _build_session
    insecure_hosts=options.trusted_hosts,
  File "/home/james/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pip/download.py", line 329, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/home/james/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pip/download.py", line 93, in user_agent
    from pip._vendor import distro
  File "/home/james/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pip/_vendor/distro.py", line 1050, in <module>
    _distro = LinuxDistribution()
  File "/home/james/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pip/_vendor/distro.py", line 595, in __init__
    self._distro_release_info = self._get_distro_release_info()
  File "/home/james/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pip/_vendor/distro.py", line 995, in _get_distro_release_info
    distro_info = self._parse_distro_release_file(filepath)
  File "/home/james/.pyenv/versions/3.6.0/lib/python3.6/site-packages/pip/_vendor/distro.py", line 1018, in _parse_distro_release_file
    return self._parse_distro_release_content(fp.readline())
  File "/home/james/.pyenv/versions/3.6.0/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 51: ordinal not in range(128)```

jameslombard avatar May 28 '20 06:05 jameslombard

I also have this problem resulting in pip trying to install to a read-only system location ERROR: Could not install packages due to an EnvironmentError: [Errno 30] Read-only file system:

Chrismarsh avatar Oct 05 '20 22:10 Chrismarsh

Oh interesting, this seems to be related to having pyenv-which-ext installed. Without it, the pip shims are created, otherwise it seems to default to system pip.

Chrismarsh avatar Oct 05 '20 23:10 Chrismarsh

Maybe check the init script: eval "$(pyenv init --path)", the --path seems new added in pyenv README.

guyskk avatar Nov 12 '21 15:11 guyskk

Agreed that --path has perhaps cleaned up some of my issues (so far).

Chrismarsh avatar Nov 16 '21 15:11 Chrismarsh