Virtualenv Setup Guide

A guide for setting up a virtualenv environment to install and run Python packages.

About Virtualenv

  • It is like a container where Python is newly installed and only the modules you want are used.
  • Virtualenv is a tool that creates an independent virtual environment so that it does not affect the Python environment installed on the system. This environment provides separate Python executable files and library paths, and installing packages does not affect the Python settings of the entire system. You can also install multiple versions of Python and select the desired version to configure the virtual environment.

Prerequisites

1. Ubuntu

Example) Installing Python 3.10 (Recommended Python version: 3.10 ~ 3.12)

  $ sudo apt-get update
  $ sudo apt-get install python3.10 python3-pip python3.10-dev python3.10-distutils

2. macOS

brew install openssl
brew install libmagic
brew install postgresql  
brew install python3 

3. Windows

Python installation (Recommended version: 3.10 ~ 3.12) Download and run the installer from https://www.python.org/downloads/windows/.
1. Check "Add Python.exe to PATH" and then click "Install Now".
python1

2. Click "Disable path length limit".
python2
OpenJDK installation (Recommended version: 11) Download and run the appropriate .msi file from https://learn.microsoft.com/en-us/java/openjdk/download.
1. Download and run the .msi file.
jdk1

2. Select 'Set or override JAVA_HOME...'.
jdk2
Microsoft Visual C++ installation (Recommended version: 14.0 or higher) Download and run the build tool from https://visualstudio.microsoft.com/visual-cpp-build-tools/.
1. Check "Desktop development with C++" and install.
vs

Git installation Download the appropriate Git installer from https://git-scm.com/download/win.



How to Create and Activate virtualenv

1. Ubuntu

  • Install and run virtualenv
    $ pip3 install virtualenv
    $ virtualenv -p /usr/bin/python3.10 venv
    $ source venv/bin/activate
    
  • virtualenv commands

    Command Description Command
    Create virtual environment virtualenv -p [python_version] [env_name]
    Activate virtual environment source [env_name]/bin/activate
    Deactivate virtual environment deactivate

2. macOS

  • Install and run virtualenv
    # If pip does not exist
    $ wget https://bootstrap.pypa.io/get-pip.py
    $ python3 get-pip.py
    $ pip install virtualenv
    $ virtualenv -p /usr/bin/python3.10 venv
    $ source venv/bin/activate
    

3. Windows

  • Install virtualenvwrapper
    $ pip install virtualenv
    $ pip install virtualenvwrapper-win
    $ mkvirtualenv venv
    $ workon venv
    
    Errors that may occur during installation
      
          1. Building wheel for py-tlsh (setup.py) error occurs 
    - Download and install Microsoft Visual C++ 14.0 or higher version.
    2. 'LINK : fatal error LNK1158: cannot execute 'rc.exe'.' error occurs
    - Copy 'rc.exe' and 'rcdll.dll' files from C:\Program Files (x86)\Windows Kits\10\bin\10.xxx\x86 to C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools.
  • virtualenvwrapper-win commands

    Command Description Command
    Deactivate environment deactivate
    Create virtual environment mkvirtualenv [virtual_env_name]
    Activate environment workon [virtual_env_name]