Pipenv: Issues running pipenv & pyenv

Created on 1 Sep 2017  ·  30Comments  ·  Source: pypa/pipenv

I am unable do activate virtualenv using pipenv shell with python managed by pyenv.

Here is the output of my terminal:

roger@ohm:/tmp/lab $ pipenv --venv
No virtualenv has been created for this project yet!
roger@ohm:/tmp/lab $ pipenv install requests
Creating a Pipfile for this project...
Creating a virtualenv for this project...
⠋Using base prefix '/home/roger/.pyenv/versions/3.6.1'
New python executable in /home/roger/.local/share/virtualenvs/lab-O8QxVB32/bin/python3.6
Also creating executable in /home/roger/.local/share/virtualenvs/lab-O8QxVB32/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /home/roger/.local/share/virtualenvs/lab-O8QxVB32
Installing requests...
Collecting requests
  Using cached requests-2.18.4-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests)
  Using cached urllib3-1.22-py2.py3-none-any.whl
Collecting idna<2.7,>=2.5 (from requests)
  Using cached idna-2.6-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests)
  Using cached certifi-2017.7.27.1-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests)
  Using cached chardet-3.0.4-py2.py3-none-any.whl
Installing collected packages: urllib3, idna, certifi, chardet, requests
Successfully installed certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22

Adding requests to Pipfile's [packages]...
P.S. You have excellent taste! ✨ 🍰 ✨
roger@ohm:/tmp/lab $ pipenv shell
ERROR: The virtualenv hasn't been activated correctly.
Either the env is corrupted (try running `pew restore env`),
Or an upgrade of your Python version broke your env,
Or check the contents of your $PATH. You might be adding new directories to it
from inside your shell's configuration file.
In this case, for further details please see: https://github.com/berdario/pew#the-environment-doesnt-seem-to-be-activated

I followed the steps of the URL above, changing PATH order, but no sucess.

Most helpful comment

pyenv does some weird things, and isn't recommended.

What weird things are you referring to? I've used pyenv for years and have never had problems with pip, virtualenv, or any other packages I've installed.

How else do people manage the installation and selection of multiple Python versions? I think the usage of pyenv is more common than you let on. 😄

All 30 comments

roger@ohm:/tmp/lab $ pew restore env
Running virtualenv with interpreter /usr/bin/env
/usr/bin/env: /home/roger/.pyenv/versions/3.6.1/lib/python3.6/site-packages/virtualenv.py: Permission denied

pyenv does some weird things, and isn't recommended.

Let's see if we can fix it, though. @berdario, do you have any thoughts on this? I believe it's related to pyenv's shimming.

Hmm, so I think this is an environment issue @rdemetrescu. I've used pyenv since the beginning of the project without issue. It looks like there may be permission issues on the directories that .pyenv is creating on your machine? Something is getting in the way of pew workon.

pyenv does some weird things, and isn't recommended.

What weird things are you referring to? I've used pyenv for years and have never had problems with pip, virtualenv, or any other packages I've installed.

How else do people manage the installation and selection of multiple Python versions? I think the usage of pyenv is more common than you let on. 😄

@jacebrowning I may be getting pyenv confused with pythonz :)

FTR some weird things do happen with pyenv, the main problem being the shims. Sometimes the path look up fails when pointed to shims, and I need to manually pass the “real” executable path) to some certain build scripts. Sometimes the shims themselves cause problems with feature checks (because which xxx and type xxx would return 0). I still use it because the overall benefits still outweigh edge case failures, but problems do exist.

Okay, that's what I thought.

I don't like the shims, which is why I don't use it.

I'm going to make a homebrew tap for all versions of Python.

@nateprewitt I did a fresh install of pyenv on my machine.

➜ pipenv install requests
Creating a Pipfile for this project...
Creating a virtualenv for this project...
⠋Using base prefix '/home/roger/.pyenv/versions/3.6.2'
New python executable in /home/roger/.local/share/virtualenvs/lab-O8QxVB32/bin/python3.6
Also creating executable in /home/roger/.local/share/virtualenvs/lab-O8QxVB32/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /home/roger/.local/share/virtualenvs/lab-O8QxVB32
Installing requests...
Collecting requests
  Using cached requests-2.18.4-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests)
  Using cached urllib3-1.22-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests)
  Using cached chardet-3.0.4-py2.py3-none-any.whl
Collecting idna<2.7,>=2.5 (from requests)
  Using cached idna-2.6-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests)
  Using cached certifi-2017.7.27.1-py2.py3-none-any.whl
Installing collected packages: urllib3, chardet, idna, certifi, requests
Successfully installed certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22

Adding requests to Pipfile's [packages]...
P.S. You have excellent taste! ✨ 🍰 ✨
➜ pipenv shell
ERROR: The virtualenv hasn't been activated correctly.
Either the env is corrupted (try running `pew restore env`),
Or an upgrade of your Python version broke your env,
Or check the contents of your $PATH. You might be adding new directories to it
from inside your shell's configuration file.
In this case, for further details please see: https://github.com/berdario/pew#the-environment-doesnt-seem-to-be-activated



md5-d98567298b1e26445f4bf7d8d6b4d6c8



➜ pew restore env
Running virtualenv with interpreter /home/roger/.pyenv/versions/3.6.2/bin/python
Using base prefix '/home/roger/.pyenv/versions/3.6.2'
New python executable in /home/roger/.local/share/virtualenvs/env/bin/python
Installing setuptools, pip, wheel...done.



md5-3f3481661e76ce0a825d897e544e1e6d



➜ pipenv shell   
ERROR: The virtualenv hasn't been activated correctly.
Either the env is corrupted (try running `pew restore env`),
Or an upgrade of your Python version broke your env,
Or check the contents of your $PATH. You might be adding new directories to it
from inside your shell's configuration file.
In this case, for further details please see: https://github.com/berdario/pew#the-environment-doesnt-seem-to-be-activated

i think you have a shell configuration problem.

We have a fix in master that should solve this, maybe. let me release it.

i want to test on windows first. try running off of master and let me know how it goes! closing in the meantime

Thanks @kennethreitz . I upgraded to pipenv, version 5.3.5 but still no sucess here.

My environment is:

Ubuntu 15.10 (x86_64)
bash version: 4.3.42(1)-release
zsh version: zsh 5.1.1

Regarding pyenv, that's what I have on both .bashrc and .zshenv :

# .bashrc
export PATH="~/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
# .zshenv
PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"

I will try to test it on a virtual machine, later.

you might want to try the changes i have landed in the master branch

Hi @kennethreitz , here is the new output:

➜ pipenv shell
{'code': <code object <module> at 0x7fbbeb4a6540, file "/home/roger/.local/share/virtualenvs/lab-O8QxVB32/bin/activate_this.py", line 6>, 'f': <_io.TextIOWrapper name='/home/roger/.local/share/virtualenvs/lab-O8QxVB32/bin/activate_this.py' mode='r' encoding='UTF-8'>, 'activate_this': '/home/roger/.local/share/virtualenvs/lab-O8QxVB32/bin/activate_this.py', 'shell_args': (), 'compat': False, 'python': False, 'three': None}
ERROR: The virtualenv hasn't been activated correctly.
Either the env is corrupted (try running `pew restore env`),
Or an upgrade of your Python version broke your env,
Or check the contents of your $PATH. You might be adding new directories to it
from inside your shell's configuration file.
In this case, for further details please see: https://github.com/berdario/pew#the-environment-doesnt-seem-to-be-activated

So, I discovered my .zprofile isn't sourced at all at my Ubuntu installation.
I changed my .zshenv to do all pyenv stuff within a sentinel.

if [ -z $PYENV_ROOT ]; then
    export PYENV_ROOT="$HOME/.pyenv"
    export PATH="$PYENV_ROOT/bin:$PATH"
    eval "$(pyenv init -)"
fi

Everything is running fine now. I am able to do a pipenv shell.

✨🍰✨

For the record, there's also $ pipenv run -c, which runs in "compatibility mode" for less-well-configured shells.

Amazing! I reverted my changes in .zshenv and tested pipenv shell -c.
It worked like a charm.

I'm going to make a homebrew tap for all versions of Python.

@kennethreitz still planning on doing this? I'm increasingly finding pyenv shims to not be great.

@AlJohri this was done the same day he said made the comment 👍 https://github.com/kennethreitz/homebrew-pythons

Awesome :)

sticking with pyenv :)

Hey guys, any timeframe on supporting 3.6.3?

I'm a newbie and got this warning when trying to push a heroku build:

The latest version of Python 3 is python-3.6.2 (you are using python-3.6.3, which is unsupported).

Will figure out how to get pyenv to make everything happy on 3.6.2 for now but still curious. Thanks!

@jaellis this isn't a pipenv issue, its an issue with the heroku python buildpack. submitted PR here: https://github.com/heroku/heroku-buildpack-python/pull/483
cc @kennethreitz

Thanks so much!

OK,
So. Whats is the best way to use pyenv and pipenv together
OR How does one manage multiple versions on python in tandem with pipenv
?
Is it just:

pyenv install 3.69.0
pyenv global 3.69.0
pip install pipenv
pipenv etc..

?

@awhillas What are you trying to do? If you specify python_version = <version installed with pyenv> in the [requires] section of your Pipfile it should _just work_.

so I can install pipenv with the system python, create a new project with it and then just make that change in the Pipfile and it will work... like magic...?

Just install Pipenv anywhere (as long as you can run it), and yes, it would just work. You don’t even need to add the shim directory to PATH or pyenv global anything (basically you don’t need the shims). All you need to set is the PYENV_ROOT environment variable.

@jacebrowning please look into this issue of mine

Was this page helpful?
0 / 5 - 0 ratings