setup.py는 무엇입니까?
누구든지 설명해 주시겠습니까, 무엇 setup.py
이며 어떻게 구성하거나 사용할 수 있습니까?
setup.py
일반적으로 설치하려는 모듈 / 패키지가 Python 모듈 배포를위한 표준 인 Distutils와 함께 패키징 및 배포되었음을 알려주는 python 파일입니다.
이를 통해 Python 패키지를 쉽게 설치할 수 있습니다. 종종 다음과 같이 작성하는 것으로 충분합니다.
$ pip install .
pip
setup.py를 사용하여 모듈을 설치합니다. setup.py
직접 전화하지 마십시오 .
https://docs.python.org/3/installing/index.html#installing-index
다른 프로젝트와 [I] Python 프롬프트에서 패키지 를 가져올 수 있도록 foo
컴퓨터 (에있을 수도 있음 virtualenv
) 에 python 패키지를 설치하면 도움이 foo
됩니다.
그것은의 유사한 작업 수행 pip
, easy_install
등
사용 setup.py
몇 가지 정의부터 시작하겠습니다.
패키지 - __init__.py
파일 이 포함 된 폴더 / 디렉토리입니다 .
모듈 - .py
확장자가 있는 유효한 파이썬 파일입니다 .
배포 -한 패키지 가 다른 패키지 및 모듈 과 관련되는 방식 .
라는 패키지를 설치한다고 가정 해 보겠습니다 foo
. 그럼 당신은
$ git clone https://github.com/user/foo
$ cd foo
$ python setup.py install
대신 실제로 설치하고 싶지는 않지만 여전히 사용하고 싶다면. 그런 다음
$ python setup.py develop
이 명령은 물건을 복사하는 대신 사이트 패키지 내의 소스 디렉토리에 대한 심볼릭 링크를 만듭니다. 이로 인해 매우 빠릅니다 (특히 대형 패키지의 경우).
생성 setup.py
패키지 트리가 다음과 같은 경우
foo
├── foo
│ ├── data_struct.py
│ ├── __init__.py
│ └── internals.py
├── README
├── requirements.txt
└── setup.py
그런 다음 setup.py
스크립트 에서 다음을 수행하여 일부 시스템에 설치할 수 있습니다.
from setuptools import setup
setup(
name='foo',
version='1.0',
description='A useful module',
author='Man Foo',
author_email='foomail@foo.com',
packages=['foo'], #same as name
install_requires=['bar', 'greek'], #external packages as dependencies
)
대신 패키지 트리가 아래와 같이 더 복잡한 경우 :
foo
├── foo
│ ├── data_struct.py
│ ├── __init__.py
│ └── internals.py
├── README
├── requirements.txt
├── scripts
│ ├── cool
│ └── skype
└── setup.py
그러면 setup.py
이 경우 다음 과 같습니다.
from setuptools import setup
setup(
name='foo',
version='1.0',
description='A useful module',
author='Man Foo',
author_email='foomail@foo.com',
packages=['foo'], #same as name
install_requires=['bar', 'greek'], #external packages as dependencies
scripts=[
'scripts/cool',
'scripts/skype',
]
)
( setup.py
)에 더 많은 항목을 추가 하고 적절하게 만드십시오.
from setuptools import setup
with open("README", 'r') as f:
long_description = f.read()
setup(
name='foo',
version='1.0',
description='A useful module',
license="MIT",
long_description=long_description,
author='Man Foo',
author_email='foomail@foo.com',
url="http://www.foopackage.com/",
packages=['foo'], #same as name
install_requires=['bar', 'greek'], #external packages as dependencies
scripts=[
'scripts/cool',
'scripts/skype',
]
)
이 long_description
사용된다 pypi.org 패키지의 README 설명한다.
마지막으로, 이제 다른 사람들 이 .NET을 사용하여 패키지를 설치할 수 있도록 PyPi.org에 패키지를 업로드 할 준비가되었습니다 pip install yourpackage
.
첫 번째 단계는 다음을 사용하여 pypi에서 패키지 이름과 공간을 요청하는 것입니다.
$ python setup.py register
패키지 이름이 등록되면 누구도이를 청구하거나 사용할 수 없습니다. 성공적으로 등록한 후에는 다음 방법으로 패키지를 클라우드에 업로드해야합니다.
$ python setup.py upload
선택적으로 다음과 같이 패키지에 서명 할 수도 있습니다 GPG
.
$ python setup.py --sign upload
보너스 : setup.py
여기에서 실제 프로젝트 의 샘플 을 확인하세요.torchvision-setup.py
setup.py
is Python's answer to a multi-platform installer and make
file.
If you’re familiar with command line installations, then make && make install
translates to python setup.py build && python setup.py install
.
Some packages are pure Python, and are only byte compiled. Others may contain native code, which will require a native compiler (like gcc
or cl
) and a Python interfacing module (like swig
or pyrex
).
If you downloaded package that has "setup.py" in root folder, you can install it by running
python setup.py install
If you are developing a project and are wondering what this file is useful for, check Python documentation on writing the Setup Script
setup.py
is a Python script that is usually shipped with libraries or programs, written in that language. It's purpose is the correct installation of the software.
Many packages use the distutils
framework in conjuction with setup.py
.
http://docs.python.org/distutils/
setup.py can be used in two scenarios , First, you want to install a Python package. Second, you want to create your own Python package. Usually standard Python package has couple of important files like setup.py, setup.cfg and Manifest.in. When you are creating the Python package, these three files will determine the (content in PKG-INFO under egg-info folder) name, version, description, other required installations (usually in .txt file) and few other parameters. setup.cfg is read by setup.py while package is created (could be tar.gz ). Manifest.in is where you can define what should be included in your package. Anyways you can do bunch of stuff using setup.py like
python setup.py build
python setup.py install
python setup.py sdist <distname> upload [-r urltorepo] (to upload package to pypi or local repo)
There are bunch of other commands which could be used with setup.py . for help
python setup.py --help-commands
When you download a package with setup.py
open your Terminal (Mac,Linux) or Command Prompt (Windows). Using cd
and helping you with Tab button set the path right to the folder where you have downloaded the file and where there is setup.py
:
iMac:~ user $ cd path/pakagefolderwithsetupfile/
Press enter, you should see something like this:
iMac:pakagefolderwithsetupfile user$
Then type after this python setup.py install
:
iMac:pakagefolderwithsetupfile user$ python setup.py install
Press enter
. Done!
To install a Python package you've downloaded, you extract the archive and run the setup.py script inside:
python setup.py install
To me, this has always felt odd. It would be more natural to point a package manager at the download, as one would do in Ruby and Nodejs, eg. gem install rails-4.1.1.gem
A package manager is more comfortable too, because it's familiar and reliable. On the other hand, each setup.py
is novel, because it's specific to the package. It demands faith in convention "I trust this setup.py takes the same commands as others I have used in the past". That's a regrettable tax on mental willpower.
I'm not saying the setup.py workflow is less secure than a package manager (I understand Pip just runs the setup.py inside), but certainly I feel it's awkard and jarring. There's a harmony to commands all being to the same package manager application. You might even grow fond it.
setup.py
is a Python file like any other. It can take any name, except by convention it is named setup.py
so that there is not a different procedure with each script.
Most frequently setup.py
is used to install a Python module but server other purposes:
Modules:
Perhaps this is most famous usage of setup.py
is in modules. Although they can be installed using pip
, old Python versions did not include pip
by default and they needed to be installed separately.
If you wanted to install a module but did not want to install pip
, just about the only alternative was to install the module from setup.py
file. This could be achieved via python setup.py install
. This would install the Python module to the root dictionary (without pip
, easy_install
ect).
This method is often used when pip
will fail. For example if the correct Python version of the desired package is not available via pip
perhaps because it is no longer maintained, , downloading the source and running python setup.py install
would perform the same thing, except in the case of compiled binaries are required, (but will disregard the Python version -unless an error is returned).
Another use of setup.py
is to install a package from source. If a module is still under development the wheel files will not be available and the only way to install is to install from the source directly.
Building Python extensions:
When a module has been built it can be converted into module ready for distribution using a distutils setup script. Once built these can be installed using the command above.
A setup script is easy to build and once the file has been properly configured and can be compiled by running python setup.py build
(see link for all commands).
Once again it is named setup.py
for ease of use and by convention, but can take any name.
Cython:
Another famous use of setup.py
files include compiled extensions. These require a setup script with user defined values. They allow fast (but once compiled are platform dependant) execution. Here is a simple example from the documentation:
from distutils.core import setup
from Cython.Build import cythonize
setup(
name = 'Hello world app',
ext_modules = cythonize("hello.pyx"),
)
This can be compiled via python setup.py build
Cx_Freeze:
Another module requiring a setup script is cx_Freeze
. This converts Python script to executables. This allows many commands such as descriptions, names, icons, packages to include, exclude ect and once run will produce a distributable application. An example from the documentation:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "guifoo",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("guifoo.py", base=base)])
This can be compiled via python setup.py build
.
So what is a setup.py
file?
Quite simply it is a script that builds or configures something in the Python environment.
A package when distributed should contain only one setup script but it is not uncommon to combine several together into a single setup script. Notice this often involves distutils
but not always (as I showed in my last example). The thing to remember it just configures Python package/script in some way.
It takes the name so the same command can always be used when building or installing.
To make it simple, setup.py is run as "__main__"
when you call the install functions the other answers mentioned. Inside setup.py, you should put everything needed to install your package.
Common setup.py functions
The following two sections discuss two things many setup.py modules have.
setuptools.setup
This function allows you to specify project attributes like the name of the project, the version.... Most importantly, this function allows you to install other functions if they're packaged properly. See this webpage for an example of setuptools.setup
These attributes of setuptools.setup enable installing these types of packages:
Packages that are imported to your project and listed in PyPI using setuptools.findpackages:
packages=find_packages(exclude=["docs","tests", ".gitignore", "README.rst","DESCRIPTION.rst"])
Packages not in PyPI, but can be downloaded from a URL using dependency_links
dependency_links=["http://peak.telecommunity.com/snapshots/",]
Custom functions
In an ideal world, setuptools.setup
would handle everything for you. Unfortunately this isn't always the case. Sometimes you have to do specific things, like installing dependencies with the subprocess command, to get the system you're installing on in the right state for your package. Try to avoid this, these functions get confusing and often differ between OS and even distribution.
참고URL : https://stackoverflow.com/questions/1471994/what-is-setup-py
'Nice programing' 카테고리의 다른 글
NaN 값을 어떻게 확인할 수 있습니까? (0) | 2020.09.28 |
---|---|
오류-IIS 메타베이스에 액세스 할 수 없습니다. (0) | 2020.09.28 |
"무작위성"이해 (0) | 2020.09.28 |
AngularJS : $ scope. $ apply () 호출시 이미 진행중인 $ digest 오류 방지 (0) | 2020.09.28 |
줄거리에서 범례를 제거하는 방법 (0) | 2020.09.28 |