H a n d s o n, p r o j e c t b a s e d


Creating a Virtual Environment


Download 4.21 Mb.
Pdf ko'rish
bet295/344
Sana31.01.2024
Hajmi4.21 Mb.
#1818553
1   ...   291   292   293   294   295   296   297   298   ...   344
Bog'liq
Python Crash Course, 2nd Edition

Creating a Virtual Environment
To work with Django, we’ll first set up a virtual environment. A virtual envi-
ronment is a place on your system where you can install packages and isolate 
them from all other Python packages. Separating one project’s libraries 
from other projects is beneficial and will be necessary when we deploy 
Learning Log to a server in Chapter 20.
Create a new directory for your project called learning_log, switch 
to that directory in a terminal, and enter the following code to create a 
virtual environment:
learning_log$ python -m venv ll_env
learning_log$ 
Here we’re running the 
venv
virtual environment module and using it 
to create a virtual environment named ll_env (note that this is ll_env with 
two lowercase Ls, not two ones). If you use a command such as 
python3
when running programs or installing packages, make sure to use that 
command here.


Getting Started with Django
381
Activating the Virtual Environment
Now we need to activate the virtual environment using the following 
command:
learning_log$ source ll_env/bin/activate
u
(ll_env)learning_log$
This command runs the script activate in ll_env/bin. When the envi-
ronment is active, you’ll see the name of the environment in parentheses, 
as shown at u; then you can install packages to the environment and use 
packages that have already been installed. Packages you install in ll_env 
will be available only while the environment is active. 
n o t e
 
If you’re using Windows, use the command 
ll_env\Scripts\activate
 (without the 
word 
source
) to activate the virtual environment. If you’re using PowerShell, you 
might need to capitalize 
Activate
.
To stop using a virtual environment, enter 

Download 4.21 Mb.

Do'stlaringiz bilan baham:
1   ...   291   292   293   294   295   296   297   298   ...   344




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling