-
-
Save Murgio/c39b25e74119d3be4f5c83711c1f3039 to your computer and use it in GitHub Desktop.
Revisions
-
wronk revised this gist
Apr 13, 2020 . 1 changed file with 10 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,9 +23,7 @@ For comparison to Anaconda, see [note below](#other-notes) **Installation/use**: From, [pyenv's install instructions](https://github.com/pyenv/pyenv#homebrew-on-macos), `brew install pyenv` on Mac. See the docs for installation via `git clone` on other other systems. Then you can list and install new Python versions like: ``` pyenv install 3.7.7 # Install Python version pyenv install 3.6.3 @@ -36,7 +34,7 @@ For comparison to Anaconda, see [note below](#other-notes) Also install [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv) like `brew install pyenv-virtualenv`, which we'll need later. **Technical details**: When you execute a Python script or use pip, pyenv intercepts that command and sends it to the Python environment that is activated. It does this using shims on the `PATH` environment variable, which allow Python-related commands to be dynamically rerouted. We'll set the `PATH` shims later in this guide. 2. Confirm python version Make sure you have an up to date version of python **at the system level** (and not from pyenv). You can check and fix (if required) using the below code. @@ -72,8 +70,15 @@ For comparison to Anaconda, see [note below](#other-notes) # Tell pyenv-virtualenvwrapper to use pyenv when creating new Python environments export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true" # Set the pyenv shims to initialize if command -v pyenv 1>/dev/null 2>&1; then eval "$(pyenv init -)" fi ``` Make sure that the directory you define for `WORKON_HOME` actually exists (or use `mkdir ~/.virtualenvs`), and then restart your terminal. See [Troubleshooting](https://gist.github.com/wronk/a902185f5f8ed018263d828e1027009b#troubleshooting) if your system has issues finding `virtualenvwrapper.sh`. Full virtualenvwrapper [installation instructions here](https://virtualenvwrapper.readthedocs.io/en/latest/index.html#introduction). ## Using the workflow -
wronk revised this gist
Apr 13, 2020 . No changes.There are no files selected for viewing
-
wronk revised this gist
Apr 13, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,7 +39,7 @@ For comparison to Anaconda, see [note below](#other-notes) **Technical details**: When you execute a Python script or use pip, pyenv intercepts that command and sends it to the Python environment that is activated. It does this using shims on the `PATH` environment variable, which allow Python-related commands to be dynamically rerouted. 2. Confirm python version Make sure you have an up to date version of python **at the system level** (and not from pyenv). You can check and fix (if required) using the below code. ``` python --version # Should be a python 3 version -
wronk revised this gist
Apr 13, 2020 . 1 changed file with 19 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,14 +30,30 @@ For comparison to Anaconda, see [note below](#other-notes) pyenv install 3.7.7 # Install Python version pyenv install 3.6.3 pyenv versions # List Python versions # Later, we will switch version with something like `pyenv global 3.7.3`, but don't do this yet ``` Also install [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv) like `brew install pyenv-virtualenv`, which we'll need later. **Technical details**: When you execute a Python script or use pip, pyenv intercepts that command and sends it to the Python environment that is activated. It does this using shims on the `PATH` environment variable, which allow Python-related commands to be dynamically rerouted. 2. Confirm python version Make sure you have an up to date version of python **at the system level** (and not from pyenv). You can check and fix (if required) using the below code. ``` python --version # Should be a python 3 version # If the above gives python 2 and not python 3: brew install python brew info python # See where the unversioned symlinks live. Likely `/usr/local/opt/python/libexec/bin` # Update your PATH so the unversioned python/pip aliases are used. Run the below line to accomplish this. # Update the command if the unversioned symlinks live in a different location or if you use .bashrc/.profile # instead of a ~/.zshrc echo 'export PATH=/usr/local/opt/python/libexec/bin:$PATH' >> ~/.zshrc 3. **[virtualenv](https://virtualenv.pypa.io/en/stable/)**: Short for "virtual environment." This tool allows manages separate directories for each environment so you can install modules (e.g., with `pip`) to each environment individually. **Installation**: `pip install virtualenv` in your terminal @@ -46,7 +62,7 @@ For comparison to Anaconda, see [note below](#other-notes) **Technical details**: `virtualenv` keeps each environment (and its installed modules) in separate folders; therefore, each is like a silo that doesn't interact with any other virtual environment. By default, the exact file location is defined by the user, but we will use virtualenvwrapper to manage these locations for us. 4. **[virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/en/latest/)**. This helps `pyenv` and `virtualenv` gel like PB&J. With it, you witch between environments using a single command (where each environment has it's own version of Python and own installed modules). **Installation**: `pip install virtualenvwrapper` and then `brew install pyenv-virtualenvwrapper` to extend pyenv. Then you'll need to do some one-time setup; in your .zshrc/.bashrc/.bash_profile, add the following: ``` -
wronk revised this gist
Mar 26, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ ## Overview of Python Virtual Environments *This guide is targetted at intermediate or expert users who want low-level control over their Python environments.* When you're working on multiple coding projects, you might want a couple different version of Python and/or modules installed. This helps keep each workflow in its own sandbox instead of trying to juggle multiple projects (each with different dependencies) on your system's version of Python. The guide here covers one way to handle multiple Python versions and Python environments on your own (i.e., without a package manager like `conda`). See the [Using the workflow](https://gist.github.com/wronk/a902185f5f8ed018263d828e1027009b#using-the-workflow) section to view the end result. <p align="center"> <img width="350" src="https://imgs.xkcd.com/comics/python_environment_2x.png"> -
wronk revised this gist
Mar 26, 2020 . 1 changed file with 19 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ ## Overview of Python Virtual Environments *This guide is targetted at intermediate or expert users on Linux or OSX.* When you're working on multiple coding projects, you might want a couple different version of Python and/or modules installed. This helps keep each project in its own sandbox instead of trying to juggle multiple projects (each with different dependencies) on your system's version of Python. The guide here covers one way to handle multiple Python versions and Python environments on your own (i.e., without a package manager like `conda`). See the [Using the workflow](https://gist.github.com/wronk/a902185f5f8ed018263d828e1027009b#using-the-workflow) section to view the end result. <p align="center"> <img width="350" src="https://imgs.xkcd.com/comics/python_environment_2x.png"> @@ -9,16 +10,16 @@ When you're working on multiple coding projects, you might want a couple differe </p> ### Use cases 1. Working on 2+ python projects that each have their own dependencies; e.g., a Python 3.6 project and a Python 3.8 project, or developing/testing a module that needs to work across multiple versions of Python. It's not reasonable to uninstall/reinstall Python modules every time you want to switch projects. 2. If you want to execute code on the cloud, you can set up a Python environment that mirrors the relevant cloud instance. For example, your favorite Amazon EC2 deep learning instance may run Python 3.6, and you could hit obstacles if you developed locally with Python 3.8. 3. You might have some working Python code and want to make sure everything stays frozen so that it'll still work in the future. Without virtual environments, upgrading Python modules could unintentionally break that year-old project. Going back to determine the correct version for each dependency would be a huge pain. This guide shows how to solve these issues with pyenv and virtualenv (along with virtualenvwrapper). It illustrates how to obtain lower-level control of your development environment (compared to Anaconda/`conda`, for example). It's tedious to setup, but very easy exert a high level of control on your Python environments after that. This is intended for MacOS, but all the tools work on Unix-like systems -- you'll just have to make use of `apt-get` instead of `brew` and detour through the original installation guides in some spots. For comparison to Anaconda, see [note below](#other-notes) ## Instructions 1. **[pyenv](https://github.com/pyenv/pyenv)**: Short for "Python environment." Pyenv manages which version of Python is visible to your computer (and temporarily hides other versions). With pyenv, you can install multiple versions of Python and quickly switch between the "activated" version (i.e., the version your computer will use to execute code). **Installation/use**: From, [pyenv's install instructions](https://github.com/pyenv/pyenv#homebrew-on-macos), `brew install pyenv` on Mac. See the docs for installation via `git clone` on other other systems. @@ -34,18 +35,18 @@ For comparison to Anaconda, see [note below](#other-notes) Also install [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv) like `brew install pyenv-virtualenv`, which we'll need later. **Technical details**: When you execute a Python script or use pip, pyenv intercepts that command and sends it to the Python environment that is activated. It does this using shims on the `PATH` environment variable, which allow Python-related commands to be dynamically rerouted. 2. **[virtualenv](https://virtualenv.pypa.io/en/stable/)**: Short for "virtual environment." This tool allows manages separate directories for each environment so you can install modules (e.g., with `pip`) to each environment individually. **Installation**: `pip install virtualenv` in your terminal **Use:** It's possible to use virtualenv directly as ([as described here](https://virtualenv.pypa.io/en/stable/userguide/)), but we'll use virtualenvwrapper instead. **Technical details**: `virtualenv` keeps each environment (and its installed modules) in separate folders; therefore, each is like a silo that doesn't interact with any other virtual environment. By default, the exact file location is defined by the user, but we will use virtualenvwrapper to manage these locations for us. 3. **[virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/en/latest/)**. This helps `pyenv` and `virtualenv` gel like PB&J. With it, you witch between environments using a single command (where each environment has it's own version of Python and own installed modules). **Installation**: `pip install virtualenvwrapper` and then `brew install pyenv-virtualenvwrapper` to extend pyenv. Then you'll need to do some one-time setup; in your .zshrc/.bashrc/.bash_profile, add the following: ``` @@ -56,22 +57,22 @@ For comparison to Anaconda, see [note below](#other-notes) # Tell pyenv-virtualenvwrapper to use pyenv when creating new Python environments export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true" ``` Make sure that the directory you define for `WORKON_HOME` actually exists (or use `mkdir ~/.virtualenvs`), and either restart your terminal or source the relevant configuration (i.e., `source ~/.zshrc`, `source ~/.bashrc`, `source ~/.bash_profile`). See [Troubleshooting](https://gist.github.com/wronk/a902185f5f8ed018263d828e1027009b#troubleshooting) if your system has issues finding `virtualenvwrapper.sh`. Full virtualenvwrapper [installation instructions here](https://virtualenvwrapper.readthedocs.io/en/latest/index.html#introduction). ## Using the workflow We're all ready to use this in the terminal! As shown below, we'll first set the Python environment with `pyenv`, and then make a couple virtual environments with `virtualenvwrapper`. Then we'll use the `workon` command to switch between them. ``` pyenv global 3.6.3 # Set your system's Python version with pyenv mkvirtualenv my_legacy_proj # Create a new virtual environment using virtualenvwrapper; it'll be tied to Python 3.6.3 pip install numpy scipy # Install the packages you want in this environment pyenv global 3.8.2 # Set your system's Python version with pyenv mkvirtualenv new_web_proj # Create and switch to a new virtual environment with a newer version of python pip install flask boto workon # List the environments available workon my_legacy_proj # Use virtualenvwrapper to switch back to the original project ``` ## Troubleshooting -
wronk revised this gist
Mar 26, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -84,7 +84,7 @@ workon my_project_py3 # Use virtualenvwrapper to switch back to my_project_py3 Make sure you have newest version of XCode CLI installed by running: `xcode-select --install` 1. If you have file not found issues with pyenv's `virtualenvwrapper.sh`, you should be able to check where it lives with `pyenv which virtualenvwrapper.sh`. Substitute in this path in your .zshrc/.bashrc/.bash_profile. 1. If on MacOS you're having issues with pip installs and getting an error like: ``` Error in sitecustomize; set PYTHONVERBOSE for traceback: -
wronk revised this gist
Mar 26, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,7 +56,7 @@ For comparison to Anaconda, see [note below](#other-notes) # Tell pyenv-virtualenvwrapper to use pyenv when creating new Python environments export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true" ``` Make sure that the directory you define for `WORKON_HOME` actually exists (or use `mkdir ~/.virtualenvs`), and either restart your terminal or source the relevant configuration (i.e., `source ~/.zshrc`, `source ~/.bashrc`, `source ~/.bash_profile`). See [Troubleshooting](https://gist.github.com/wronk/a902185f5f8ed018263d828e1027009b#troubleshooting) if your system has issues finding `virtualenvwrapper.sh`. You can find the full virtualenvwrapper [installation instructions here](https://virtualenvwrapper.readthedocs.io/en/latest/index.html#introduction). ## Using the workflow -
wronk revised this gist
Mar 26, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,7 +56,7 @@ For comparison to Anaconda, see [note below](#other-notes) # Tell pyenv-virtualenvwrapper to use pyenv when creating new Python environments export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true" ``` Make sure that the directory you define for `WORKON_HOME` actually exists (or use `mkdir ~/.virtualenvs`), and either restart your terminal or source the relevant configuration (i.e., `source ~/.zshrc`, `source ~/.bashrc`, `source ~/.bash_profile`). You can find the full virtualenvwrapper [installation instructions here](https://virtualenvwrapper.readthedocs.io/en/latest/index.html#introduction). ## Using the workflow -
wronk revised this gist
Mar 26, 2020 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,14 +23,13 @@ For comparison to Anaconda, see [note below](#other-notes) **Installation/use**: From, [pyenv's install instructions](https://github.com/pyenv/pyenv#homebrew-on-macos), `brew install pyenv` on Mac. See the docs for installation via `git clone` on other other systems. Now, we need to finish pyenv install by setting up pyenv's shims. Execute the next line in a terminal: `echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc` Then you can install new Python versions, list installed versions, and set the Python version in the terminal like: ``` pyenv install 3.7.7 # Install Python version pyenv install 3.6.3 pyenv versions # List Python versions pyenv global 3.7.3 # Set the global Python version ``` Also install [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv) like `brew install pyenv-virtualenv`, which we'll need later. -
wronk revised this gist
Mar 26, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,7 +48,7 @@ For comparison to Anaconda, see [note below](#other-notes) 3. **[virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/en/latest/)**. This helps pyenv and virtualenv gel like PB&J. With it, you can effectively switch between a single environment that has both the Python version and virtual environment wrapped in one bundle. Make sure pyenv and virtualenv are installed before you install this wrapper. **Installation**: `pip install virtualenvwrapper` and then `brew install pyenv-virtualenvwrapper` to extend pyenv. Then you'll need to do some one-time setup; in your .zshrc/.bashrc/.bash_profile, add the following: ``` # Setup virtualenv home export WORKON_HOME=$HOME/.virtualenvs @@ -57,7 +57,7 @@ For comparison to Anaconda, see [note below](#other-notes) # Tell pyenv-virtualenvwrapper to use pyenv when creating new Python environments export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true" ``` Make sure that the directory you define for `WORKON_HOME` actually exists, and either restart your terminal or source the relevant configuration (i.e., `source ~/.zshrc`, `source ~/.bashrc`, `source ~/.bash_profile`). You can find the full virtualenvwrapper [installation instructions here](https://virtualenvwrapper.readthedocs.io/en/latest/index.html#introduction). ## Using the workflow -
wronk revised this gist
Oct 22, 2019 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,8 +9,8 @@ When you're working on multiple coding projects, you might want a couple differe </p> ### Use cases 1. Working on 2+ projects that each have their own dependencies; e.g., a Python 2.7 project and a Python 3.7 project, or developing a module that needs to work across multiple versions of Python. It's not reasonable to uninstall/reinstall modules every time you want to switch environments. 2. If you want to execute code on the cloud, you can set up a Python environment that mirrors the relevant cloud instance. For example, one of Amazon's main EC2 deep learning instances runs Python 3.6, and you may hit obstacles if you use code developed on your machine with Python 3.8. 3. You might have some working Python code and want to make sure everything stays frozen so that it'll still work in the future. Without virtual environments, upgrading Python modules could unintentionally break that year-old project. Having to go back and determine the correct version for each dependency would be a huge pain. This guide shows how to solve these issues with pyenv and virtualenv (along with virtualenvwrapper). It shows how to obtain lower-level control of your development environment (compared to Anaconda/`conda`, for example) without too much technical complication. This is intended for MacOS, but all the tools work on Unix-like systems -- you'll just have to make use of `apt-get` instead of `brew` and detour through the original installation guides in some spots. @@ -121,7 +121,7 @@ workon my_project_py3 # Use virtualenvwrapper to switch back to my_project_py3 1. **Anaconda** does have functionality to handle some of the problems outlined above. Generally, it provides a lower bar for entry to Python development because the Anaconda software distribution contains both the `conda` package manager as well as many useful python modules, which is great for new Python users. Anaconda is also a good choice for Windows users as getting all Python packages to play nicely together is a challenge on Windows. However, there are some downsides to Anaconda/`conda`: * Any package that can't be installed via the `conda` package manager must be installed with pip or some other method; at that point, you're managing two install streams. For more advanced development, this can get messy. * You aren't always going to be using the most up-to-date version of modules because Continuum must repackage each one into their own system before calling `conda update` will actually provide the newest version of that module's code. * Different versions of Python will not always have the latest module updates -- Continuum focuses its resources on certain versions of python, and you're relying on their team to incorporate all package updates to those version as well as the less-popular versions (like 3.4 and 3.5). * Because the Anaconda software distribution is a large self-contained install, it'll install many packages that you might not need. Miniconda solves this to some degree as it only contains the `conda` package manager and its dependencies. That aside, a good discussion of Anaconda's benefits, and some counter-arguements are [here](http://jakevdp.github.io/blog/2016/08/25/conda-myths-and-misconceptions/#Myth-#5:-conda-doesn't-work-with-virtualenv,-so-it's-useless-for-my-workflow). -
wronk revised this gist
Oct 22, 2019 . No changes.There are no files selected for viewing
-
wronk revised this gist
Oct 22, 2019 . 1 changed file with 10 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,13 +20,21 @@ For comparison to Anaconda, see [note below](#other-notes) ## Overview of the tools and setup 1. **[pyenv](https://github.com/pyenv/pyenv)**: Short for "Python environment." This manages which version of Python is visible to your computer (and temporarily hides any others). With pyenv, you can install multiple versions of Python and quickly switch between the "activated" version (i.e., the version your computer will use to execute code). Here, we'll switch the version of Python we're using with virtualenvwrapper's `workon` command (as described later). **Installation/use**: From, [pyenv's install instructions](https://github.com/pyenv/pyenv#homebrew-on-macos), `brew install pyenv` on Mac. See the docs for installation via `git clone` on other other systems. Now, we need to finish pyenv install by setting up pyenv's shims. Execute the next line in a terminal: `echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile` Then you can install new Python versions, list installed versions, and set the Python version in the terminal like: ``` pyenv install 3.6.3 # Install Python version pyenv install 3.4.0 pyenv versions # List Python versions pyenv global 3.6.3 # Set your system's Python version ``` Also install [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv) like `brew install pyenv-virtualenv`, which we'll need later. **Technical details**: Every time you execute a Python script or use pip, pyenv works in the background to intercept that command and send it to the Python environment that is currently activated. It does this using shims on the PATH environment variable, which allow Python-related commands to be dynamically rerouted. 2. **[virtualenv](https://virtualenv.pypa.io/en/stable/)**: Short for "virtual environment." This manages separate directories for the modules you install (e.g., with `pip`). That way, each virtual environment can have it's own set of installed modules that is walled off from every other virtual environment so they don't interfere with each other. Like with pyenv, we'll switch virtual environments with virtualenvwrapper's `workon` command (as described later). @@ -107,7 +115,7 @@ workon my_project_py3 # Use virtualenvwrapper to switch back to my_project_py3 set properly. ``` First, make sure the underlying tools are installed with `pip install virtualenv virtualenvwrapper`. If that still doesn't work, `pip` might be referring to a default version of python when you want to install it for a different version. You can explicitly call the version of python to refer to with something like `/usr/local/bin/pip3.7 install virtualenv virtualenvwrapper`. If that still doesn't work, try executing `pyenv virtualenvwrapper` as in Troubleshooting item 4. ## Other notes 1. **Anaconda** does have functionality to handle some of the problems outlined above. Generally, it provides a lower bar for entry to Python development because the Anaconda software distribution contains both the `conda` package manager as well as many useful python modules, which is great for new Python users. Anaconda is also a good choice for Windows users as getting all Python packages to play nicely together is a challenge on Windows. However, there are some downsides to Anaconda/`conda`: -
wronk revised this gist
Feb 12, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ When you're working on multiple coding projects, you might want a couple differe <p align="center"> <img width="350" src="https://imgs.xkcd.com/comics/python_environment_2x.png"> <br> h/t @sharkinsspatial for linking me to the perfect cartoon </p> ### Use cases -
wronk revised this gist
Feb 12, 2019 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,8 +4,9 @@ When you're working on multiple coding projects, you might want a couple differe <p align="center"> <img width="350" src="https://imgs.xkcd.com/comics/python_environment_2x.png"> <br> h/t @sharkinsspatial </p> ### Use cases 1. Working on 2+ projects that each have their own dependencies; e.g., a Python 2.7 project and a Python 3.6 project, or developing a module that needs to work across multiple versions of Python. It's not reasonable to uninstall/reinstall modules every time you want to switch environments. -
wronk revised this gist
Feb 12, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ When you're working on multiple coding projects, you might want a couple differe <p align="center"> <img width="350" src="https://imgs.xkcd.com/comics/python_environment_2x.png"> </p> h/t @sharkinsspatial -
wronk revised this gist
Feb 12, 2019 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,12 @@ ## Overview When you're working on multiple coding projects, you might want a couple different version of Python and/or modules installed. That way you can keep each project in its own sandbox instead of trying to juggle multiple projects (each with different dependencies) on your system's version of Python. This intermediate guide covers one way to handle multiple Python versions and Python environments on your own (i.e., without a package manager like `conda`). See the [Using the workflow](https://gist.github.com/wronk/a902185f5f8ed018263d828e1027009b#using-the-workflow) section to view the end result. <p align="center"> <img width="350" src="https://xkcd.com/1987/"> </p> h/t @sharkinsspatial ### Use cases 1. Working on 2+ projects that each have their own dependencies; e.g., a Python 2.7 project and a Python 3.6 project, or developing a module that needs to work across multiple versions of Python. It's not reasonable to uninstall/reinstall modules every time you want to switch environments. 2. If you want to execute code on the cloud, you can set up a Python environment that mirrors the relevant cloud instance. For example, one of Amazon's main EC2 deep learning instances runs Python 3.4, and you may hit obstacles if you use code developed on your machine with Python 3.6. -
wronk revised this gist
Jan 24, 2019 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -89,6 +89,19 @@ workon my_project_py3 # Use virtualenvwrapper to switch back to my_project_py3 make sure you've set the desired version of python and enter on the command line `pyenv virtualenvwrapper` before trying to create a new virtual environment with the `mkvirtualenv` command. 1. If you're upgrading to a new version of python and having issues with `virtualenvwrapper` giving getting an error like: ``` /usr/local/opt/python/bin/python3.7: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: No module named 'virtualenvwrapper') virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenvwrapper has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/local/opt/python/libexec/bin/python and that PATH is set properly. ``` first, make sure the underlying tools are installed with `pip install virtualenv virtualenvwrapper`. If that still doesn't work, `pip` might be referring to a default version of python when you want to install it for a different version. You can explicitly call the version of python to refer to with something like `/usr/local/bin/pip3.7 install virtualenv virtualenvwrapper`. ## Other notes 1. **Anaconda** does have functionality to handle some of the problems outlined above. Generally, it provides a lower bar for entry to Python development because the Anaconda software distribution contains both the `conda` package manager as well as many useful python modules, which is great for new Python users. Anaconda is also a good choice for Windows users as getting all Python packages to play nicely together is a challenge on Windows. However, there are some downsides to Anaconda/`conda`: * Any package that can't be installed via the `conda` package manager must be installed with pip or some other method; at that point, you're managing two install streams. For more advanced development, this can get messy. -
wronk revised this gist
Sep 10, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -78,7 +78,7 @@ workon my_project_py3 # Use virtualenvwrapper to switch back to my_project_py3 ``` try deleting homebrew's link to python by deleting the `~/.local` folder. 1. If you're upgrading to a new version of python and having issues using `mkvirtualenv` giving getting an error like: ``` pyenv: virtualenv: command not found @@ -87,7 +87,7 @@ workon my_project_py3 # Use virtualenvwrapper to switch back to my_project_py3 3.6.3 ``` make sure you've set the desired version of python and enter on the command line `pyenv virtualenvwrapper` before trying to create a new virtual environment with the `mkvirtualenv` command. ## Other notes 1. **Anaconda** does have functionality to handle some of the problems outlined above. Generally, it provides a lower bar for entry to Python development because the Anaconda software distribution contains both the `conda` package manager as well as many useful python modules, which is great for new Python users. Anaconda is also a good choice for Windows users as getting all Python packages to play nicely together is a challenge on Windows. However, there are some downsides to Anaconda/`conda`: -
wronk revised this gist
Sep 10, 2018 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -78,7 +78,17 @@ workon my_project_py3 # Use virtualenvwrapper to switch back to my_project_py3 ``` try deleting homebrew's link to python by deleting the `~/.local` folder. 1. If you're having issues when using `mkvirtualenv` and getting an error like: ``` pyenv: virtualenv: command not found The `virtualenv' command exists in these Python versions: 2.7.14 3.6.3 ``` make sure you've set the desired version of python and try `pyenv virtualenvwrapper` before running `mkvirtualenv`. ## Other notes 1. **Anaconda** does have functionality to handle some of the problems outlined above. Generally, it provides a lower bar for entry to Python development because the Anaconda software distribution contains both the `conda` package manager as well as many useful python modules, which is great for new Python users. Anaconda is also a good choice for Windows users as getting all Python packages to play nicely together is a challenge on Windows. However, there are some downsides to Anaconda/`conda`: * Any package that can't be installed via the `conda` package manager must be installed with pip or some other method; at that point, you're managing two install streams. For more advanced development, this can get messy. -
wronk revised this gist
Jun 12, 2018 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,10 +72,10 @@ workon my_project_py3 # Use virtualenvwrapper to switch back to my_project_py3 1. If you have file not found issues with pyenv's `virtualenvwrapper.sh`, you should be able to check where it lives with `pyenv which virtualenvwrapper.sh` 1. If on MacOS you're having issues with pip installs and getting an error like: ``` Error in sitecustomize; set PYTHONVERBOSE for traceback: KeyError: 'PYTHONPATH' ``` try deleting homebrew's link to python by deleting the `~/.local` folder. -
wronk revised this gist
Jun 12, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -77,7 +77,7 @@ Error in sitecustomize; set PYTHONVERBOSE for traceback: KeyError: 'PYTHONPATH' ``` try deleting homebrew's link to python by deleting the `~/.local` folder. ## Other notes 1. **Anaconda** does have functionality to handle some of the problems outlined above. Generally, it provides a lower bar for entry to Python development because the Anaconda software distribution contains both the `conda` package manager as well as many useful python modules, which is great for new Python users. Anaconda is also a good choice for Windows users as getting all Python packages to play nicely together is a challenge on Windows. However, there are some downsides to Anaconda/`conda`: -
wronk revised this gist
Jun 12, 2018 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -71,6 +71,14 @@ workon my_project_py3 # Use virtualenvwrapper to switch back to my_project_py3 Make sure you have newest version of XCode CLI installed by running: `xcode-select --install` 1. If you have file not found issues with pyenv's `virtualenvwrapper.sh`, you should be able to check where it lives with `pyenv which virtualenvwrapper.sh` 1. If on MacOS you're having issues with pip installs and getting an error like: ``` Error in sitecustomize; set PYTHONVERBOSE for traceback: KeyError: 'PYTHONPATH' ``` try deleting homebrew's link to python by deleting the `~/.local` folder. ## Other notes 1. **Anaconda** does have functionality to handle some of the problems outlined above. Generally, it provides a lower bar for entry to Python development because the Anaconda software distribution contains both the `conda` package manager as well as many useful python modules, which is great for new Python users. Anaconda is also a good choice for Windows users as getting all Python packages to play nicely together is a challenge on Windows. However, there are some downsides to Anaconda/`conda`: * Any package that can't be installed via the `conda` package manager must be installed with pip or some other method; at that point, you're managing two install streams. For more advanced development, this can get messy. -
wronk revised this gist
Jan 19, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,11 +72,11 @@ workon my_project_py3 # Use virtualenvwrapper to switch back to my_project_py3 1. If you have file not found issues with pyenv's `virtualenvwrapper.sh`, you should be able to check where it lives with `pyenv which virtualenvwrapper.sh` ## Other notes 1. **Anaconda** does have functionality to handle some of the problems outlined above. Generally, it provides a lower bar for entry to Python development because the Anaconda software distribution contains both the `conda` package manager as well as many useful python modules, which is great for new Python users. Anaconda is also a good choice for Windows users as getting all Python packages to play nicely together is a challenge on Windows. However, there are some downsides to Anaconda/`conda`: * Any package that can't be installed via the `conda` package manager must be installed with pip or some other method; at that point, you're managing two install streams. For more advanced development, this can get messy. * You aren't always going to be using the most up-to-date version of modules because Continuum must repackage each one into their own system before calling `conda update` will actually provide the newest version of that module's code. * Different versions of Python will not always have the latest module updates -- Continuum focuses its resources on Python 2.7 and 3.6 right now, and you're relying on their team to incorporate all package updates to those version as well as the less-popular versions (like 3.4 and 3.5). * Because the Anaconda software distribution is a large self-contained install, it'll install many packages that you might not need. Miniconda solves this to some degree as it only contains the `conda` package manager and its dependencies. That aside, a good discussion of Anaconda's benefits, and some counter-arguements are [here](http://jakevdp.github.io/blog/2016/08/25/conda-myths-and-misconceptions/#Myth-#5:-conda-doesn't-work-with-virtualenv,-so-it's-useless-for-my-workflow). -
wronk revised this gist
Jan 19, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -78,7 +78,7 @@ workon my_project_py3 # Use virtualenvwrapper to switch back to my_project_py3 * Different versions of Python will not always have the latest module updates -- Continuum focuses its resources on Python 2.7 and 3.6 right now, and you're relying on their team to incorporate all package updates to those version as well as the less-popular versions (like 3.4 and 3.5). * Because the Anaconda software distribution is a large self-contained install, it'll install many packages that you might not need. Miniconda solves this to some degree as it only contains the `conda` package manager and it's dependencies. That aside, a good discussion of Anaconda's benefits, and some counter-arguements are [here](http://jakevdp.github.io/blog/2016/08/25/conda-myths-and-misconceptions/#Myth-#5:-conda-doesn't-work-with-virtualenv,-so-it's-useless-for-my-workflow). 1. **Virtual environment prefix on source prompt** -
wronk revised this gist
Jan 19, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -78,7 +78,7 @@ workon my_project_py3 # Use virtualenvwrapper to switch back to my_project_py3 * Different versions of Python will not always have the latest module updates -- Continuum focuses its resources on Python 2.7 and 3.6 right now, and you're relying on their team to incorporate all package updates to those version as well as the less-popular versions (like 3.4 and 3.5). * Because the Anaconda software distribution is a large self-contained install, it'll install many packages that you might not need. Miniconda solves this to some degree as it only contains the `conda` package manager and it's dependencies. That aside, a good discussion of Anaconda's benefits, and some counter-arguements are [here](http://jakevdp.github.io/blog/2016/08/25/conda-myths-and-misconceptions/#Myth-#5:-conda-doesn't-work-with-virtualenv,-so-it's-useless-for-my-workflow). 1. **Virtual environment prefix on source prompt** -
wronk revised this gist
Jan 19, 2018 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -77,6 +77,8 @@ workon my_project_py3 # Use virtualenvwrapper to switch back to my_project_py3 * You aren't always going to be using the most up-to-date version of modules because Continuum must repackage each one into their own system before calling `conda update` will actually provide the newest version of that module's code. * Different versions of Python will not always have the latest module updates -- Continuum focuses its resources on Python 2.7 and 3.6 right now, and you're relying on their team to incorporate all package updates to those version as well as the less-popular versions (like 3.4 and 3.5). * Because the Anaconda software distribution is a large self-contained install, it'll install many packages that you might not need. Miniconda solves this to some degree as it only contains the `conda` package manager and it's dependencies. That aside, a good discussion of Anaconda's benefits, and some counter-arguements are [here](http://jakevdp.github.io/blog/2016/08/25/conda-myths-and-misconceptions/#Myth-#5:-conda-doesn't-work-with-virtualenv,-so-it's-useless-for-my-workflow). 1. **Virtual environment prefix on source prompt** -
wronk revised this gist
Jan 19, 2018 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,12 @@ ## Overview When you're working on multiple coding projects, you might want a couple different version of Python and/or modules installed. That way you can keep each project in its own sandbox instead of trying to juggle multiple projects (each with different dependencies) on your system's version of Python. This intermediate guide covers one way to handle multiple Python versions and Python environments on your own (i.e., without a package manager like `conda`). See the [Using the workflow](https://gist.github.com/wronk/a902185f5f8ed018263d828e1027009b#using-the-workflow) section to view the end result. ### Use cases 1. Working on 2+ projects that each have their own dependencies; e.g., a Python 2.7 project and a Python 3.6 project, or developing a module that needs to work across multiple versions of Python. It's not reasonable to uninstall/reinstall modules every time you want to switch environments. 2. If you want to execute code on the cloud, you can set up a Python environment that mirrors the relevant cloud instance. For example, one of Amazon's main EC2 deep learning instances runs Python 3.4, and you may hit obstacles if you use code developed on your machine with Python 3.6. 3. You might have some working Python code and want to make sure everything stays frozen so that it'll still work in the future. Without virtual environments, upgrading Python modules could unintentionally break that year-old project. Having to go back and determine the correct version for each dependency would be a huge pain. This guide shows how to solve these issues with pyenv and virtualenv (along with virtualenvwrapper). It shows how to obtain lower-level control of your development environment (compared to Anaconda/`conda`, for example) without too much technical complication. This is intended for MacOS, but all the tools work on Unix-like systems -- you'll just have to make use of `apt-get` instead of `brew` and detour through the original installation guides in some spots. For comparison to Anaconda, see [note below](#other-notes) @@ -72,7 +72,7 @@ workon my_project_py3 # Use virtualenvwrapper to switch back to my_project_py3 1. If you have file not found issues with pyenv's `virtualenvwrapper.sh`, you should be able to check where it lives with `pyenv which virtualenvwrapper.sh` ## Other notes 1. **Anaconda**: Anaconda does have functionality to handle some of the problems outlined above. Generally, it provides a lower bar for entry to Python development because the Anaconda software distribution contains both the `conda` package manager as well as many useful python modules, which is great for new Python users. Anaconda is also a good choice for Windows users as getting all Python packages to play nicely together is a challenge on Windows. However, there are some downsides to Anaconda/`conda`: * Any package that can't be installed via the `conda` package manager must be installed with pip or some other method; at that point, you're managing two install streams. For more advanced development, this can get messy. * You aren't always going to be using the most up-to-date version of modules because Continuum must repackage each one into their own system before calling `conda update` will actually provide the newest version of that module's code. * Different versions of Python will not always have the latest module updates -- Continuum focuses its resources on Python 2.7 and 3.6 right now, and you're relying on their team to incorporate all package updates to those version as well as the less-popular versions (like 3.4 and 3.5). -
wronk revised this gist
Jan 19, 2018 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,11 +72,11 @@ workon my_project_py3 # Use virtualenvwrapper to switch back to my_project_py3 1. If you have file not found issues with pyenv's `virtualenvwrapper.sh`, you should be able to check where it lives with `pyenv which virtualenvwrapper.sh` ## Other notes 1. **Anaconda**: Anaconda does have functionality to handle some of the problems outlined above. Generally, it provides a lower bar for entry to Python development because the Anaconda software distribution contains both the `conda` package manager as well as many useful python modules, which is great for new Python users. Anaconda is also a good choice for Windows users as getting all Python packages to play nicely together is a challenge on Windows. However, there are some downsides to Anaconda: * Any package that can't be installed via the `conda` package manager must be installed with pip or some other method; at that point, you're managing two install streams. For more advanced development, this can get messy. * You aren't always going to be using the most up-to-date version of modules because Continuum must repackage each one into their own system before calling `conda update` will actually provide the newest version of that module's code. * Different versions of Python will not always have the latest module updates -- Continuum focuses its resources on Python 2.7 and 3.6 right now, and you're relying on their team to incorporate all package updates to those version as well as the less-popular versions (like 3.4 and 3.5). * Because the Anaconda software distribution is a large self-contained install, it'll install many packages that you might not need. Miniconda solves this to some degree as it only contains the `conda` package manager and it's dependencies. 1. **Virtual environment prefix on source prompt**
NewerOlder