Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does python view the package search path

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you python how to check the package search path, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The fastest way to view the package search path

When you use import to import a package or module, Python will look in some directories, which are in order of priority, and normal people will use sys.path to view them.

> import sys > from pprint import pprint > pprint (sys.path) [','/ usr/local/Python3.7/lib/python37.zip','/ usr/local/Python3.7/lib/python3.7','/ usr/local/Python3.7/lib/python3.7/lib-dynload','/ home/wangbm/.local/lib/python3.7/site-packages','/ usr/local/Python3.7/lib/python3.7/site-packages'] >

Is there a faster way?

Do I have a method that doesn't even have to enter console mode?

You might think of this, but it's essentially no different from the above.

[wangbm@localhost ~] $python-c "print ('\ n'.join (_ _ import__ ('sys') .path)" / usr/lib/python2.7/site-packages/pip-18.1-py2.7.egg / usr/lib/python2.7/site-packages/redis-3.0.1-py2.7.egg / usr/lib64/python27.zip / usr/lib64/python2.7/ usr/lib64/python2.7/plat-linux2 / usr/lib64/python2 . 7/lib-tk / usr/lib64/python2.7/lib-old / usr/lib64/python2.7/lib-dynload / home/wangbm/.local/lib/python2.7/site-packages / usr/lib64/python2.7/site-packages/ usr/lib64/python2.7/site-packages/gtk-2.0 / usr/lib/python2.7/site-packages

What I'm going to introduce here is a much more convenient method than both of the above, which can be solved with one command.

[wangbm@localhost ~] $python3-m site sys.path = ['/ home/wangbm','/ usr/local/Python3.7/lib/python37.zip','/ usr/local/Python3.7/lib/python3.7','/ usr/local/Python3.7/lib/python3.7/lib-dynload','/ home/wangbm/.local/lib/python3.7/site-packages' '/ usr/local/Python3.7/lib/python3.7/site-packages',] USER_BASE: / home/wangbm/.local' (exists) USER_SITE:' / home/wangbm/.local/lib/python3.7/site-packages' (exists) ENABLE_USER_SITE: True

From the output, you can see that the path of this column is more complete than sys.path, which contains the directory of the user environment.

The above is all the content of the article "how to check the package search path for python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report