Master Python Virtual Environments with virtualenv and PyCharm
This guide walks you through installing virtualenv via pip or source, creating and activating a Python 3.6 virtual environment for a project, and seamlessly integrating it into PyCharm on Windows, enabling simultaneous use of Python 2.7 and 3.6 for development.
1. Install virtualenv
virtualenv can be installed like any other Python package, either with pip install virtualenv or by downloading the source tar.gz from the official site and running python setup.py install. Uninstall with pip uninstall virtualenv.
1.1 Install via pip
pip install virtualenv1.2 Install from source
Download the latest tar.gz from the virtualenv website, extract it, navigate to the extracted directory, and run:
python setup.py install2. Configure a Python virtual environment
Use virtualenv to create an isolated environment for a specific project directory, specifying the desired Python interpreter. Example for a project at c:\PythonProj\sjtu-cs using Python 3.6: virtualenv -p c:\Python36\python.exe HigEnv Here -p indicates the Python executable path, and HigEnv is the name of the virtual environment.
3. Activate the virtual environment
Activate the environment with:
c:\PythonProj\sjtu-cs>cd HigEnv\Scripts
activateAfter activation, running python will use the selected Python version (e.g., print becomes a function). Deactivate with:
deactivate4. Use virtualenv in PyCharm
PyCharm integrates virtualenv, allowing you to create or select a virtual environment directly in the IDE without manual installation.
4.1 Create a new project and choose Python version
When importing an existing project, PyCharm auto‑detects the matching Python interpreter, but you can manually select a different one.
4.2 Create a virtualenv in PyCharm
In the project settings, choose "Add New Interpreter", select "Virtualenv Environment", and specify the base interpreter (e.g., Python 3.6). PyCharm will create the environment and configure the project to use it.
You can also skip creating a new environment and simply point the project to an existing interpreter.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
