Python environment variable pythonpath setting and easy_install

Source: Internet
Author: User

 

1. add your own Python module to pythonpath.

If you want the python interpreter to find the module you have compiled, the module must be on pythonpath. Otherwise, the module cannot be found when importing the module, therefore, you must add the path of the required module to pythonpath (in general, add lib/python2.6/Site-packages to pythonpath ). The procedure is as follows:

A. Assume that the required Python module (or package) is located at/home/lxc/software/Program/python.

B. Add/home/lxc/software/Program/python to pythonpath. The syntax is the same as that in shell:

Export pythonpath = $ pythonpath:/home/lxc/software/Program/Python

Now you can use the getopt_exam.py module, for example:

$ Python

>>> Import getopt_exam

>>> Getopt_exam

Version V1.0

>>>

Note: When getopt_exam is imported for the first time, getopt_exam.py will be compiled as a bytecode. In this case, a file named getopt_exam.pyc will appear in this directory, because *. pyC format ratio *. PY format is faster to export. If getopt_exam.py is updated, you must delete the previously compiled bytecode getopt_exam.pyc. Otherwise, you will not see the updated part when using this module, it is derived from the first generated getopt_exam.pyc. We need to compile the new getopt_exam.py script *. delete the PyC file or directly Delete getopt_exam.pyc (generated for the first time). The Python interpreter automatically does not have the corresponding *. *. the py file generates the corresponding *. pyC file (basic rule: When importing a module, the python interpreter first sets *. compile the py file *. pyC, and then in *. export in PyC ).

2. Use third-party packages or self-compiled modules that are no longer on pythonpath in Python scripts

Take/home/lxc/software/Program/Python/getopt_exam.py as an example.

$ Python

>>> Import sys

>>> SYS. Path. append ("/home/lxc/software/Program/Python ")

>>> Import getopt_exam

>>> Getopt_exam.version ()

Version V1.0

>>>

3. Use easy_install to automatically install the python package

Take networkx installation as an example. Install networkx under pavement/home/lxc/software/Program/Python/Site-packages.

A. Add/home/lxc/software/Program/Python/Site-packages to pythonpath first;

Export pythonpath = $ pythonpath:/home/lxc/software/Program/Python/Site-packages

B. install packages with Versions later than 1.1

Easy_install-2.6-D/home/lxc/software/Program/Python/Site-packages "networkx> 1.1"

4. Use the networkx package that has been installed with EPD

Export pythonpath = $ pythonpath:/home/lxc/software/install/epd-6.2-2-rh5-x86/lib/python2.6/Site-packages

5. Update the python package

Easy_install-2.6-u-d/home/lxc/software/install/epd-6.2-2-rh5-x86/lib/python2.6/Site-packages "networkx> 1.1"

A folder epd-6.2-2-rh5-x86 appears in the/home/lxc/software/install/networkx-1.4-py2.6.egg/lib/python2.6/Site-packages directory, but now you cannot directly use the updated version (networkx-1.4) in the EPD command line; to use the updated version, you can delete the previously installed networkx directly, or "Mv
Networkx. BK ".

Note/home/lxc/software/install/epd-6.2-2-rh5-x86/lib/python2.6/Site-packages must be added to pythonpath first

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.