Python3 environment construction
In this chapter, we will show you how to build a Python3 development environment locally.
Python3 is available on multiple platforms including Windows, Linux and Mac OS X.
-
Unix (Solaris, Linux, FreeBSD, AIX, HP/UX, SunOS, IRIX, etc.)
-
Win9x/NT/2000
-
Macintosh (Intel, PPC, 68K)
-
OS/2
-
DOS (multiple DOS versions)
-
PalmOS
-
Nokia mobile phones
-
Windows CE
-
Acorn/RISC OS
-
BeOS
-
Amiga
-
VMS/OpenVMS
-
QNX
-
VxWorks
-
Psion
-
Python is also portable to Java and .NET virtual machines.
Python3 download
The latest source code, binary documentation, news information, etc. of Python3 can be viewed on Python's official website:
Python official website: https://www.python.org/
You can download the documentation for Python at the link below, you can download the documentation in HTML, PDF and PostScript formats.
Python documentation download address: https://www.python.org/doc/
Python installation
Python has been ported to many platforms (modified to work on different platforms).
You'll need to download the binaries for the platform you're using, then install Python.
If binaries for your platform are not available, you will need to manually compile the source code using a C compiler.
Compiled source code, which is more selective in functionality, provides more flexibility for Python installations.
The following is the download address of the installation package for each platform:
Source Code is available for installation on Linux.
Here's how to install Python3 on different platforms.
Install Python3 on Unix & Linux platforms:
Here are the simple steps to install Python on Unix & Linux platforms:
-
Open a web browser and visit https://www.python.org/downloads/source/
-
Choose the source tarball for Unix/Linux.
-
Download and decompress the compressed package Python-3.xxtgz , where 3.xx is the corresponding version number you downloaded.
-
If you need to customize some options modify Modules/Setup
Take Python 3.6.1 version as an example:
# tar -zxvf Python-3.6.1.tgz # cd Python-3.6.1 # ./configure # make && make install
Check if Python3 is available normally:
# python3 -V Python 3.6.1
Install Python on Windows platform:
Following are the simple steps to install Python on Window platform.
Open the WEB browser to visit https://www.python.org/downloads/windows/, generally download the executable installer, x86 means 32-bit machine, x86-64 means 64-bit machine.
Remember to check Add Python 3.6 to PATH .
Press Win+R , enter cmd to bring up the command prompt, enter python:
You can also search for IDLE in the start menu :
Install Python on the MAC platform:
The MAC system comes with a Python2.7 environment, you can download the latest version and install Python 3.x at the link https://www.python.org/downloads/mac-osx/.
You can also refer to the source installation method to install.
Environment variable configuration
Programs and executables can be in many directories that are most likely not in the search path for executables provided by the operating system.
path is stored in an environment variable, which is a named string maintained by the operating system. These variables contain information about available command line interpreters and other programs.
The path variable in Unix or Windows is PATH (UNIX is case sensitive, Windows is not).
In Mac OS, the installation path of python is changed during the installer. If you need to reference Python in another directory, you must add the Python directory to the path.
Setting environment variables on Unix/Linux
-
In the csh shell: enter
setenv PATH "$PATH:/usr/local/bin/python"
, press Enter .
-
Type in bash shell (Linux):
export PATH = "$PATH:/usr/local/bin/python"
Press Enter .
-
In sh or ksh shell type:
PATH = "$PATH:/usr/local/bin/python"
Press Enter.
Note: /usr/local/bin/python is the directory where Python is installed.
Setting environment variables on Windows
Add the Python directory to the environment variables:
In the command prompt box (cmd): enter
path =% path %; C : \Python
Press "Enter".
Note: C:\Python is the Python installation directory.
It can also be set by:
-
Right-click on "Computer" and then click on "Properties"
-
Then click on "Advanced System Settings"
-
Select "Path" under the "System Variables" window and double-click!
-
-
Then in the "Path" line, add the python installation path (my D:\Python32), so in the back, add the path. ps: Remember, the paths are directly separated by semicolons ";"!
-
After the final setting is successful, in the cmd command line, enter the command "python", you can have the relevant display.
Python environment variables
The following important environment variables apply to Python:
variable name | describe |
---|---|
PYTHONPATH | PYTHONPATH is the Python search path. By default, the modules we import will be searched from PYTHONPATH. |
PYTHONSTARTUP | After Python starts, it first looks for the PYTHONSTARTUP environment variable, and then executes the code in the file specified by this variable. |
PYTHONCASEOK | Adding the PYTHONCASEOK environment variable will make python case-insensitive when importing modules. |
PYTHONHOME | Another module search path. It is usually embedded in the PYTHONSTARTUP or PYTHONPATH directory, making it easier to switch between the two module libraries. |
run Python
There are three ways to run Python:
1. Interactive interpreter:
You can enter python through the command line window and start writing Python code in the interactive interpreter.
You can work with python coding on Unix, DOS, or any other system that provides a command line or shell.
$ python # Unix/Linux
or
C:>python # Windows/DOS
The following are the Python command line arguments:
Options | describe |
---|---|
-d | Display debug information while parsing |
-O | Generate optimized code ( .pyo file ) |
-S | Do not introduce where to look for Python paths at startup |
-V | Output Python version number |
-X | Built-in exceptions (for strings only) have been deprecated since version 1.6. |
-c cmd | Execute a Python script and get the result of the run as a cmd string. |
file | Execute a python script in the given python file. |
2. Command line script
You can execute Python scripts on the command line by introducing an interpreter into your application, as follows:
$ python script.py # Unix/Linux
or
C:>python script.py # Windows/DOS
Note: When executing the script, please check if the script has executable permission.
3. IDE: Integrated Development Environment: PyCharm
PyCharm is a Python IDE created by JetBrains that supports macOS, Windows, and Linux systems.
PyCharm features: debugging, syntax highlighting, project management, code jumping, smart prompts, auto-completion, unit testing, version control...
PyCharm download address: https://www.jetbrains.com/pycharm/download/
PyCharm installation address: http://www.runoob.com/w3cnote/pycharm-windows-install.html