Py 5
Py 5
"
# greet.py
import hello
hello.say_hello()
# greet.py
say_hello()
# greet.py
import hello as ai
ai.say_hello()
# run_hello.py
if __name__ == '__main__':
say_hello()
Run it!
$ python run_hello.py
=> "Hello!"
If the module is inside a directory and needs to be detected by python, the directory should contain
a file named
__init__.py.
Note: Following instructions are written for Python 2.7 (unless specified): instructions for Python 3.x
are
similar.
Windows
First, download the latest version of Python 2.7 from the official Website
(https://www.python.org/downloads/).
Version is provided as an MSI package. To install it manually, just double-click the file.
By default, Python installs to a directory:
C:\Python27\
Warning: installation does not automatically modify the PATH environment variable.
Assuming that your Python installation is in C:\Python27, add this to your PATH:
C:\Python27\;C:\Python27\Scripts\
python --version
To install and use both Python 2.x and 3.x side-by-side on a Windows machine:
Optional: add Python to PATH to make Python 2.x callable from the command-line using python.
Optional: add Python to PATH to make Python 3.x callable from the command-line using python. This
may override Python 2.x PATH settings, so double-check your PATH and ensure it's configured to your
preferences.
Python 3 will install the Python launcher which can be used to launch Python 2.x and Python 3.x
interchangeably
P:\>py -3
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
>>>
C:\>py -2
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 Intel)] on win32
>>>
To use the corresponding version of pip for a specific Python version, use:
C:\>py -3 -m pip -V
C:\>py -2 -m pip -V
Linux
The latest versions of CentOS, Fedora, Red Hat Enterprise (RHEL) and Ubuntu come with Python 2.7.
cd Python-2.7.X
./configure