python permanently add environment variables

Reprinted from: https://www.cnblogs.com/hujq1029/p/7133237.html

This is adding pythonpath environment variable

 

import sys
sys.path
The system environment is a list, you can add the libraries you need, such as mysql library, hive library, etc. There are three ways to add, all of which are verified:
 
 

1 Temporarily added, in a shell window

import sys
sys.path
sys.path.append(path) 
But exit the shell window, that is invalid
 
 

2 Permanently add using pth file 

 
Use the pth file, create a .pth file in the site-packages file, and write the path of the module in, one path per line, the following is an example, the pth file can also use comments:
# .pth file for the my project (this line is a comment)
E: \ DjangoWord
E:\DjangoWord\mysite
E:\DjangoWord\mysite\polls
This is a good approach, but has management issues and cannot be shared across different python versions
 
 
 

In the python installation directory or the Lib\site-packages directory, add the xx.pth file, where xx is your name, and write the path to the directory where your own module is located in the .pth file, one line at a time.

 Import the executable file under the custom path directly import xx (xx does not contain the file name of the suffix)

3 Using the PYTHONPATH environment variable

Use the PYTHONPATH environment variable, enter the relevant path in this environment variable, separate the different paths with commas (English!), if the PYTHONPATH variable does not exist, you can create it!
The path will be automatically added to sys.path, and it can be shared between different python versions, which should be the same more convenient method
 
This method has not been successfully set up by myself
 
Reprinted from: http://blog.sina.com.cn/s/blog_7de9d5d80101hlj5.html
import sys
sys.path
The system environment is a list, you can add the libraries you need, such as mysql library, hive library, etc. There are three ways to add, all of which are verified:
 
 

1 Temporarily added, in a shell window

import sys
sys.path
sys.path.append(path) 
But exit the shell window, that is invalid
 
 

2 Permanently add using pth file 

 
Use the pth file, create a .pth file in the site-packages file, and write the path of the module in, one path per line, the following is an example, the pth file can also use comments:
# .pth file for the my project (this line is a comment)
E: \ DjangoWord
E:\DjangoWord\mysite
E:\DjangoWord\mysite\polls
This is a good approach, but has management issues and cannot be shared across different python versions
 
 
 

In the python installation directory or the Lib\site-packages directory, add the xx.pth file, where xx is your name, and write the path to the directory where your own module is located in the .pth file, one line at a time.

 Import the executable file under the custom path directly import xx (xx does not contain the file name of the suffix)

3 Using the PYTHONPATH environment variable

Use the PYTHONPATH environment variable, enter the relevant path in this environment variable, separate the different paths with commas (English!), if the PYTHONPATH variable does not exist, you can create it!
The path will be automatically added to sys.path, and it can be shared between different python versions, which should be the same more convenient method
 
This method has not been successfully set up by myself
 
Reprinted from: http://blog.sina.com.cn/s/blog_7de9d5d80101hlj5.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324574527&siteId=291194637