-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvitual_environments.py
67 lines (42 loc) · 1.88 KB
/
vitual_environments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Virtual Environments Guide
# 1. Creating a Virtual Environment
# In the terminal or command prompt, navigate to your project folder and run:
# python -m venv venv
# This command creates a virtual environment named 'venv' in your project folder.
# 2. Activating the Virtual Environment
# On Windows:
# .\venv\Scripts\activate
# On macOS/Linux:
# source venv/bin/activate
# After activation, your terminal prompt should change to indicate that the virtual environment is active.
# 3. Installing Packages in the Virtual Environment
# With the virtual environment active, use pip to install packages:
# pip install package_name
# Example:
# pip install requests
# 4. Deactivating the Virtual Environment
# To deactivate the virtual environment and return to the global Python environment:
# deactivate
# 5. Using a Requirements File
# Create a file named 'requirements.txt' with a list of dependencies:
# Example 'requirements.txt':
"""
requests==2.26.0
beautifulsoup4==4.10.0
"""
# Install dependencies from the requirements file:
# pip install -r requirements.txt
# 6. Checking Installed Packages
# To see a list of installed packages in the virtual environment:
# pip list
# 7. Using Virtual Environments in Scripts
# You can add the shebang line to the top of your Python script to specify the interpreter and activate the virtual environment:
# Example shebang line for Windows:
# #!./venv/Scripts/python.exe
# Example shebang line for macOS/Linux:
# #!/path/to/venv/bin/python
# 8. Creating a Virtual Environment with a Specific Python Version
# If you have multiple Python versions installed, you can create a virtual environment with a specific version:
# python3.8 -m venv venv
# Note: Ensure you have Python and pip installed on your system before creating virtual environments.
# Virtual environments are an essential tool for managing project dependencies and isolating project environments.