Nov 27, 2018

Managing Multiple Python Instances

The problem with working on different Python codebases is the versioning and the large amounts of libraries available. Say you are working on a data science project using Pandas and then suddenly your boss wants you to take a look at an old Django project that is still using Python 2.7! And what if that messes up how you manage your large MP3 collection? How can you do this? And how you can stop it from looking like a waste site?

While Python 3 has built-in functionality for some of this, it doesn’t help you if have an old Python 2 project to support as well. Luckily, tools for this exist: You can install multiple Python instances with pyenv and you can have different instances of the same version with virtualenv. And pyenv has a plugin for virtualenv so it’s really one-stop shopping.

If you follow the install directions, you will find that you have a command called pyenvLike sdkman for Java, this is the command that will manage all your Python instances. If setup correctly, this will be in control of all your Python environments, executables, and libraries in your user space but not effect the main system version of Python. This way you can keep up with all the latest versions of Python and not rely on your system’s package manager. pyenv will store all your Python instances (“normal” and via virtualenv) in your $HOME/.pyenv/versions folder, which is handy to know if you use something like Pycharm, etc, for your Python development. Just point it to the correct instance under the folder, and you are good to go. Then you can install new libraries via pip in an isolated way, and then switch to another Python instance easily.

Instead of stepping you througbh all the documentation, I thought I would make a little cheatsheet of what the main commands are:

 

Command Result
pyenv install <pyversion> Download, compile and install that version in the pyenv versions
pyenv global see what the global python version is in your user space
pyenv global <pyversion> set the global python version in your user space
pyenv local See the python version local in that folder
pyenv local <pyversion> Set the python version in that folder
pyenv virtualenv <pyversion> <projectname> Create a blank copy (no outside deps) of the python version and install it as the project name (i.e. virtualenv)
pyenv local &lt;projectname&gt; Use the virutalenv <projectname> in that folder

Hopefully this will save you from pulling your hair out while working on different Python projects.

About the Author

Mike Hostetler profile.

Mike Hostetler

Principal Technologist

Mike has almost 20 years of experience in technology. He started in networking and Unix administration, and grew into technical support and QA testing. But he has always done some development on the side and decided a few years ago to pursue it full-time. His history of working with users gives Mike a unique perspective on writing software.

One thought on “Managing Multiple Python Instances

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Blog Posts
Structuring SwiftUI Previews for API Calls
SwiftUI, together with Combine and Xcode 11+, provide a powerful toolset for quickly creating an app with a native UI. In Xcode 11+, the preview pane was introduced in order to provide live snapshots of […]
Seamlessly Integrating Micro Apps with iFrame
A recent client wanted to upgrade a small portion of their legacy application with a more modern UI and extra functionality, like fuzzy text search. There are a few approaches to incremental upgrades of legacy […]
Consul on Docker EE
[markdown]”Consul is a service networking solution to connect and secure services across any runtime platform and public or private cloud” – [https://consul.io](https://consul.io) This post details a way to run a Consul cluster on Docker EE […]
Passing the AWS Machine Learning Speciality Exam
The Amazon Machine Learning Specialty Exam is a 3-hour, 65 question test. It is designed to test your skills in AWS specific Data Engineering and Machine Learning Practices along with Machine Learning in general. I […]