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

Object Partners profile.

One thought on “Managing Multiple Python Instances

Leave a Reply

Your email address will not be published.

Related Blog Posts
Natively Compiled Java on Google App Engine
Google App Engine is a platform-as-a-service product that is marketed as a way to get your applications into the cloud without necessarily knowing all of the infrastructure bits and pieces to do so. Google App […]
Building Better Data Visualization Experiences: Part 2 of 2
If you don't have a Ph.D. in data science, the raw data might be difficult to comprehend. This is where data visualization comes in.
Unleashing Feature Flags onto Kafka Consumers
Feature flags are a tool to strategically enable or disable functionality at runtime. They are often used to drive different user experiences but can also be useful in real-time data systems. In this post, we’ll […]
A security model for developers
Software security is more important than ever, but developing secure applications is more confusing than ever. TLS, mTLS, RBAC, SAML, OAUTH, OWASP, GDPR, SASL, RSA, JWT, cookie, attack vector, DDoS, firewall, VPN, security groups, exploit, […]