Đây là giải pháp tôi đặt cùng nhau mà tôi gọi là pyInstall.py
. Nó thực sự kiểm tra xem mô -đun có được cài đặt thay vì dựa vào
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
0 [theo ý kiến của tôi, nó trông sạch hơn, để xử lý việc này với from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
1 thay vì ________ 12/________ 13].Tôi đã sử dụng nó theo phiên bản 2.6 và 2.7 ... nó có thể sẽ hoạt động trong các phiên bản cũ hơn nếu tôi không muốn xử lý
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
4 như một chức năng ... và tôi nghĩ nó sẽ hoạt động trong phiên bản 3.0+ nhưng tôi chưa bao giờ thử.Ngoài ra, như tôi lưu ý trong các bình luận của hàm
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
5 của tôi, tôi không nghĩ rằng chức năng cụ thể đó sẽ hoạt động theo OS X.from __future__ import print_function
from subprocess import call
def installPip[log=print]:
"""
Pip is the standard package manager for Python. Starting with Python 3.4
it's included in the default installation, but older versions may need to
download and install it. This code should pretty cleanly do just that.
"""
log["Installing pip, the standard Python Package Manager, first"]
from os import remove
from urllib import urlretrieve
urlretrieve["//bootstrap.pypa.io/get-pip.py", "get-pip.py"]
call[["python", "get-pip.py"]]
# Clean up now...
remove["get-pip.py"]
def getPip[log=print]:
"""
Pip is the standard package manager for Python.
This returns the path to the pip executable, installing it if necessary.
"""
from os.path import isfile, join
from sys import prefix
# Generate the path to where pip is or will be installed... this has been
# tested and works on Windows, but will likely need tweaking for other OS's.
# On OS X, I seem to have pip at /usr/local/bin/pip?
pipPath = join[prefix, 'Scripts', 'pip.exe']
# Check if pip is installed, and install it if it isn't.
if not isfile[pipPath]:
installPip[log]
if not isfile[pipPath]:
raise["Failed to find or install pip!"]
return pipPath
def installIfNeeded[moduleName, nameOnPip=None, notes="", log=print]:
""" Installs a Python library using pip, if it isn't already installed. """
from pkgutil import iter_modules
# Check if the module is installed
if moduleName not in [tuple_[1] for tuple_ in iter_modules[]]:
log["Installing " + moduleName + notes + " Library for Python"]
call[[getPip[log], "install", nameOnPip if nameOnPip else moduleName]]
Dưới đây là một số ví dụ sử dụng:
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
EDIT: Một cách nhận pippath đa nền tảng hơn là:: A more cross-platform way of getting pipPath is:
from subprocess import Popen, PIPE
finder = Popen[['where' if isWindows[] else 'which', 'pip'], stdout = PIPE, stderr = PIPE]
pipPath = finder.communicate[][0].strip[]
Điều này làm cho giả định rằng
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
6 là/sẽ được cài đặt trên đường dẫn hệ thống. Nó có xu hướng khá đáng tin cậy trên các nền tảng không phải Windows, nhưng trên Windows, có thể tốt hơn là sử dụng mã trong câu trả lời ban đầu của tôi. distutils-sig@python.org@python.org
Là một dự án phát triển nguồn mở phổ biến, Python có một cộng đồng người đóng góp và người dùng hỗ trợ tích cực cũng cung cấp phần mềm của họ cho các nhà phát triển Python khác sử dụng theo các điều khoản cấp phép nguồn mở.
Điều này cho phép người dùng Python chia sẻ và hợp tác hiệu quả, được hưởng lợi từ các giải pháp mà những người khác đã tạo ra cho các vấn đề phổ biến [và đôi khi thậm chí hiếm!], Cũng như có khả năng đóng góp các giải pháp của riêng họ cho nhóm chung.
Hướng dẫn này bao gồm phần cài đặt của quá trình. Để biết hướng dẫn tạo và chia sẻ các dự án Python của riêng bạn, hãy tham khảo Hướng dẫn phân phối.distribution guide.
Ghi chú
Đối với các công ty và người dùng tổ chức khác, hãy lưu ý rằng nhiều tổ chức có chính sách riêng của họ xung quanh việc sử dụng và đóng góp cho phần mềm nguồn mở. Vui lòng tính đến các chính sách như vậy khi sử dụng các công cụ phân phối và cài đặt được cung cấp với Python.
Điều khoản quan trọng¶
7 là chương trình trình cài đặt ưa thích. Bắt đầu với Python 3.4, nó được bao gồm theo mặc định với các trình cài đặt nhị phân Python.from datetime import datetime from pyInstall import installIfNeeded # I like to have my messages timestamped so I can get an idea of how long they take. def log[message]: print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]] # The name fabric doesn't really convey to the end user why the module is needed, # so I include a very quick note that it's used for SSH. installIfNeeded["fabric", notes = " [ssh]", log = log] # SoftLayer is actually named softlayer on pip. installIfNeeded["SoftLayer", "softlayer", log = log]
Môi trường ảo là môi trường Python bán phân lập cho phép các gói được cài đặt để sử dụng để sử dụng bởi một ứng dụng cụ thể, thay vì được cài đặt rộng hệ thống.
8 là công cụ tiêu chuẩn để tạo môi trường ảo và là một phần của Python kể từ Python 3.3. Bắt đầu với Python 3.4, mặc định cài đặtfrom datetime import datetime from pyInstall import installIfNeeded # I like to have my messages timestamped so I can get an idea of how long they take. def log[message]: print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]] # The name fabric doesn't really convey to the end user why the module is needed, # so I include a very quick note that it's used for SSH. installIfNeeded["fabric", notes = " [ssh]", log = log] # SoftLayer is actually named softlayer on pip. installIfNeeded["SoftLayer", "softlayer", log = log]
7 vào tất cả các môi trường ảo được tạo.from datetime import datetime from pyInstall import installIfNeeded # I like to have my messages timestamped so I can get an idea of how long they take. def log[message]: print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]] # The name fabric doesn't really convey to the end user why the module is needed, # so I include a very quick note that it's used for SSH. installIfNeeded["fabric", notes = " [ssh]", log = log] # SoftLayer is actually named softlayer on pip. installIfNeeded["SoftLayer", "softlayer", log = log]
0 là sự thay thế của bên thứ ba [và tiền thân] thànhfrom subprocess import Popen, PIPE finder = Popen[['where' if isWindows[] else 'which', 'pip'], stdout = PIPE, stderr = PIPE] pipPath = finder.communicate[][0].strip[]
8. Nó cho phép các môi trường ảo được sử dụng trên các phiên bản của Python trước 3.4, mà không phải là don cung cấpfrom datetime import datetime from pyInstall import installIfNeeded # I like to have my messages timestamped so I can get an idea of how long they take. def log[message]: print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]] # The name fabric doesn't really convey to the end user why the module is needed, # so I include a very quick note that it's used for SSH. installIfNeeded["fabric", notes = " [ssh]", log = log] # SoftLayer is actually named softlayer on pip. installIfNeeded["SoftLayer", "softlayer", log = log]
8, hoặc aren có thể tự động cài đặtfrom datetime import datetime from pyInstall import installIfNeeded # I like to have my messages timestamped so I can get an idea of how long they take. def log[message]: print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]] # The name fabric doesn't really convey to the end user why the module is needed, # so I include a very quick note that it's used for SSH. installIfNeeded["fabric", notes = " [ssh]", log = log] # SoftLayer is actually named softlayer on pip. installIfNeeded["SoftLayer", "softlayer", log = log]
7 vào các môi trường được tạo.from datetime import datetime from pyInstall import installIfNeeded # I like to have my messages timestamped so I can get an idea of how long they take. def log[message]: print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]] # The name fabric doesn't really convey to the end user why the module is needed, # so I include a very quick note that it's used for SSH. installIfNeeded["fabric", notes = " [ssh]", log = log] # SoftLayer is actually named softlayer on pip. installIfNeeded["SoftLayer", "softlayer", log = log]
Chỉ số gói Python là một kho lưu trữ công khai của các gói được cấp phép nguồn mở được cung cấp để sử dụng bởi những người dùng Python khác.
Cơ quan bao bì Python là nhóm các nhà phát triển và tác giả tài liệu chịu trách nhiệm bảo trì và phát triển các công cụ đóng gói tiêu chuẩn và các tiêu chuẩn định dạng tệp và siêu dữ liệu liên quan. Họ duy trì một loạt các công cụ, tài liệu và trình theo dõi phát hành trên cả GitHub và Bitbucket.
4 là hệ thống xây dựng và phân phối ban đầu lần đầu tiên được thêm vào thư viện tiêu chuẩn Python vào năm 1998. Mặc dù việc sử dụng trực tiếpfrom subprocess import Popen, PIPE finder = Popen[['where' if isWindows[] else 'which', 'pip'], stdout = PIPE, stderr = PIPE] pipPath = finder.communicate[][0].strip[]
4 đang được loại bỏ, nó vẫn đặt nền tảng cho cơ sở hạ tầng đóng gói và phân phối hiện tại và nó không chỉ là một phần của tiêu chuẩn Thư viện, nhưng tên của nó tồn tại theo những cách khác [chẳng hạn như tên của danh sách gửi thư được sử dụng để phối hợp phát triển tiêu chuẩn bao bì Python].from subprocess import Popen, PIPE finder = Popen[['where' if isWindows[] else 'which', 'pip'], stdout = PIPE, stderr = PIPE] pipPath = finder.communicate[][0].strip[]
Thay đổi trong phiên bản 3.5: Việc sử dụng
8 hiện được khuyến nghị để tạo môi trường ảo.The use of from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
8 is now recommended for creating virtual environments.Cách sử dụng cơ bản
Các công cụ đóng gói tiêu chuẩn đều được thiết kế để sử dụng từ dòng lệnh.
Lệnh sau đây sẽ cài đặt phiên bản mới nhất của một mô -đun và các phụ thuộc của nó từ chỉ mục gói Python:
python -m pip install SomePackage
Ghi chú
Đối với người dùng POSIX [bao gồm cả người dùng MacOS và Linux], các ví dụ trong hướng dẫn này giả định việc sử dụng môi trường ảo.virtual environment.
Đối với người dùng Windows, các ví dụ trong hướng dẫn này giả định rằng tùy chọn điều chỉnh biến môi trường đường dẫn hệ thống đã được chọn khi cài đặt Python.
Nó cũng có thể chỉ định một phiên bản chính xác hoặc tối thiểu trực tiếp trên dòng lệnh. Khi sử dụng các toán tử so sánh như
from subprocess import Popen, PIPE
finder = Popen[['where' if isWindows[] else 'which', 'pip'], stdout = PIPE, stderr = PIPE]
pipPath = finder.communicate[][0].strip[]
7, from subprocess import Popen, PIPE
finder = Popen[['where' if isWindows[] else 'which', 'pip'], stdout = PIPE, stderr = PIPE]
pipPath = finder.communicate[][0].strip[]
8 hoặc một số ký tự đặc biệt khác được giải thích bởi shell, tên gói và phiên bản phải được đặt trong các trích dẫn kép:python -m pip install SomePackage==1.0.4 # specific version python -m pip install "SomePackage>=1.0.4" # minimum version
Thông thường, nếu một mô -đun phù hợp đã được cài đặt, cố gắng cài đặt lại sẽ không có hiệu lực. Nâng cấp các mô -đun hiện có phải được yêu cầu một cách rõ ràng:
python -m pip install --upgrade SomePackage
Thêm thông tin và tài nguyên liên quan đến
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
7 và các khả năng của nó có thể được tìm thấy trong Hướng dẫn sử dụng bao bì Python.Tạo các môi trường ảo được thực hiện thông qua mô -đun
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
8. Cài đặt các gói vào một môi trường ảo hoạt động sử dụng các lệnh được hiển thị ở trên.Làm thế nào để tôi …?¶
Đây là những câu trả lời nhanh hoặc liên kết cho một số nhiệm vụ phổ biến.
Cài đặt from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
7 trong các phiên bản của Python trước Python 3.4?
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
Python chỉ bắt đầu bó
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
7 với Python 3.4. Đối với các phiên bản trước đó, from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
7 cần phải là Bootstrapping, như được mô tả trong Hướng dẫn sử dụng bao bì Python.Các gói cài đặt chỉ dành cho người dùng hiện tại? ¶
Chuyển tùy chọn
python -m pip install SomePackage4 cho
python -m pip install SomePackage5 sẽ cài đặt gói chỉ cho người dùng hiện tại, thay vì cho tất cả người dùng của hệ thống.
Lắp đặt các gói Python khoa học? ¶
Một số gói Python khoa học có các phụ thuộc nhị phân phức tạp và hiện tại rất dễ cài đặt bằng cách sử dụng
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
7 trực tiếp. Tại thời điểm này, người dùng thường sẽ dễ dàng cài đặt các gói này bằng các phương tiện khác thay vì cố gắng cài đặt chúng với from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
7.Làm việc với nhiều phiên bản Python được cài đặt song song? ¶
Trên Linux, MacOS và các hệ thống POSIX khác, sử dụng các lệnh Python được phiên bản kết hợp với công tắc
python -m pip install SomePackage8 để chạy bản sao thích hợp của
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
7:python2 -m pip install SomePackage # default Python 2 python2.7 -m pip install SomePackage # specifically Python 2.7 python3 -m pip install SomePackage # default Python 3 python3.4 -m pip install SomePackage # specifically Python 3.4
Các lệnh
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
7 được phiên bản thích hợp cũng có thể có sẵn.Trên Windows, hãy sử dụng Trình khởi chạy Python
python -m pip install SomePackage==1.0.4 # specific version python -m pip install "SomePackage>=1.0.4" # minimum version1 kết hợp với công tắc
python -m pip install SomePackage8:
py -2 -m pip install SomePackage # default Python 2 py -2.7 -m pip install SomePackage # specifically Python 2.7 py -3 -m pip install SomePackage # default Python 3 py -3.4 -m pip install SomePackage # specifically Python 3.4
Các vấn đề cài đặt phổ biến
Cài đặt vào Python hệ thống trên Linux¶
Trên các hệ thống Linux, việc cài đặt Python thường sẽ được đưa vào như một phần của phân phối. Cài đặt vào cài đặt Python này yêu cầu truy cập gốc vào hệ thống và có thể can thiệp vào hoạt động của Trình quản lý gói hệ thống và các thành phần khác của hệ thống nếu một thành phần được nâng cấp bất ngờ bằng cách sử dụng
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
7.Trên các hệ thống như vậy, thường tốt hơn là sử dụng môi trường ảo hoặc cài đặt mỗi người dùng khi cài đặt các gói với
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
7.Pip chưa được cài đặt
Có thể là
from datetime import datetime
from pyInstall import installIfNeeded
# I like to have my messages timestamped so I can get an idea of how long they take.
def log[message]:
print[datetime.now[].strftime["%a %b %d %H:%M:%S"] + " - " + str[message]]
# The name fabric doesn't really convey to the end user why the module is needed,
# so I include a very quick note that it's used for SSH.
installIfNeeded["fabric", notes = " [ssh]", log = log]
# SoftLayer is actually named softlayer on pip.
installIfNeeded["SoftLayer", "softlayer", log = log]
7 không được cài đặt theo mặc định. Một sửa chữa tiềm năng là:python -m ensurepip --default-pip
Ngoài ra còn có các tài nguyên bổ sung để cài đặt PIP.
Cài đặt phần mở rộng nhị phân
Python thường phụ thuộc rất nhiều vào phân phối dựa trên nguồn, với người dùng cuối được dự kiến sẽ biên dịch các mô -đun mở rộng từ nguồn như là một phần của quy trình cài đặt.
Với việc giới thiệu hỗ trợ cho định dạng nhị phân
python -m pip install SomePackage==1.0.4 # specific version python -m pip install "SomePackage>=1.0.4" # minimum version6 và khả năng xuất bản bánh xe cho ít nhất Windows và MacOS thông qua chỉ số gói Python, vấn đề này dự kiến sẽ giảm theo thời gian, vì người dùng thường xuyên có thể cài đặt các tiện ích mở rộng được xây dựng sẵn trước hơn thay vì cần phải tự xây dựng chúng.
Một số giải pháp để cài đặt phần mềm khoa học chưa có sẵn vì các tệp
python -m pip install SomePackage==1.0.4 # specific version python -m pip install "SomePackage>=1.0.4" # minimum version6 được xây dựng trước cũng có thể giúp thu được các phần mở rộng nhị phân khác mà không cần phải xây dựng chúng tại địa phương.