What to do if you can't pipenv shell

Introduction

I am doing Python version control, library management, and virtual environment management with pyenv + pipenv on a mac, but one day when I tried to activate the virtual environment of pipenv, I got the following error and could not activate it. ..

$ pipenv shell
Traceback (most recent call last):
  File "/usr/local/Cellar/pipenv/2018.11.26_4/libexec/bin/pipenv", line 5, in <module>
    from pipenv import cli
ModuleNotFoundError: No module named 'pipenv'

The error is that pipenv cannot be found, but when I go to the directory where pipenv itself is stored, I do not know the cause of this error because it exists normally there. I got this error when I tried to activate the virtual environment in any other directory and realized that pipenv was broken. If you know the cause, it's been a while since you restarted your mac. It's unconfirmed, but maybe it happened after rebooting with some things left in the virtual environment. By the way, a few days ago, my junior also fell into this symptom, and while being supported by a university professor without knowing the cause, I solved it by reinstalling pyenv and pipenv, so I tried it myself and it was cured. I will keep a series of work as a memorandum.

Delete existing environment

First, delete the existing pyenv and pipenv. Here, it is not necessary to delete the Pipfile etc. that manages the library. Leave it ready for immediate rebuilding based on the information contained in the Pipfile. Since this article focuses on rebuilding the virtual environment of pyenv + pipenv, it is assumed that you are using these environments originally and you do not need to change the settings of Pipfile, Pifile.lock, .bash_profile and zshrc. write.

--Check the path of Python you are using --Delete the directory related to pyenv --Remove pyenv --Remove pipenv

$ which python
>>> /Users/xxx/.pyenv/shims/python
$ rm -rf /Users/xxx/.pyenv
$ brew uninstall pyenv
$ brew uninstall pipenv

Reinsert pyenv + pipenv, Python

Now it's time to reinstall the tools.

$ brew install pyenv
$ brew install pipenv

--Install Python by specifying the version you were originally using --Set to use 3.7.5 for the entire mac --Check the Python version (Is it over if it is reflected?)

$ pyenv install 3.6.7
$ pyenv install 3.7.5
$ pyenv global 3.7.5
$ python -V
>>> Python 2.7.10

Since it was not reflected, when I checked which Python I was using, it seems that I am using the mac default Python.

$ which python
>>> /usr/bin/python

Speaking of which, in order to be able to use Python of pyenv with a path specification such as / Users / xxx / .pyenv / shims / python, write the following in `` `.bash_profile``` I remembered what I did. The zsh user is another file.

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

Reflect the above settings again and check which Python you are using again.

$ source .bash_profile
$ which python
>>> /Users/xxx/.pyenv/shims/python

It was confirmed that it supports Python of pyenv normally.

Rebuilding a virtual environment

From here, it is about rebuilding the virtual environment managed by pipenv.

--Move to the directory you originally used and want to rebuild the virtual environment --Create a pipenv environment by specifying the Python version --Activate virtual environment --Batch installation of libraries based on existing Pipfile

cd The directory where you want to create a virtual environment
pipenv --python 3.7.5
pipenv shell
pipenv install

This completes the rebuilding of the virtual environment.

Finally

I searched for the error described at the beginning, including English literature, but I could not find a person with the same symptom, and the cause is still unknown, but there is symptomatic treatment, so do not panic and deal with it calmly.

Referenced articles

Reinstalled pipenv and pyenv Erase pyenv properly and then put it back in

Recommended Posts

What to do if you can't pipenv shell
What to do if you can't pip install mysqlclient
What to do if you can't sort files with subscripts
What to do if you can't log in as root
What to do if you can't use WiFi on Linux
What to do if you can't install pyaudio with pip #Python
What to do if you can't build your project with Maven
What to do if you can't use the trash in Lubuntu 18.04.
What to do if you can't find well with grep's -f option
What to do if you can't find PDO in Laravel or CakePHP
What to do if you can't use scikit grid search in Python
What to do if you can't install with pip in babun environment
No module named What to do if you get'libs.resources'
ModuleNotFoundError: No module What to do if you get'tensorflow.contrib'
pipenv shell is no longer available ... what to do?
What to do when you can't bind CaboCha to Python
What to do if you get a "No versions found" error in pipenv
What to do if yum breaks
What to do if you are addicted to Windows character code
What to do if you get "coverage unknown" in Coveralls
What to do if you lose your EC2 key pair
How to install and use pyenv, what to do if you can't switch python versions
What to do if you can't hit the arrow keys in the Python interactive console
Let's summarize what you want to do.
What to do if you get a minus zero in Python
What to do if you get a UnicodeDecodeError with pip install
What to do when you get "I can't see the site !!!!"
What to do if pipreqs results in UnicodeDecodeError
What to do if the Pipenv environment is corrupted by updating Homebrew
CommandNotFoundError: Your shell has not been properly configured to use What to do if you get'conda activate'
What to do if you couldn't send an email to Yahoo with Python.
Note: What to do if pip install fails
What to do if mod_fcgid cannot resolve UnicodeEncodeError
What to do if you forget your login password on Manjaro Linux
What to do if rails s doesn't work
What to do if you get lost in file reference with FileNotFoundError
What to do if you get angry in TensorFlow v2 without attribute'app'
What to do if you get stuck during Anaconda installation on Linux
What to do if you get a TypeError with numpy min, max
What to do if you get an error when trying to load mnist
What to do if pip cannot be installed
What to do if atom autocomplete-python doesn't work
What to do if you get Could not fetch URL 443 with pip
What to do if Docker-sync suddenly stops working
What to do if you get an error when installing Dlib (Ubuntu)
What to do if "amazon-linux-extras" → "No module named amazon_linux_extras"
What to do if you get angry with swapon failed: Operation not permitted
What to do if Django can't load an image from a static folder
What to do if you get an error when installing python with pyenv
What to do if you get "Python not configured." Using PyDev in Eclipse
UnicodeDecodeError: What to do when'shift_jis' codec can't decode byte
What to do if SciPy installation fails on CentOS
Links to do what you want with Sublime Text
What to do if a UnicodeDecodeError occurs in pip
What you can't do with hstack or vstack with dstack
What to do if pip install fails to install dependent libraries
What to do if sys / cdefs.h does not exist
What to do if pyenv is not enabled (zsh)
What to do if you get an "unknown service" error from your gRPC server
What to do if you get an OpenSSL error when installing Python 2 with pyenv
What to do if the Microsoft Store opens even if you run python on Windows