python添加pth文件,支持第三方模块
## 添加pth文件,支持第三方模块
在site-packages/ 增加路径,这种方法一劳永逸, 简单暴力。
举个例子,将/tmp/增加到sys.path
首先cd到指定python的sit-packages/目录下,然后创建一个文件,例如test.pth,在文件中增加/tmp/路径信息,保存退出。
[root@instance-jl0wxuf5 python]# python -m site
sys.path = [
'/home/dir/python',
'/root/anaconda3/envs/weixin/lib/python36.zip',
'/root/anaconda3/envs/weixin/lib/python3.6',
'/root/anaconda3/envs/weixin/lib/python3.6/lib-dynload',
'/root/anaconda3/envs/weixin/lib/python3.6/site-packages',
]
[root@instance-jl0wxuf5 python]# cd /root/anaconda3/envs/weixin/lib/python3.6/site-packages
vim test.pth
$
/home/dir/python/spyder_projdect_py/bot_weixin/
$
[root@instance-jl0wxuf5 site-packages]# cat test.pth
/home/dir/python/spyder_projdect_py/bot_weixin/
[root@instance-jl0wxuf5 site-packages]# python
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:51:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/root/anaconda3/envs/weixin/lib/python36.zip', '/root/anaconda3/envs/weixin/lib/python3.6', '/root/anaconda3/envs/weixin/lib/python3.6/lib-dynload', '/root/anaconda3/envs/weixin/lib/python3.6/site-packages', '/home/dir/python/spyder_projdect_py/bot_weixin']
>>> quit();