Difference between revisions of "Set up a Python virtual environment"

From Parallel Library Services
Jump to navigation Jump to search
Line 9: Line 9:


== Activate ==
== Activate ==
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
source venv/bin/activate
source venv/bin/activate
Line 18: Line 17:
(venv)Username@Computer myfolder %
(venv)Username@Computer myfolder %
</syntaxhighlight>
</syntaxhighlight>
== Use ==
Install dependencies within the new Python virtual environment. For Mac, the command is:
pip install {packagename}


== Deactivate ==
== Deactivate ==
To stop the virtual environment, type:
To stop it, type:


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 27: Line 31:


== Close ==
== Close ==
Simply type
Simply type



Revision as of 18:36, 4 November 2021

Python virtual environments run their own site directories, allowing them to be optionally separated from system directories. This can easily avoid a potential nightmare of version conflicts - one piece of software on your system may require a certain version to run, while another make require a different one.

Create

venv is a tool that can be used to create an environment:

python3 -m venv venv

Activate

source venv/bin/activate

You will see the prompt change to something like this:

(venv)Username@Computer myfolder %

Use

Install dependencies within the new Python virtual environment. For Mac, the command is:

pip install {packagename}

Deactivate

To stop it, type:

deactivate

Close

Simply type

exit