How to create virtual env with python3

后端 未结 8 1315
感情败类
感情败类 2020-12-05 06:48

I am using python 2.7 + virtualenv version 1.10.1 for running myproject projects. Due to some other projects requirement I have to work wit

8条回答
  •  -上瘾入骨i
    2020-12-05 07:14

    virtualenv is the tool of choice for Python 2, while venv handles the task in Python 3.

    Yet you can create the virtual environment for Python 3 using any of them.

    Using venv

    python3 -m venv virtualenvname

    Command Syntax:

    /path/to/python3 -m venv /path/to/directory/virtual_env_name

    Using virtualenv

    virtualenv -p python3 virtualenvname

    Command Syntax:

    virtualenv -p /path/to/python3 /path/to/directory/virtual_env_name

    Activate the virtual environment

    On Linux, Unix or MacOS, using the terminal or bash shell:

    source /path/to/venv/bin/activate

    e.g. source virtualenvname/bin/activate

    On Unix or MacOS, using the csh shell:

    source /path/to/venv/bin/activate.csh

    On Unix or MacOS, using the fish shell:

    source /path/to/venv/bin/activate.fish

    On Windows using the Command Prompt:

    path\to\venv\Scripts\activate.bat

    On Windows using PowerShell:

    path\to\venv\Scripts\Activate.ps1

    Deactivating the virtual environment

    On Linux, Unix or MacOS, using the terminal or bash shell:

    deactivate

    On Windows using the Command Prompt:

    path\to\venv\Scripts\deactivate.bat

    On Windows using PowerShell:

    deactivate

    This answer is for those who may use a different OS.

提交回复
热议问题