Hướng dẫn how do i open python environment in windows? - làm cách nào để mở môi trường python trong windows?

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
1 là một công cụ để tạo ra môi trường Python bị cô lập. Bạn có thể đọc thêm về nó trong tài liệu ảo. Bài viết này cung cấp một bản tóm tắt nhanh chóng để giúp bạn thiết lập và sử dụng môi trường ảo.

Ở đâu, con trăn của tôi? ¶

Đôi khi phần khó nhất trong việc thiết lập môi trường ảo trên Windows là tìm phân phối Python của bạn. Nếu trình cài đặt didn thêm nó vào biến

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
2 của bạn, bạn có thể phải đi tìm. Nếu bạn đã tải xuống và cài đặt Python từ python.org và chấp nhận tất cả các mặc định trong quá trình cài đặt,
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
3 có thể được tìm thấy ở một trong các vị trí sau:

64 bit (ưa thích) ¶

C:\Users\%username%\AppData\Local\Programs\Python\Python36\python.exe

32 bit¶

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe

Cài đặt ________ 11¶

Nếu bạn cố gắng chạy

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
1 và thấy nó không có mặt, bạn có thể cài đặt nó bằng PIP.

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
6 có thể sẽ được tìm thấy trong thư mục cài đặt Python của bạn theo thư mục con
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
7.

Tạo một môi trường python ảo %

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
8 cho thư mục dự án của bạn và chạy
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
1 để tạo môi trường ảo mới.

Các lệnh sau sẽ tạo ra một môi trường ảo mới theo

cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
0.

cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv

Ghi chú

Nếu Windows không thể tìm thấy

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
6, hãy xem Cài đặt VirtualEnv. Bạn có thể thêm thư mục home thực thi vào biến
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
2 của bạn hoặc chỉ bao gồm đường dẫn đầy đủ trong dòng lệnh của bạn. Nếu bạn không chắc chắn ở đâu
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
3 được cài đặt, hãy xem vị trí của tôi là con trăn của tôi ?.Install virtualenv. You can either add the executable’s home directory to your
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
2 variable, or just include the full path in your command line. If you aren’t sure where
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
3 is installed, see Where’s My Python?.

Kích hoạt Môi trường Or

Bây giờ chúng ta có một môi trường ảo, chúng ta cần kích hoạt nó.

Sau khi bạn kích hoạt môi trường, dấu nhắc lệnh của bạn sẽ được sửa đổi để phản ánh sự thay đổi.

Thêm thư viện và tạo tệp yêu cầu.txt

Sau khi bạn kích hoạt môi trường ảo, bạn có thể thêm các gói vào nó bằng

cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
4. Bạn cũng có thể tạo một mô tả về các phụ thuộc của bạn bằng cách sử dụng
cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
4.

Lệnh sau tạo một tệp có tên

cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
6 liệt kê các gói đã cài đặt.

pip freeze > requirements.txt

Tệp này sau đó có thể được các cộng tác viên sử dụng để cập nhật môi trường ảo bằng lệnh sau.

pip install -r requirements.txt

Vô hiệu hóa môi trường lor

Để trở lại cài đặt hệ thống bình thường, hãy sử dụng lệnh

cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
7.

Sau khi bạn ban hành lệnh này, bạn sẽ nhận thấy rằng dấu nhắc lệnh trở lại bình thường.

Mới trong phiên bản 3.3.

Mã nguồn: lib/venv/ Lib/venv/


Mô -đun

cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
8 hỗ trợ tạo ra các môi trường ảo nhẹ, mỗi bộ có bộ gói python độc lập riêng được cài đặt trong các thư mục
cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
9 của họ. Một môi trường ảo được tạo ra trên đầu cài đặt Python hiện có, được gọi là môi trường ảo, cơ sở của Python, và có thể được phân lập từ các gói trong môi trường cơ sở, do đó, chỉ có những gói được cài đặt rõ ràng trong môi trường ảo.

Khi được sử dụng từ trong môi trường ảo, các công cụ cài đặt phổ biến như PIP sẽ cài đặt các gói Python vào môi trường ảo mà không cần phải nói rõ ràng như vậy.

Xem PEP 405 để biết thêm nền tảng về môi trường ảo Python.PEP 405 for more background on Python virtual environments.

Tính khả dụng: Không phải emscripten, không phải wasi.: not Emscripten, not WASI.

Mô -đun này không hoạt động hoặc không có sẵn trên các nền tảng Webassugging

pip freeze > requirements.txt
0 và
pip freeze > requirements.txt
1. Xem các nền tảng Webassugging để biết thêm thông tin.WebAssembly platforms for more information.

Tạo môi trường ảo

Tạo các môi trường ảo được thực hiện bằng cách thực thi lệnh

cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
8:virtual environments is done by executing the command
cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
8:

python3 -m venv /path/to/new/virtual/environment

Chạy lệnh này tạo thư mục đích (tạo bất kỳ thư mục mẹ nào chưa tồn tại) và đặt tệp

pip freeze > requirements.txt
3 trong đó với khóa
pip freeze > requirements.txt
4 trỏ đến cài đặt Python mà từ đó lệnh được chạy (một tên chung cho thư mục đích là
pip freeze > requirements.txt
5). Nó cũng tạo ra một thư mục con
pip freeze > requirements.txt
6 (hoặc
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
7 trên Windows) chứa một bản sao/liên kết của các nhị phân/nhị phân Python (phù hợp với nền tảng hoặc đối số được sử dụng tại thời gian tạo môi trường). Nó cũng tạo ra một thư mục con (ban đầu trống)
pip freeze > requirements.txt
8 (trên Windows, đây là
pip freeze > requirements.txt
9). Nếu một thư mục hiện có được chỉ định, nó sẽ được sử dụng lại.

Đã không dùng từ Phiên bản 3.6:

pip install -r requirements.txt
0 là công cụ được đề xuất để tạo môi trường ảo cho Python 3.3 và 3,4, và không được dùng trong Python 3.6.
pip install -r requirements.txt
0 was the recommended tool for creating virtual environments for Python 3.3 and 3.4, and is deprecated in Python 3.6.

Thay đổi trong phiên bản 3.5: Việc sử dụng

cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
8 hiện được khuyến nghị để tạo môi trường ảo.The use of
cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
8 is now recommended for creating virtual environments.

Trên Windows, gọi lệnh

cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
8 như sau:

c:\>c:\Python35\python -m venv c:\path\to\myenv

Ngoài ra, nếu bạn đã cấu hình các biến

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
2 và
pip install -r requirements.txt
4 cho cài đặt Python của bạn:Python installation:

c:\>python -m venv c:\path\to\myenv

Lệnh, nếu chạy với

pip install -r requirements.txt
5, sẽ hiển thị các tùy chọn có sẵn:

usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
            [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

optional arguments:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system
                        site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks
                        are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when
                        symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it
                        already exists, before environment creation.
  --upgrade             Upgrade the environment directory to use this version
                        of Python, assuming Python has been upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual
                        environment (pip is bootstrapped by default)
  --prompt PROMPT       Provides an alternative prompt prefix for this
                        environment.
  --upgrade-deps        Upgrade core dependencies: pip setuptools to the
                        latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.

Đã thay đổi trong phiên bản 3.9: Thêm tùy chọn

pip install -r requirements.txt
6 để nâng cấp PIP + setuptools lên mới nhất trên PYPIAdd
pip install -r requirements.txt
6 option to upgrade pip + setuptools to the latest on PyPI

Đã thay đổi trong phiên bản 3.4: Cài đặt PIP theo mặc định, đã thêm các tùy chọn

pip install -r requirements.txt
7 và
pip install -r requirements.txt
8Installs pip by default, added the
pip install -r requirements.txt
7 and
pip install -r requirements.txt
8 options

Đã thay đổi trong phiên bản 3.4: Trong các phiên bản trước, nếu thư mục đích đã tồn tại, lỗi đã được nêu ra, trừ khi tùy chọn

pip install -r requirements.txt
9 hoặc
python3 -m venv /path/to/new/virtual/environment
0 được cung cấp.In earlier versions, if the target directory already existed, an error was raised, unless the
pip install -r requirements.txt
9 or
python3 -m venv /path/to/new/virtual/environment
0 option was provided.

Ghi chú

Mặc dù các liên kết symlink được hỗ trợ trên Windows, nhưng chúng không được khuyến khích. Đặc biệt lưu ý là việc nhấp đúp vào

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
3 trong File Explorer sẽ giải quyết Symlink một cách háo hức và bỏ qua môi trường ảo.

Ghi chú

Mặc dù các liên kết symlink được hỗ trợ trên Windows, nhưng chúng không được khuyến khích. Đặc biệt lưu ý là việc nhấp đúp vào

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
3 trong File Explorer sẽ giải quyết Symlink một cách háo hức và bỏ qua môi trường ảo.

Trên Microsoft Windows, có thể cần phải bật tập lệnh

python3 -m venv /path/to/new/virtual/environment
2 bằng cách đặt chính sách thực thi cho người dùng. Bạn có thể làm điều này bằng cách ban hành lệnh PowerShell sau:

PS C:> Set -ExecutionPolicy -executpolicy RemoteSign -scope CurrentUser

Xem về chính sách thực thi để biết thêm thông tin.

Tệp

pip freeze > requirements.txt
3 được tạo cũng bao gồm khóa
python3 -m venv /path/to/new/virtual/environment
4, được đặt thành
python3 -m venv /path/to/new/virtual/environment
5 nếu
cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
8 được chạy với tùy chọn
python3 -m venv /path/to/new/virtual/environment
7,
python3 -m venv /path/to/new/virtual/environment
8 nếu không.

Trừ khi tùy chọn

pip install -r requirements.txt
7 được đưa ra,
c:\>c:\Python35\python -m venv c:\path\to\myenv
0 sẽ được gọi cho bootstrap
cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
4 vào môi trường ảo.

Nhiều đường dẫn có thể được đưa ra cho cd my-project virtualenv --python C:\Path\To\Python\python.exe venv 8, trong trường hợp đó, một môi trường ảo giống hệt nhau sẽ được tạo ra, theo các tùy chọn đã cho, tại mỗi đường dẫn được cung cấp.

Cách VENVS hoạt động trong đó

Khi một thông dịch viên Python chạy từ môi trường ảo,

c:\>c:\Python35\python -m venv c:\path\to\myenv
3 và
c:\>c:\Python35\python -m venv c:\path\to\myenv
4 chỉ ra các thư mục của môi trường ảo, trong khi
c:\>c:\Python35\python -m venv c:\path\to\myenv
5 và
c:\>c:\Python35\python -m venv c:\path\to\myenv
6 chỉ ra các thư mục của Python cơ sở được sử dụng để tạo ra môi trường. Nó là đủ để kiểm tra
c:\>c:\Python35\python -m venv c:\path\to\myenv
7 để xác định xem trình thông dịch hiện tại có chạy từ môi trường ảo hay không.!python will invoke the environment’s Python interpreter and you can run installed scripts without having to use their full path. The invocation of the activation script is platform-specific (
c:\>python -m venv c:\path\to\myenv
1 must be replaced by the path to the directory containing the virtual environment):

Nền tảng

Vỏ bọc

Lệnh để kích hoạt môi trường ảo

Posix

bash/zsh

c:\>python -m venv c:\path\to\myenv
2

c:\>python -m venv c:\path\to\myenv
3

csh/tcsh

c:\>python -m venv c:\path\to\myenv
4

Powershell

c:\>python -m venv c:\path\to\myenv
5

các cửa sổ

cmd.exe

c:\>python -m venv c:\path\to\myenv
6

Powershell

c:\>python -m venv c:\path\to\myenv
7

các cửa sổ!fish and !csh activation scripts.

Mới trong Phiên bản 3.4:! Cá và! Các kịch bản kích hoạt CSH.PowerShell activation scripts installed under POSIX for PowerShell Core support.

Mới trong phiên bản 3.8: Các tập lệnh kích hoạt PowerShell được cài đặt theo POSIX cho hỗ trợ Core PowerShell.

Bạn không cần phải kích hoạt một môi trường ảo, vì bạn chỉ có thể chỉ định đường dẫn đầy đủ đến môi trường đó là phiên dịch viên Python Python khi gọi Python. Hơn nữa, tất cả các tập lệnh được cài đặt trong môi trường nên được chạy mà không cần kích hoạt nó.Python Launcher for Windows installed. Thus, double-clicking an installed script in a Windows Explorer window should run it with the correct interpreter without the environment needing to be activated or on the

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
2.

Để đạt được điều này, các tập lệnh được cài đặt vào các môi trường ảo, có một dòng Shebang Shebang, chỉ vào môi trường phiên dịch Python Python, tức là

c:\>python -m venv c:\path\to\myenv
8. Điều này có nghĩa là tập lệnh sẽ chạy với trình thông dịch đó bất kể giá trị của
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
2. Trên Windows, xử lý dòng Shebang Shebang được hỗ trợ nếu bạn đã cài đặt trình khởi chạy Python cho Windows. Do đó, nhấp đúp vào một tập lệnh được cài đặt trong cửa sổ Windows Explorer sẽ chạy nó với trình thông dịch chính xác mà không cần môi trường cần được kích hoạt hoặc trên
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
2.

Khi một môi trường ảo đã được kích hoạt, biến môi trường

usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
            [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

optional arguments:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system
                        site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks
                        are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when
                        symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it
                        already exists, before environment creation.
  --upgrade             Upgrade the environment directory to use this version
                        of Python, assuming Python has been upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual
                        environment (pip is bootstrapped by default)
  --prompt PROMPT       Provides an alternative prompt prefix for this
                        environment.
  --upgrade-deps        Upgrade core dependencies: pip setuptools to the
                        latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.
1 được đặt thành đường dẫn của môi trường. Vì kích hoạt rõ ràng một môi trường ảo không bắt buộc phải sử dụng nó,
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
            [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

optional arguments:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system
                        site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks
                        are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when
                        symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it
                        already exists, before environment creation.
  --upgrade             Upgrade the environment directory to use this version
                        of Python, assuming Python has been upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual
                        environment (pip is bootstrapped by default)
  --prompt PROMPT       Provides an alternative prompt prefix for this
                        environment.
  --upgrade-deps        Upgrade core dependencies: pip setuptools to the
                        latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.
1 không thể dựa vào để xác định xem một môi trường ảo có được sử dụng hay không.

Cảnh báo

Bởi vì các tập lệnh được cài đặt trong môi trường không nên mong đợi môi trường được kích hoạt, các dòng shebang của chúng chứa các đường dẫn tuyệt đối đến các phiên dịch viên môi trường của họ. Bởi vì điều này, môi trường vốn đã không thể thực thể, trong trường hợp chung. Bạn nên luôn có một phương tiện đơn giản để tái tạo môi trường (ví dụ: nếu bạn có tệp yêu cầu

cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
6, bạn có thể gọi
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
            [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

optional arguments:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system
                        site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks
                        are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when
                        symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it
                        already exists, before environment creation.
  --upgrade             Upgrade the environment directory to use this version
                        of Python, assuming Python has been upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual
                        environment (pip is bootstrapped by default)
  --prompt PROMPT       Provides an alternative prompt prefix for this
                        environment.
  --upgrade-deps        Upgrade core dependencies: pip setuptools to the
                        latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.
4 bằng môi trường
cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
4 để cài đặt tất cả các gói cần thiết cho môi trường). Nếu vì bất kỳ lý do gì bạn cần di chuyển môi trường đến một địa điểm mới, bạn nên tạo lại nó tại vị trí mong muốn và xóa vị trí tại vị trí cũ. Nếu bạn di chuyển một môi trường vì bạn đã di chuyển một thư mục cha mẹ về nó, bạn nên tạo lại môi trường ở vị trí mới của nó. Mặt khác, phần mềm được cài đặt vào môi trường có thể không hoạt động như mong đợi.

Bạn có thể hủy kích hoạt một môi trường ảo bằng cách nhập cd my-project virtualenv --python C:\Path\To\Python\python.exe venv 7 vào vỏ của bạn. Cơ chế chính xác là đặc trưng cho nền tảng và là một chi tiết triển khai nội bộ (thông thường, chức năng tập lệnh hoặc shell sẽ được sử dụng).

Api¶

Phương pháp cấp cao được mô tả ở trên sử dụng API đơn giản cung cấp các cơ chế cho người tạo môi trường ảo của bên thứ ba để tùy chỉnh tạo môi trường theo nhu cầu của họ, lớp
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
            [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

optional arguments:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system
                        site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks
                        are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when
                        symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it
                        already exists, before environment creation.
  --upgrade             Upgrade the environment directory to use this version
                        of Python, assuming Python has been upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual
                        environment (pip is bootstrapped by default)
  --prompt PROMPT       Provides an alternative prompt prefix for this
                        environment.
  --upgrade-deps        Upgrade core dependencies: pip setuptools to the
                        latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.
7.
venv.EnvBuilder(system_site_packages=False, clear=False, symlinks=False, upgrade=False, with_pip=False, prompt=None, upgrade_deps=False)

classvenv.envbuilder (System_site_packages = false

  • Lớp

    usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
                [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
                ENV_DIR [ENV_DIR ...]
    
    Creates virtual Python environments in one or more target directories.
    
    positional arguments:
      ENV_DIR               A directory to create the environment in.
    
    optional arguments:
      -h, --help            show this help message and exit
      --system-site-packages
                            Give the virtual environment access to the system
                            site-packages dir.
      --symlinks            Try to use symlinks rather than copies, when symlinks
                            are not the default for the platform.
      --copies              Try to use copies rather than symlinks, even when
                            symlinks are the default for the platform.
      --clear               Delete the contents of the environment directory if it
                            already exists, before environment creation.
      --upgrade             Upgrade the environment directory to use this version
                            of Python, assuming Python has been upgraded in-place.
      --without-pip         Skips installing or upgrading pip in the virtual
                            environment (pip is bootstrapped by default)
      --prompt PROMPT       Provides an alternative prompt prefix for this
                            environment.
      --upgrade-deps        Upgrade core dependencies: pip setuptools to the
                            latest version in PyPI
    
    Once an environment has been created, you may wish to activate it, e.g. by
    sourcing an activate script in its bin directory.
    
    7 chấp nhận các đối số từ khóa sau khi khởi tạo:

  • usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
                [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
                ENV_DIR [ENV_DIR ...]
    
    Creates virtual Python environments in one or more target directories.
    
    positional arguments:
      ENV_DIR               A directory to create the environment in.
    
    optional arguments:
      -h, --help            show this help message and exit
      --system-site-packages
                            Give the virtual environment access to the system
                            site-packages dir.
      --symlinks            Try to use symlinks rather than copies, when symlinks
                            are not the default for the platform.
      --copies              Try to use copies rather than symlinks, even when
                            symlinks are the default for the platform.
      --clear               Delete the contents of the environment directory if it
                            already exists, before environment creation.
      --upgrade             Upgrade the environment directory to use this version
                            of Python, assuming Python has been upgraded in-place.
      --without-pip         Skips installing or upgrading pip in the virtual
                            environment (pip is bootstrapped by default)
      --prompt PROMPT       Provides an alternative prompt prefix for this
                            environment.
      --upgrade-deps        Upgrade core dependencies: pip setuptools to the
                            latest version in PyPI
    
    Once an environment has been created, you may wish to activate it, e.g. by
    sourcing an activate script in its bin directory.
    
    9-Giá trị Boolean chỉ ra rằng các gói trang web Python của hệ thống nên có sẵn cho môi trường (mặc định là
    def create(self, env_dir):
        """
        Create a virtualized Python environment in a directory.
        env_dir is the target directory to create an environment in.
        """
        env_dir = os.path.abspath(env_dir)
        context = self.ensure_directories(env_dir)
        self.create_configuration(context)
        self.setup_python(context)
        self.setup_scripts(context)
        self.post_setup(context)
    
    0).

  • def create(self, env_dir):
        """
        Create a virtualized Python environment in a directory.
        env_dir is the target directory to create an environment in.
        """
        env_dir = os.path.abspath(env_dir)
        context = self.ensure_directories(env_dir)
        self.create_configuration(context)
        self.setup_python(context)
        self.setup_scripts(context)
        self.post_setup(context)
    
    1 - Một giá trị boolean, nếu đúng, sẽ xóa nội dung của bất kỳ thư mục đích hiện có nào, trước khi tạo môi trường.

  • def create(self, env_dir):
        """
        Create a virtualized Python environment in a directory.
        env_dir is the target directory to create an environment in.
        """
        env_dir = os.path.abspath(env_dir)
        context = self.ensure_directories(env_dir)
        self.create_configuration(context)
        self.setup_python(context)
        self.setup_scripts(context)
        self.post_setup(context)
    
    2 - Một giá trị boolean cho biết có nên cố gắng liên kết nhị phân Python thay vì sao chép hay không.

  • def create(self, env_dir):
        """
        Create a virtualized Python environment in a directory.
        env_dir is the target directory to create an environment in.
        """
        env_dir = os.path.abspath(env_dir)
        context = self.ensure_directories(env_dir)
        self.create_configuration(context)
        self.setup_python(context)
        self.setup_scripts(context)
        self.post_setup(context)
    
    3 - một giá trị boolean, nếu đúng, sẽ nâng cấp một môi trường hiện có với python đang chạy - để sử dụng khi con trăn đó đã được nâng cấp tại chỗ (mặc định là
    def create(self, env_dir):
        """
        Create a virtualized Python environment in a directory.
        env_dir is the target directory to create an environment in.
        """
        env_dir = os.path.abspath(env_dir)
        context = self.ensure_directories(env_dir)
        self.create_configuration(context)
        self.setup_python(context)
        self.setup_scripts(context)
        self.post_setup(context)
    
    0).

  • def create(self, env_dir):
        """
        Create a virtualized Python environment in a directory.
        env_dir is the target directory to create an environment in.
        """
        env_dir = os.path.abspath(env_dir)
        context = self.ensure_directories(env_dir)
        self.create_configuration(context)
        self.setup_python(context)
        self.setup_scripts(context)
        self.post_setup(context)
    
    5 - Một giá trị boolean, nếu đúng, đảm bảo PIP được cài đặt trong môi trường ảo. Điều này sử dụng
    c:\>c:\Python35\python -m venv c:\path\to\myenv
    
    0 với tùy chọn
    def create(self, env_dir):
        """
        Create a virtualized Python environment in a directory.
        env_dir is the target directory to create an environment in.
        """
        env_dir = os.path.abspath(env_dir)
        context = self.ensure_directories(env_dir)
        self.create_configuration(context)
        self.setup_python(context)
        self.setup_scripts(context)
        self.post_setup(context)
    
    7.

  • def create(self, env_dir):
        """
        Create a virtualized Python environment in a directory.
        env_dir is the target directory to create an environment in.
        """
        env_dir = os.path.abspath(env_dir)
        context = self.ensure_directories(env_dir)
        self.create_configuration(context)
        self.setup_python(context)
        self.setup_scripts(context)
        self.post_setup(context)
    
    8 - Một chuỗi được sử dụng sau khi môi trường ảo được kích hoạt (mặc định là
    def create(self, env_dir):
        """
        Create a virtualized Python environment in a directory.
        env_dir is the target directory to create an environment in.
        """
        env_dir = os.path.abspath(env_dir)
        context = self.ensure_directories(env_dir)
        self.create_configuration(context)
        self.setup_python(context)
        self.setup_scripts(context)
        self.post_setup(context)
    
    9 có nghĩa là tên thư mục của môi trường sẽ được sử dụng). Nếu chuỗi đặc biệt
    C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    00 được cung cấp, tên cơ sở của thư mục hiện tại được sử dụng làm dấu nhắc.

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
01 - Cập nhật các mô -đun VEN cơ sở lên mới nhất trên PYPIAdded the
def create(self, env_dir):
    """
    Create a virtualized Python environment in a directory.
    env_dir is the target directory to create an environment in.
    """
    env_dir = os.path.abspath(env_dir)
    context = self.ensure_directories(env_dir)
    self.create_configuration(context)
    self.setup_python(context)
    self.setup_scripts(context)
    self.post_setup(context)
5 parameter

Đã thay đổi trong phiên bản 3.4: Đã thêm tham số

def create(self, env_dir):
    """
    Create a virtualized Python environment in a directory.
    env_dir is the target directory to create an environment in.
    """
    env_dir = os.path.abspath(env_dir)
    context = self.ensure_directories(env_dir)
    self.create_configuration(context)
    self.setup_python(context)
    self.setup_scripts(context)
    self.post_setup(context)
5Added the
def create(self, env_dir):
    """
    Create a virtualized Python environment in a directory.
    env_dir is the target directory to create an environment in.
    """
    env_dir = os.path.abspath(env_dir)
    context = self.ensure_directories(env_dir)
    self.create_configuration(context)
    self.setup_python(context)
    self.setup_scripts(context)
    self.post_setup(context)
8 parameter

Mới trong phiên bản 3.6: Đã thêm tham số

def create(self, env_dir):
    """
    Create a virtualized Python environment in a directory.
    env_dir is the target directory to create an environment in.
    """
    env_dir = os.path.abspath(env_dir)
    context = self.ensure_directories(env_dir)
    self.create_configuration(context)
    self.setup_python(context)
    self.setup_scripts(context)
    self.post_setup(context)
8Added the
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
01 parameter

Mới trong phiên bản 3.9: Đã thêm tham số

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
01

Người tạo ra các công cụ môi trường ảo của bên thứ ba sẽ được tự do sử dụng lớp

usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
            [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

optional arguments:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system
                        site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks
                        are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when
                        symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it
                        already exists, before environment creation.
  --upgrade             Upgrade the environment directory to use this version
                        of Python, assuming Python has been upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual
                        environment (pip is bootstrapped by default)
  --prompt PROMPT       Provides an alternative prompt prefix for this
                        environment.
  --upgrade-deps        Upgrade core dependencies: pip setuptools to the
                        latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.
7 được cung cấp làm lớp cơ sở.

Env-Builder được trả lại là một đối tượng có phương thức,
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
06:
(env_dir)

tạo (env_dir) ¶

Phương pháp

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
06 của lớp
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
            [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

optional arguments:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system
                        site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks
                        are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when
                        symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it
                        already exists, before environment creation.
  --upgrade             Upgrade the environment directory to use this version
                        of Python, assuming Python has been upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual
                        environment (pip is bootstrapped by default)
  --prompt PROMPT       Provides an alternative prompt prefix for this
                        environment.
  --upgrade-deps        Upgrade core dependencies: pip setuptools to the
                        latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.
7 minh họa các móc có sẵn để tùy chỉnh lớp con:

def create(self, env_dir):
    """
    Create a virtualized Python environment in a directory.
    env_dir is the target directory to create an environment in.
    """
    env_dir = os.path.abspath(env_dir)
    context = self.ensure_directories(env_dir)
    self.create_configuration(context)
    self.setup_python(context)
    self.setup_scripts(context)
    self.post_setup(context)

Mỗi phương thức

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
10,
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
11,
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
12,
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
13 và
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
14 có thể được ghi đè.

Đảm bảo_directories (env_dir) ¶(env_dir)

Tạo thư mục môi trường và tất cả các thư mục con cần thiết đã không tồn tại và trả về một đối tượng ngữ cảnh. Đối tượng bối cảnh này chỉ là một người giữ cho các thuộc tính (như đường dẫn) để sử dụng bởi các phương thức khác. Nếu

usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
            [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

optional arguments:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system
                        site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks
                        are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when
                        symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it
                        already exists, before environment creation.
  --upgrade             Upgrade the environment directory to use this version
                        of Python, assuming Python has been upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual
                        environment (pip is bootstrapped by default)
  --prompt PROMPT       Provides an alternative prompt prefix for this
                        environment.
  --upgrade-deps        Upgrade core dependencies: pip setuptools to the
                        latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.
7 được tạo bằng Arg
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
16, nội dung của thư mục môi trường sẽ được xóa và sau đó tất cả các thư mục con cần thiết sẽ được tái tạo.

Đối tượng bối cảnh được trả về là

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
17 với các thuộc tính sau:

  • C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    18 - Vị trí của môi trường ảo. Được sử dụng cho
    C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    19 trong các tập lệnh kích hoạt (xem
    C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    20).

  • C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    21 - Tên của môi trường ảo. Được sử dụng cho
    C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    22 trong các tập lệnh kích hoạt (xem
    C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    20).

  • def create(self, env_dir):
        """
        Create a virtualized Python environment in a directory.
        env_dir is the target directory to create an environment in.
        """
        env_dir = os.path.abspath(env_dir)
        context = self.ensure_directories(env_dir)
        self.create_configuration(context)
        self.setup_python(context)
        self.setup_scripts(context)
        self.post_setup(context)
    
    8 - Lời nhắc được sử dụng bởi các tập lệnh kích hoạt. Được sử dụng cho
    C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    25 trong các tập lệnh kích hoạt (xem
    C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    20).

  • C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    27 - Python cơ bản có thể thực thi được sử dụng bởi môi trường ảo. Điều này có tính đến trường hợp môi trường ảo được tạo ra từ một môi trường ảo khác.

  • C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    28 - Đường dẫn bao gồm môi trường ảo.

  • C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    29 - Đường dẫn Purelib cho môi trường ảo.

  • C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    30 - Đường dẫn tập lệnh cho môi trường ảo.

  • C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    31 - Tên của đường dẫn tập lệnh liên quan đến vị trí môi trường ảo. Được sử dụng cho
    C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    32 trong các tập lệnh kích hoạt (xem
    C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    20).

  • C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    34 - Tên của trình thông dịch Python trong môi trường ảo. Được sử dụng cho
    C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    35 trong các tập lệnh kích hoạt (xem
    C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    20).

  • C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    37 - Tên của trình thông dịch Python, có tài khoản chuyển hướng hệ thống tập tin. Điều này có thể được sử dụng để chạy Python trong môi trường ảo.

Thay đổi trong phiên bản 3.12: Thuộc tính

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
29 đã được thêm vào ngữ cảnh và đối tượng ngữ cảnh đã được ghi lại.The attribute
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
29 was added to the context, and the context object was documented.

Thay đổi trong phiên bản 3.11: Sơ đồ cài đặt SYSConfig VETV được sử dụng để xây dựng các đường dẫn của các thư mục được tạo.The venv sysconfig installation scheme is used to construct the paths of the created directories.

created_configuration (bối cảnh) ¶(context)

Tạo tệp cấu hình

pip freeze > requirements.txt
3 trong môi trường.

setup_python (bối cảnh) ¶(context)

Tạo một bản sao hoặc Symlink cho Python thực thi trong môi trường. Trên các hệ thống POSIX, nếu một

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
40 thực thi cụ thể được sử dụng, các liên kết symlink thành
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
41 và
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
42 sẽ được tạo chỉ vào việc thực thi đó, trừ khi các tệp có tên đó đã tồn tại.

setup_scripts (bối cảnh) ¶(context)

Cài đặt các tập lệnh kích hoạt phù hợp với nền tảng vào môi trường ảo.

nâng cấp_dependencies (bối cảnh) ¶(context)

Nâng cấp các gói phụ thuộc VEN Core (hiện tại

cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
4 và
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
44) trong môi trường. Điều này được thực hiện bằng cách bắn ra
cd my-project
virtualenv --python C:\Path\To\Python\python.exe venv
4 có thể thực thi trong môi trường.

Mới trong phiên bản 3.9.

post_setup (bối cảnh) ¶(context)

Một phương thức giữ chỗ có thể được ghi đè trong các triển khai của bên thứ ba để cài đặt sẵn các gói trong môi trường ảo hoặc thực hiện các bước sau sáng tạo khác.

Đã thay đổi trong phiên bản 3.7.2: Windows hiện sử dụng các tập lệnh chuyển hướng cho

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
46 thay vì sao chép các nhị phân thực tế. Trong 3.7.2, chỉ
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
12 không làm gì trừ khi chạy từ bản dựng trong cây nguồn.Windows now uses redirector scripts for
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
46 instead of copying the actual binaries. In 3.7.2 only
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
12 does nothing unless running from a build in the source tree.

Đã thay đổi trong phiên bản 3.7.3: Windows sao chép các tập lệnh chuyển hướng như một phần của

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
12 thay vì
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
13. Đây không phải là trường hợp trong 3.7.2. Khi sử dụng SymLinks, các tệp thực thi ban đầu sẽ được liên kết.Windows copies the redirector scripts as part of
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
12 instead of
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
13. This was not the case in 3.7.2. When using symlinks, the original executables will be linked.

Ngoài ra,

usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
            [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

optional arguments:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system
                        site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks
                        are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when
                        symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it
                        already exists, before environment creation.
  --upgrade             Upgrade the environment directory to use this version
                        of Python, assuming Python has been upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual
                        environment (pip is bootstrapped by default)
  --prompt PROMPT       Provides an alternative prompt prefix for this
                        environment.
  --upgrade-deps        Upgrade core dependencies: pip setuptools to the
                        latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.
7 cung cấp phương thức tiện ích này có thể được gọi từ
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
13 hoặc
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
14 trong các lớp con để hỗ trợ cài đặt các tập lệnh tùy chỉnh vào môi trường ảo.

install_scripts (bối cảnh, đường dẫn) ¶(context, path)

Đường dẫn là đường dẫn đến một thư mục nên chứa các thư mục con phổ biến, thì Poss, thì, NT NT, mỗi tập lệnh có các tập lệnh dành cho thư mục bin trong môi trường. Nội dung của Common Common và thư mục tương ứng với

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
53 được sao chép sau khi thay thế văn bản của các chủ lưu chỗ:

  • C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    19 được thay thế bằng đường dẫn tuyệt đối của thư mục môi trường.

  • C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    22 được thay thế bằng tên môi trường (phân đoạn đường dẫn cuối cùng của thư mục môi trường).

  • C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    25 được thay thế bằng lời nhắc (tên môi trường được bao quanh bởi dấu ngoặc đơn và với một không gian sau)

  • C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    32 được thay thế bằng tên của thư mục bin (hoặc
    pip freeze > requirements.txt
    
    6 hoặc
    C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    7).

  • C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
    
    35 được thay thế bằng con đường tuyệt đối của môi trường có thể thực thi.

Các thư mục được phép tồn tại (vì khi một môi trường hiện tại đang được nâng cấp).

Ngoài ra còn có chức năng tiện lợi cấp độ mô-đun:

venv.create (env_dir, system_site_packages = false, rõ ràng = false, symlinks = false, with_pip = falsecreate(env_dir, system_site_packages=False, clear=False, symlinks=False, with_pip=False, prompt=None, upgrade_deps=False)

Tạo một

usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
            [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

optional arguments:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system
                        site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks
                        are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when
                        symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it
                        already exists, before environment creation.
  --upgrade             Upgrade the environment directory to use this version
                        of Python, assuming Python has been upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual
                        environment (pip is bootstrapped by default)
  --prompt PROMPT       Provides an alternative prompt prefix for this
                        environment.
  --upgrade-deps        Upgrade core dependencies: pip setuptools to the
                        latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.
7 với các đối số từ khóa đã cho và gọi phương thức
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
62 của nó với đối số env_dir.

Mới trong phiên bản 3.3.

Đã thay đổi trong phiên bản 3.4: Đã thêm tham số

def create(self, env_dir):
    """
    Create a virtualized Python environment in a directory.
    env_dir is the target directory to create an environment in.
    """
    env_dir = os.path.abspath(env_dir)
    context = self.ensure_directories(env_dir)
    self.create_configuration(context)
    self.setup_python(context)
    self.setup_scripts(context)
    self.post_setup(context)
5Added the
def create(self, env_dir):
    """
    Create a virtualized Python environment in a directory.
    env_dir is the target directory to create an environment in.
    """
    env_dir = os.path.abspath(env_dir)
    context = self.ensure_directories(env_dir)
    self.create_configuration(context)
    self.setup_python(context)
    self.setup_scripts(context)
    self.post_setup(context)
5 parameter

Đã thay đổi trong phiên bản 3.6: Đã thêm tham số

def create(self, env_dir):
    """
    Create a virtualized Python environment in a directory.
    env_dir is the target directory to create an environment in.
    """
    env_dir = os.path.abspath(env_dir)
    context = self.ensure_directories(env_dir)
    self.create_configuration(context)
    self.setup_python(context)
    self.setup_scripts(context)
    self.post_setup(context)
8Added the
def create(self, env_dir):
    """
    Create a virtualized Python environment in a directory.
    env_dir is the target directory to create an environment in.
    """
    env_dir = os.path.abspath(env_dir)
    context = self.ensure_directories(env_dir)
    self.create_configuration(context)
    self.setup_python(context)
    self.setup_scripts(context)
    self.post_setup(context)
8 parameter

Đã thay đổi trong phiên bản 3.9: Đã thêm tham số

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
01Added the
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
01 parameter

Một ví dụ về việc mở rộng ________ 87¶

Tập lệnh sau đây cho thấy cách mở rộng

usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
            [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

optional arguments:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system
                        site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks
                        are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when
                        symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it
                        already exists, before environment creation.
  --upgrade             Upgrade the environment directory to use this version
                        of Python, assuming Python has been upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual
                        environment (pip is bootstrapped by default)
  --prompt PROMPT       Provides an alternative prompt prefix for this
                        environment.
  --upgrade-deps        Upgrade core dependencies: pip setuptools to the
                        latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.
7 bằng cách triển khai một lớp con cài đặt setuptools và pip vào môi trường ảo được tạo:

C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
0

Kịch bản này cũng có sẵn để tải xuống trực tuyến.

Làm cách nào để kích hoạt môi trường trong Python?

Outline..
Mở một thiết bị đầu cuối ..
Thiết lập trình quản lý gói PIP ..
Cài đặt gói VirtualEnv ..
Tạo môi trường ảo ..
Kích hoạt môi trường ảo ..
Vô hiệu hóa môi trường ảo ..
Tùy chọn: Làm cho môi trường ảo thành con trăn mặc định của bạn ..
Thêm: Tài liệu Virtualenv của Python ..

Làm cách nào để mở môi trường ảo Python trong CMD?

Tạo các môi trường ảo được thực hiện bằng cách thực hiện lệnh Venv:..
python3 -m venv/path/to/new/ảo/môi trường ..
C: \> C: \ python35 \ python -m venv c: \ path \ to \ myenv ..
C: \> python -m venv c: \ path \ to \ myenv ..

Môi trường Python nằm ở đâu?

Các môi trường được tạo ra bởi Conda luôn được đặt trong /users /.../anaconda3/envs/.Bạn có thể thay đổi vị trí mặc định bằng cách sử dụng lệnh sau nhưng nó không được khuyến khích./Users/.../anaconda3/envs/ . You may change the default location by using the following command but it is not encouraged.