Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
You are hereĀ because:
- You are using Windows OS versionĀ 10+
- You would like to use multiple Python versions on the sameĀ computer
- You are tired of the internet telling you to āJust Use Virtualenvā
TL;DR
- Open Command Prompt and enter pip install virtualenv
- Download the desired python version (do NOT add to PATH!), and remember the path\to\new_python.exe of the newly installed version
- To create a virtualenv, open Command Prompt and enter virtualenv \path\to\env -p path\to\new_python.exe
- If you are using PyCharm, update the Project Interpreter and the Code compatibility inspection.
- To install packages: (I) Activate virtualenv: open Command Prompt and either enter path\to\env\Scripts\activate.bat or activate env_nameĀ .(II) Install desired packages(III) Deactivate with deactivateĀ .
The Long version; DoĀ Read
Prologue
If you are using the Anaconda App this process might be easier using their GUI. I havenāt tried it myself, please let know how it went if you are going down that roadĀ :)
1. Install virtualenv
If you already have some virtual environments, or are using Anaconda, make sure the next steps are performed from outside all these environments.
2. InstallĀ Python
You can download python from the official site, for example for python3.7.3 goĀ here.
The file you should be downloading is called Windows x86ā64 executable installer, or Windows x86 executable installer if for some reason you are using a 32-bitĀ windows.
Once downloading is finished, open the executable file and an installation prompt willĀ appear.
- You do NOT want to add the new python to your PATH since we are going to have multiple python versions on the same computer, and we would like for each application to know only one pythonĀ version.
- Either use the default suggested location for the new python, or supply a location of your choice. Either way, remember this location and letās denote it from now on with C:\<some_path>\Python37Ā .
Open the Command Prompt, or if you are using Anaconda open the Anaconda PromptĀ .
Decide where you want your virtualenv to be, for example, C:\Users\<your_username>\Anaconda3\envs\<env_name>Ā .
Enter:
virtualenv C:\Users\<your_username>\Anaconda3\envs\<env_name> -p C:\<some_path>\Python37\python.exe
4. Update PyCharm Interpreter
If you are using PyCharm, open the project you would like to work on (that is/will be written with the new python version), and go to File -> Settings -> Project -> Project Interpreter press the gear icon and then Add..Ā .
This will open a prompt window that allows you to define a new interpreter:
Assuming you are using Code Inspections, you might need to tell PyCharm which python version to inspect for. Go to File -> Settings-> Editor -> Inspections -> Python -> Code compatibility InspectionĀ , make sure the box on the top indicates the specific project you are working on, and tick the box of your pythonĀ version.
If you donāt see your python version on the Options list, this might also be the time to update PyCharmā¦ yup, happened to meĀ tooā¦5. InstallĀ packages
Currently, your virtualenv contains only the crucial packages, pip and setuptoolsĀ . To install more packages:
- Open Command Prompt or Anaconda PromptĀ , and activate your virtualenv by either entering C:\Users\<your_username>\Anaconda3\envs\<env_name>\activate.bat or activate env_nameĀ . For the life of me I still donāt understand why for some of my virtualenvs the first one works, and for some theĀ second.
- Use pip to install packages like you usuallyĀ do.
- Deactivate your virtualenv by entering deactivateĀ .
Epilogue
This morning, when I decided to open a new project with a different python version, I thought, āYeah, Iāll just use a virtualenvā, because the internet said I can āJust doĀ itā.
Well, itās working now, so no hard feelings dear internet, but seriously, was the āJustā really justified? Does reinstalling-PyCharm-only-because-I-want-to-have-proper-code-inspections fall under the āJustā category??
Anyway, along the way I stumbled upon several helpful guides, but each one took me ājustā one step of the way, so I decided to put it all in oneĀ place.
I hope my journey helped you with yours, and may we all enjoy happy coding, with as little as IT-friction as possibleĀ :D
Installing Multiple Python Versions on Windows Using Virtualenv was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.