home PYTHONJAVA
 

Python3 Environmental build

In this chapter we will show you how to build a Python3 development environment locally.

Python 3 can be applied to multiple platforms including Windows, Linux, and Mac OS X.

  • Unix (Solaris, Linux, FreeBSD, AIX, HP/UX, SunOS, IRIX, etc.)
  • Win 9x/NT/2000
  • Macintosh (Intel, PPC, 68K)
  • OS/2
  • DOS (multiple DOS versions)
  • PalmOS
  • Nokia mobile phone
  • Windows CE
  • Acorn/RISC OS
  • BeOS
  • Amiga
  • VMS/OpenVMS
  • QNX
  • VxWorks
  • Psion
  • Python can also be ported to Java and .NET virtual machines.


Python3 Download

Python3's latest source code, binary documentation, news, etc. can be viewed on Python's official website:

Python official website: https://www.python.org/

>

You can download Python documentation from the links below, and you can download documents in formats such as HTML, PDF, and PostScript.

Python documentation download address: https://www.python.org/doc/



Python installation

Python has been ported to many platforms (it has been modified to work on different platforms).

You need to download the binary code for your platform and install Python.

If your platform's binary code is not available, you will need to manually compile the source code using the C compiler.

Compiled source code, with more optional features, provides more flexibility for Python installations.

Source Code is available for installation on Linux.

Here are the ways to install Python3 on different platforms.

Unix & Linux Platform Installation Python3:

Here are the simple steps to install Python on Unix & Linux:

  • Open a web browser to access https://www.python.org/downloads /source/
  • Select a source tarball for Unix/Linux.
  • Download and unzip the zip file Python-3.x.x.tgz, 3.x.x for the corresponding version number you downloaded.
  • If you need to customize some options to modify Modules/Setup

Use the 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:

# python3 -V
Python 3.6 .1

Window platform installation Python:

Here are the simple steps to install Python on the Window platform.

Open the web browser to access https://www.python.org/downloads /windows/ , generally download executable installer, x86 means 32-bit machine, x86-64 means 64-bit machine.

MAC Platform Installation Python:

The MAC system comes with a Python 2.7 environment, you can link Download the latest version of Python 3.x at https://www.python.org/downloads/mac-osx/.

You can also install it by referring to the way the source is installed.



Environment Variable Configuration

Programs and executables can be in many directories, and these paths are most likely not in the search path where the operating system provides executable files.

path is stored in an environment variable, which is a named string maintained by the operating system. These variables contain information about the available command line interpreters and other programs.

The path variable in Unix or Windows is PATH (UNIX is case sensitive and Windows is not case sensitive).

In Mac OS, the installation path of python was changed during the installation process. If you need to reference Python in other directories, you must add the Python directory to the path.

Set environment variables on Unix/Linux

Python environment variable

The following important environment variables apply to Python:

Variable NameDescription
PYTHONPATH PYTHONPATH is the Python search path. By default, the modules we import will be searched from PYTHONPATH.
PYTHONSTARTUP After Python starts, look for the PYTHONSTARTUP environment variable and then execute the code in the file specified by this variable.
PYTHONCASEOK Adding PYTHONCASEOK environment variables will make python import case insensitive.
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 go to python through the command line window and start writing Python code in the interactive interpreter.

You can do python encoding 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 Python command line arguments:

OptionsDescription
-dShow debug information when parsing
-OGenerate optimized code ( .pyo file )
-SDo not introduce a location to find the Python path at startup
-VOutput Python version number
-X Built-in exceptions (only for strings) since version 1.6 are obsolete.
-c cmd Execute the Python script and run the result as a cmd string.
file Execute a python script in a given python file.

Run Python3 program in Cloud Studio

The 3.0 version of Python, often referred to as Python3000, or Py3k for short. This is a larger upgrade than the previous version of Python. In order not to introduce too much cumbersome, Python 3.0 was not designed to be backward compatible. Many programs designed for earlier versions of Python are not working properly on Python 3.0. The Python development environment that Cloud Studio provides for us is the Python version 2.7. The following steps will allow you to run a program written in Python3 on Cloud Studio

  • step1: Sign in to Tencent Cloud Developer Platform, select PHP + Python + Java development environment, at this time, I see the terminal input command python --version can see that the currently used python interpreter version is 2.7.12

  • step2: Install Python3, execute the command, install Python3 and see if the interpreter works.
sudo apt-get install python3
Python3 --version





welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.