Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaeb15f1

Browse files
authored
Merge pull requestwilfredinni#31 from Sonatrix/master
Add setup.py introduction
2 parents00a087a +bea13f1 commitaeb15f1

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

‎blog_files/pysheet.md‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3879,7 +3879,7 @@ A module can discover whether or not it is running in the main scope by checking
38793879
... main()
38803880
```
38813881

3882-
For a package, the same effect can be achieved by including a __main__.py module, the contents of which will be executed when the moduleis runwith-m
3882+
For a package, the same effect can be achieved by including a __main__.py module, the contents of which will be executed when the moduleis runwith-m.
38833883

38843884
For example we are developing script whichis designed to be usedas module, we should do:
38853885

@@ -3907,6 +3907,35 @@ For example we are developing script which is designed to be used as module, we
39073907
3. Python files can actas either reusable modules,oras standalone programs.
39083908
4.if`__name__== “main”:`is used to execute some code onlyif thefile was run directly,andnot imported.
39093909

3910+
## setup.py
3911+
3912+
The setup scriptis the centre ofall activityin building, distributing,and installing modules using the Distutils. The main purpose of the setup scriptis to describe your module distribution to the Distutils, so that the various commands that operate on your modules do the right thing.
3913+
3914+
The`setup.py`fileis at the heart of a Python project. It describesall of the metadata about your project. There a quite a few fields you can add to a project to give it a richset of metadata describing the project. However, there are only three required fields: name, version,and packages. The name field must be uniqueif you wish to publish your package on the Python Package Index (PyPI). The version field keeps track of different releases of the project. The packages field describes where you’ve put the Python source code within your project.
3915+
3916+
This allows you to easily install Python packages. Often it's enough to write:
3917+
3918+
```
3919+
$ python setup.py install
3920+
```
3921+
3922+
and module will install itself.
3923+
3924+
Our initial setup.py will also include information about thelicenseand will re-use theREADME.txtfilefor the long_description field. This will look like:
3925+
3926+
```python
3927+
>>>from distutils.coreimport setup
3928+
>>> setup(
3929+
...name='pythonCheatsheet',
3930+
...version='0.1',
3931+
...packages=['pipenv',],
3932+
...license='MIT',
3933+
...long_description=open('README.txt').read(),
3934+
... )
3935+
```
3936+
3937+
Find more information visit http://docs.python.org/install/index.html.
3938+
39103939
## Virtual Environment
39113940

39123941
The use of a Virtual Environmentis to test python codein encapsulated environmentsand to also avoid filling the base Python installationwith libraries we might usefor only one project.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp