Using Python 3 in virtualenv
To use Python 3 inside a virtualenv, run the following:
This creates and starts a Python 3 virtual environment named env
tailored for your project's dependency isolation.
If you have Python 3.6 or newer, venv
is already included out of the box:
If you get compatibility issues, upgrade virtualenv
like so:
You can deep dive into specific issues related to virtualenv
like #463.
Setting up like a Python Pro
Handling Python versions with pyenv
When dealing with multiple Python versions, supplement pyenv-virtualenv
with pyenv
for better navigation:
To activate:
To ensure you're using the intended Python version, do a quick check:
Streamlining with virtualenvwrapper
To enhance your workflow, use virtualenvwrapper
, essentially the Swiss Army knife of virtual environments:
- Make a new virtualenv with:
- Visit an existing virtual environment:
Utilizing system-wide packages
Occasionally, you might need those system packages. Here's what you do when setting up the virtualenv:
Always check for compatability and performance issues, because not everyone plays nice together.
Tackling compatibility issues on macOS
For macOS users, go with venv
to avoid compatibility issues:
If you encounter problems, raise an issue on virtualenv's GitHub repository because sharing is caring.
Keeping global packages on call
For packages you often use, give them a global pass and use them in multiple virtual environments. Just be discerning with project-specific dependencies.
Was this article helpful?