[Python learning] two, using platform Python on Linux

Source: Internet
Author: User
Tags gtk virtual environment

In this section, it describes how Linux uses platform python


1. Python installation.

Today, most of the Python's own version number, it cannot be installed. Suppose you want to install it, you can use the appropriate installation instructions.

Fedora: Log in as Root first. Execute yum Install python

Ubuntu System: User in the root group, execute sudo apt-get install python


2. The Python script used

Linux is a file-based system, so what is the Python file we use?

This can be achieved by command: which Python

For example, this is the result on my computer.

# which Python
/usr/bin/python

Since there is the presence of this directive. It also means that there may be more than one Python environment on the system.

What I am encountering now is the use of a miniature framework flask. It reconstructs a python in-house, adding a lot of functionality that you need.

In this case, it is possible to create a virtual environment through VIRTUALENV. In this virtual environment, call yourself python.


So when writing a Python program and unsure of the Python path, you can write

#/usr/bin/env python

It's up to the system to decide which python


3. python file Run

This is the same script as most parts. There are two ways of doing this. Example of a file with a test.py

A. Python test.py

Run directly

B. chmod a+x test.py

./test.py

Become executable and run


4. Use of Python instructions

Since 3. A can see that python can be said to be Linux inside the instructions. So what are the ways to use it? This can be obtained through Python--help or man python. is not similar to all Linux instructions.

For now, I'm more often using python-v to get the Python version number. The version number is a very important issue in Python programming. Be sure to focus on your own invocation or whether the use method is supported for the version number you are using.

By looking at this user manual. Be able to find that Python can add a lot of parameters when running a file or command, and you can use it according to your needs.


5. Python-Programmed environment variables

There are many environment variables in Python. Among the more important are:

Pythonhome: Represents the location of Python

Location of the Pythonpath:python library

Others can take the test https://docs.python.org/2/using/cmdline.html

Among them Pythonhome can be obtained by which Python

Pythonpath is able to get through Sys.path the following is an interesting experiment

The steps to experiment with Pythonpath on my computer are as follows

[Email protected] ~]$ export pythonpath=/home/linxj/downloads/
[[email protected] ~]$ python
Python 2.7.3 (Default, 9 2012, 17:23:58)
[GCC 4.7.1 20120720 (Red Hat 4.7.1-5)] on linux2
Type "Help", "copyright", "credits" or "license" for more information.
>>> Import Sys
>>> Sys.path
[', '/home/linxj/downloads ', '/usr/lib/python27.zip ', '/usr/lib/python2.7 ', '/usr/lib/python2.7/plat-linux2 ', '/ Usr/lib/python2.7/lib-tk ', '/usr/lib/python2.7/lib-old ', '/usr/lib/python2.7/lib-dynload ', '/usr/lib/python2.7/ Site-packages ', '/usr/lib/python2.7/site-packages/gst-0.10 ', '/usr/lib/python2.7/site-packages/gtk-2.0 ', '/usr/ Lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info ']
>>>
Keyboardinterrupt
>>>
[4]+ Stopped python
[Email protected] ~]$ export pythonpath=
[[email protected] ~]$ python
Python 2.7.3 (Default, 9 2012, 17:23:58)
[GCC 4.7.1 20120720 (Red Hat 4.7.1-5)] on linux2
Type "Help", "copyright", "credits" or "license" for more information.
>>> Import Sys
>>> Sys.path
[', '/home/linxj ', '/usr/lib/python27.zip ', '/usr/lib/python2.7 ', '/usr/lib/python2.7/plat-linux2 ', '/usr/lib/ Python2.7/lib-tk ', '/usr/lib/python2.7/lib-old ', '/usr/lib/python2.7/lib-dynload ', '/usr/lib/python2.7/ Site-packages ', '/usr/lib/python2.7/site-packages/gst-0.10 ', '/usr/lib/python2.7/site-packages/gtk-2.0 ', '/usr/ Lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info ']


Thought so much for a moment. You are welcome to add. We study together, summarize

Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

[Python learning] two, using platform Python on Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.