Nothing more frustrating in a data science project than a library that doesn’t work in your particular Python version. Sometimes, you just need to install a virtual environment with another Python version.
First of all, if you are a venv user, I hate to break it to you. There’s no straightforward way to create a virtual environment with another Python version using venv. For this reason, you’ll have to install virtualenv.
But first…
What is the difference between venv and virtualenv?
- venv is a package that comes with Python 3. In other words: you don’t need to install an extra package to create virtual environments.
- On the other hand, virtualenv is library that you can download via pip install virtualenv.
Furthermore, according to the virtualenv documentation, venv is…
- is slower (by not having the
app-data
seed method), - is not as extendable,
- cannot create virtual environments for arbitrarily installed python versions (and automatically discover these),
- is not upgrade-able via pip,
- does not have as rich programmatic API (describe virtual environments without creating them).
Virtual environments with other Python version
To create a virtual environment with another Python version, you have to take the following steps.
- Download the Python version that you need, e.g. Python 3.6
- Install the Python executable. I recommend a custom installation. There’s no need to add it to PATH.
- Run Virtual Studio Code (or any other editor or terminal). Windows: If the installation directory is within Program Files, run it as an Administrator.
- Install virtualenv in your main Python version via pip install virtualenv
- Create the virtual environment with virtualenv, and specify the -p parameter.
py -m virtualenv -p=<your_python_executable> <virtual_environment_directory>
If your directory contains spaces, wrap it in double quotes. Like this:
py -m virtualenv -p="C:\Program Files\Python36\python.Exe" .virtenv
Good luck!
Thank you, It worked for me
Thanks a lot! It worked 👍
Great post. I just wonder if this will work when the two python versions are 32 bit and 64 bit ?
This is a great post! I’m currently working on a project that will require me to use a different version of Python, so this is really helpful.
This is a great post! I’m currently working on a project that will require me to use a different version of Python, so this is really helpful.
This is a great post! I’m currently working on a project that will require me to use a different version of Python, so this is really helpful.
This is a great post! I’m currently working on a project that will require me to use a different version of Python, so this is really helpful.
This is a great post! I’m currently working on a project that will require me to use a different version of Python, so this is really helpful.
This is a great post! I’m currently working on a project that will require me to use a different version of Python, so this is really helpful.
This is a great post! I’m currently working on a project that will require me to use a different version of Python, so this is really helpful.
This is a great post! I’m currently working on a project that will require me to use a different version of Python, so this is really helpful.
This is a great post! I’m currently working on a project that will require me to use a different version of Python, so this is really helpful.
This is a great post! I’m currently working on a project that will require me to use a different version of Python, so this is really helpful.
This is a great post! I’m currently working on a project that will require me to use a different version of Python, so this is really helpful.
Watch Bigg Boss 17 Colors Tv Show Hindi Video Episode Update.
That is great! I will definitely be watching that show! Thank you so much for that great info Bigg Boss 17 Today Episode
Watch Bigg Boss 17 Colors Tv Show Hindi Video Episode Update.
This is an interesting topic that I would like to learn more about! Can you provide some resources or tutorials on how to create virtual environments with another Python version?
Everything is very open with a clear description of the challenges.
It was definitely informative. Your website is very helpful.
Thank you for sharing!
Great tutorial! I’m always looking for ways to manage multiple Python versions on my machine, and this approach looks very elegant. Can’t wait to try it out and simplify my development workflow.
Thanks for the clear and detailed explanation! I followed your steps and was able to create a virtual environment with a different Python version smoothly. This is a game-changer for managing my projects. Great job!
Thanks for the clear instructions! I’ve always found managing different Python versions tricky, but this guide makes it straightforward. Looking forward to trying out virtual environments with my projects!