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

From Parallel Library Services
Jump to navigation Jump to search
(Created page with "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 ve...")
 
Line 1: Line 1:
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.
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.


== Creating the virtual environment ==
== Create ==
<code>venv</code> is a tool that can be used to create an environment:
<code>venv</code> is a tool that can be used to create an environment:


Line 8: Line 8:
</syntaxhighlight>
</syntaxhighlight>


To activate the virtual environment, run:
== Activate ==


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 19: Line 19:
</syntaxhighlight>
</syntaxhighlight>


To close it, simply type
== Close ==
 
Simply type


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
exit
exit
</syntaxhighlight>
</syntaxhighlight>

Revision as of 21:47, 2 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 %

Close

Simply type

exit