easy_install python拡張機能を使用すると、次のようにコンソールからpythoneggをインストールできます。
easy_install py2app
しかし、Pythonスクリプト内でeasy_install機能にアクセスすることは可能ですか?つまり、os.system( "easy_install py2app")を呼び出さずに、代わりにeasy_installをPythonモジュールとしてインポートし、そのネイティブメソッドを使用しますか?
easy_install python拡張機能を使用すると、次のようにコンソールからpythoneggをインストールできます。
easy_install py2app
しかし、Pythonスクリプト内でeasy_install機能にアクセスすることは可能ですか?つまり、os.system( "easy_install py2app")を呼び出さずに、代わりにeasy_installをPythonモジュールとしてインポートし、そのネイティブメソッドを使用しますか?
セットアップツールのソースを見ると、次のことができるように見えます。
from setuptools.command import easy_install
easy_install.main( ["-U","py2app"] )
from setuptools.command import easy_install
def install_with_easyinstall(package):
easy_install.main(["-U", package]).
install_with_easyinstall('py2app')
具体的に何をしようとしていますか?奇妙な要件がない限り、setup.pyでパッケージを依存関係として宣言することをお勧めします。
from setuptools import setup, find_packages
setup(
name = "HelloWorld",
version = "0.1",
packages = find_packages(),
scripts = ['say_hello.py'],
# Project uses reStructuredText, so ensure that the docutils get
# installed or upgraded on the target machine
install_requires = ['docutils>=0.3'],
package_data = {
# If any package contains *.txt or *.rst files, include them:
'': ['*.txt', '*.rst'],
# And include any *.msg files found in the 'hello' package, too:
'hello': ['*.msg'],
}
# metadata for upload to PyPI
author = "Me",
author_email = "me@example.com",
description = "This is an Example Package",
license = "PSF",
keywords = "hello world example examples",
url = "http://example.com/HelloWorld/", # project home page, if any
# could also include long_description, download_url, classifiers, etc.
)
ここでの重要な行はですinstall_requires = ['docutils>=0.3']
。これにより、ユーザーが特に指定しない限り、setup.pyファイルがこの依存関係を自動的にインストールします。これに関するその他のドキュメントはここにあります(setuptoolsのWebサイトは非常に遅いことに注意してください!)。
この方法では満たすことができないある種の要件がある場合は、おそらくS.Lottの答えを確認する必要があります(私はそれを自分で試したことはありませんが)。
呼び出しについての答えsetuptools.main()
は正しいです。ただし、setuptoolsが.eggを作成する場合、スクリプトはモジュールのインストール後にモジュールをインポートできません。卵はPythonの開始時にsys.pathに自動的に追加されます。
1つの解決策は、require()を使用して新しいeggをパスに追加することです。
from setuptools.command import easy_install
import pkg_resources
easy_install.main( ['mymodule'] )
pkg_resources.require('mymodule')
いずれかのインポートsetuptoolsを使用することでそれを達成できると思います。