Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyenv, pip and virtual environment #5

Open
jiansoung opened this issue Oct 10, 2018 · 0 comments
Open

pyenv, pip and virtual environment #5

jiansoung opened this issue Oct 10, 2018 · 0 comments
Labels

Comments

@jiansoung
Copy link
Owner

pyenv, pip and virtual environment

Notes on The Hitchhiker’s Guide to Python

pyenv and how does it work ?

pyenv is a tool to allow multiple versions of the Python interpreter to be installed at the same time.

pyenv works by filling a shims directory with fake versions of the Python interpreter (plus other tools like pip and 2to3). When the system looks for a program named python, it looks inside the shims directory first, and uses the fake version, which in turn passes the command on to pyenv. pyenv then works out which version of Python should be run based on environment variables, .python-version files, and the global default.

pip and virtual environment

In order to make sure that you install packages to your active virtual environment when you use pip install, consider adding the following lines to your ~/.bashrc (or ~/.zshrc) file:

export PIP_REQUIRE_VIRTUALENV=true

gpip() {
    PIP_REQUIRE_VIRTUALENV="" pip "$@"
} 

After saving this change and sourcing the ~/.bashrc file (or ~/.zshrc) with source ~/.bashrc (or source ~/.zshrc), pip will no longer let you install packages if you are not in a virtual environment. (But you can use gpip install packages globally. )

You can also do this configuration by editing your pip.conf or pip.ini file.

References

  1. The Hitchhiker’s Guide to Python!
  2. https://docs.python-guide.org/dev/pip-virtualenv/#requiring-an-active-virtual-environment-for-pip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant